×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    43

    Sqlite3 and Out of Memory error

    Hi,

    I'm getting an Sqlite error:
    Out of Memory Error unable to execute statement

    I'm using Qt/Symbian S60 5th Edition SDK on a XPressMusic device.

    Can someone tell me why this is happening?

    Here's the code:

    bool createTables=contactsFile.exists();
    if(!contactsFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
    msgBox.setText("Can't open contacts file!");
    msgBox.exec();
    }
    contactDatabase.setDatabaseName(contactsFile.fileName());
    contactDatabase.open();
    if(!contactDatabase.isOpen()) {
    msgBox.setText("Unable to open database!");
    msgBox.exec();
    }
    if(!createTables) {
    QString sql =
    "CREATE TABLE USER_CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, "
    "CONTACT_ID INTEGER, URI VARCHAR(32))";
    sqlQuery.exec(sql);
    if(sqlQuery.lastError().isValid()) {
    msgBox.setText(sqlQuery.lastError().text());
    msgBox.exec();
    }
    }



    Thanks,
    Jim

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Sqlite3 and Out of Memory error

    And you're saying the error is coming from the CREATE TABLE?

    Try replacing 'fileName()' with 'absoluteFilePath().replace("/", "\\")'

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    43

    Re: Sqlite3 and Out of Memory error

    Yes, the error is coming from CREATE TABLE. I changed the code and added the change you suggested. I'm getting the same error.

    Here it is:

    ContactsSyncChecker::ContactsSyncChecker() try
    : contactsFile("ContactIds.db"),
    contactDatabase(QSqlDatabase::addDatabase("QSQLITE")),
    sqlQuery(contactDatabase) {
    QMessageBox msgBox;
    bool createTables=contactsFile.exists();
    if(!contactsFile.open(QIODevice::ReadWrite | QIODevice::Text)) {
    msgBox.setText("Can't open contacts file!");
    msgBox.exec();
    }

    QFileInfo fileInfo(contactsFile);
    QString path = fileInfo.absoluteFilePath().replace("/", "\\");
    contactDatabase.setDatabaseName(path);
    contactDatabase.open();
    if(!contactDatabase.isOpen()) {
    msgBox.setText("Unable to open database!");
    msgBox.exec();
    }
    if(!createTables) {
    QString sql =
    "CREATE TABLE USER_CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, "
    "CONTACT_ID INTEGER, URI VARCHAR(32))";
    sqlQuery.exec(sql);
    if(sqlQuery.lastError().isValid()) {
    msgBox.setText(sqlQuery.lastError().text());
    msgBox.exec();
    }
    }
    } catch(...) {

    }

  4. #4
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Sqlite3 and Out of Memory error

    Is fileInfo pointing to a valid file location?

    Can you create ANY sort of table?

  5. #5
    Registered User
    Join Date
    Jan 2010
    Posts
    43

    Re: Sqlite3 and Out of Memory error

    I was able to execute the SQL using the exec() method of QSqlDatabase. QSqlQuery reported the error. I can't say why QSqlQuery would not execute the SQL. In other code, I'm still using the returned QSqlQuery from QSqlDatabase::exec().

    The code is here:

    QFileInfo fileInfo(contactsFile);
    QString path = fileInfo.absoluteFilePath().replace("/", "\\");
    contactDatabase.setDatabaseName(path);
    contactDatabase.open();
    if(!contactDatabase.isOpen()) {
    msgBox.setText("Unable to open database!");
    msgBox.exec();
    }
    if(!createTables) {
    QString sql =
    "CREATE TABLE USER_CONTACTS(ID INTEGER PRIMARY KEY AUTOINCREMENT, "
    "CONTACT_ID INTEGER, URI VARCHAR(32))";
    contactDatabase.exec(sql); // This works without an error
    if(contactDatabase.lastError().isValid()) {
    msgBox.setText(contactDatabase.lastError().text()+path);
    msgBox.exec();
    }
    }


    Thanks for your comments, they were very helpful.



    Jim

  6. #6
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Sqlite3 and Out of Memory error

    I'm sorry, but every time you post code it looks different, and you still leave out much of the declaration and initialization. (And please click on the "#" symbol when posting so that you can quote your code in a formatted block.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×