开发者

QT SQLite not working in Embedded device

I am using QT framework. Basically I am creating application for ARM devices.

Now I've created sample application using SQLite for DB work. Thing is that one is working in my desktop but when I cross compiled it for device and tried to execute it in my device Getting error.

So I logged some error messages. Finally i found that DB file was created successfully but unable to create table in device.

Is i开发者_如何学JAVAt because of out of memory issue?

Code :

QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("songs.db");
    if (!db.open()) {
        QMessageBox::critical(0, qApp->tr("Cannot open database"),
            qApp->tr("Unable to establish a database connection.\n"
                     "This example needs SQLite support. Please read "
                     "the Qt SQL driver documentation for information how "
                     "to build it.\n\n"
                     "Click Cancel to exit."), QMessageBox::Cancel);
        //return false;

debugLog("#fileListThread::run()-> Unable to establish a database connection.."<<db.lastError(););
                }
else
{
    debugLog("#fileListThread::run()-> opened songs.db successfully..");
}

QSqlQuery query;


bool queryStatus = query.exec("create table songsList (id int primary key, "
           "Song varchar(20), Artist varchar(20),Producer varchar(20))");

if(queryStatus)
{
    debugLog("#fileListThread::run()-> created table in songs DB successfully..");
}
else
{
    debugLog("#fileListThread::run()-> failed to create table in songs DB.."<<query.lastError(););
}

Okay! One more quick question-> Is it possible to create DB file and executing queries inside in embeedded devices. In my device available free memory is 9MB.

Thanks, Vishnu


I think you should use

CREATE TABLE IF NOT EXISTS songsList

sql statement rather than

create table songsList

Otherwise once the table is created , the second time you try to execute it, you may get an error.

Other than that I don't see a problem but who knows... I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜