Discussion Board

Results 1 to 13 of 13
  1. #1
    Regular Contributor narendar_discover's Avatar
    Join Date
    Oct 2007
    Location
    India
    Posts
    349
    Hi,
    I want to save some data on device, for that I am using SQLite Database. In Emulator I am able to create DB, Tables and also able to run various type of SQL statement like Insert, Delete, Update and so on. Here is the link from where I got all information regarding SQLite on Symbian:

    http://wiki.forum.nokia.com/index.ph...database_in_Qt

    But after creation sis file if I run this app on device. its not working. What may have problem ?

    I am using Nokia Qt SDK 1.0.2. I have installed the app on Nokia E7.

    I am also getting this error in Application Output :
    QSqlDatabasePrivate::addDatabase: duplicate connection name 'qt_sql_default_connection', old connection removed

  2. #2
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Maybe you should show us a little bit of your code.

  3. #3
    Nokia Developer Moderator skumar_rao's Avatar
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968
    you can try this

    Code:
            QString connectionName = "myconnection";
            if(QSqlDatabase::contains(connectionName)) {
                QSqlDatabase::removeDatabase(connectionName);
            }
            database = QSqlDatabase::addDatabase("QSQLITE", connectionName);
            database.setDatabaseName("tablename");

  4. #4
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    If you want the database on the device, you shouldn't need a connection name.

  5. #5
    Regular Contributor narendar_discover's Avatar
    Join Date
    Oct 2007
    Location
    India
    Posts
    349
    Quote Originally Posted by danhicksbyron View Post
    If you want the database on the device, you shouldn't need a connection name.
    bool DatabaseManager:penDB()
    {
    bool ret = false;

    // QString connectionName = "connection";
    // if(QSqlDatabase::contains(connectionName)) {
    // QSqlDatabase::removeDatabase("QSQLITE");
    // }

    mDb = QSqlDatabase::addDatabase("QSQLITE");
    mDb.setDatabaseName("MYDB");
    ret = mDb.open();
    qDebug()<<"openDB() ret = "<<ret;
    return ret;
    }

    In my app I call this method more than one time and get the error on log

  6. #6
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Well, don't call the method more than one time. Or close the db when you're done with it.

  7. #7
    Nokia Developer Moderator skumar_rao's Avatar
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968
    did #3 worked ?

  8. #8
    Regular Contributor narendar_discover's Avatar
    Join Date
    Oct 2007
    Location
    India
    Posts
    349
    Quote Originally Posted by skumar_rao View Post
    did #3 worked ?
    I was still getting same issue. Then I have changed my code like below I mean I have placed QSqlDatabase::removeDatabase("QSQLITE"); after closing the db and again getting same issue.

    void DatabaseManager::closeDB()
    {
    if (mDb.isOpen())
    {
    mDb.close();
    QSqlDatabase::removeDatabase("QSQLITE");
    }
    }

  9. #9
    Nokia Developer Moderator skumar_rao's Avatar
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968
    can you check the doc http://doc.qt.nokia.com/latest/qsqld...removeDatabase as you can see removeDatabase() closes a open connection. i suggest you try again #3 before opening file or open the file with a connection name then

    Code:
    void DatabaseManager::closeDB()
    {
    if (mDb.isOpen())
    {
    mDb.close();
    QSqlDatabase::removeDatabase("connectionName");
    }
    }

  10. #10
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Why are you opening the DB more than once???

  11. #11
    Regular Contributor narendar_discover's Avatar
    Join Date
    Oct 2007
    Location
    India
    Posts
    349
    Quote Originally Posted by danhicksbyron View Post
    Why are you opening the DB more than once???
    I have two Tabs each. Each tab read some data from DB from different table.

    At startup Tab A opens the DB, reads the rows and then closes the DB also removes the database. when user goes to Tab B again my app opens the DB, reads the rows and then closes the DB and removes the database. Do we need to change this logic. and just need to open DB in Tab A and then continue in Tab B without closing it.

  12. #12
    Nokia Developer Moderator skumar_rao's Avatar
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968
    note that : a DB can have multiple tables .

  13. #13
    Nokia Developer Champion danhicksbyron's Avatar
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209
    Why not just leave the database open?

Similar Threads

  1. Replies: 3
    Last Post: 2008-12-01, 19:58
  2. sqlite database on symbian devices
    By simmik in forum Python
    Replies: 2
    Last Post: 2007-05-17, 13:08
  3. facing problem to find bluetooth device!!!
    By call2kk in forum Bluetooth Technology
    Replies: 1
    Last Post: 2005-05-10, 08:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved