Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 237
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel
Accepted Solution

Question About QSqlDatabase

Hi, my app using QSqlDatabase.

 

It work fine, I can insert and load data from DB.

On  device-debug and device-release.

 

The problem is, when I'm Export Release Build on .bar-descriptor, then .bar file created.

So I want to try install (sideloading) the .bar file on device, I used DDPB to deploy .bar file on device.

http://ddpb.dauden.vn/

 

And my app deployed on device using DDPB, so I test the app.

But the database action is not working, like insert do DB.

Why this happen?

Or just ignore this and submit to Blackberry World? Because on device release is working. (use run-as)

 

Thanks

 

 

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Question About QSqlDatabase

Did you copy your database to the data folder or keep it in assets?

The assets folder is read only.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Regular Contributor
Posts: 94
Registered: ‎12-02-2011
My Device: non-Blackberry user
My Carrier: none

Re: Question About QSqlDatabase

You can either create it if it does not exist, or copy one over from the asset folder.  Here is how I do the copy if needed on app startup:

 

bool MyAppr::initDatabase(QString dbName) {
    bool bstatus = false;
    QString databaseFile = "./data/" + dbName + ".sql";
    qDebug() << "INIT DATABASE FILE NAMED : " << databaseFile

    QFileInfo fi(databaseFile);
    if (!fi.exists()) {
            QFile file("app/native/assets/data/cm.sql");
            bstatus = file.copy(databaseFile);
            if (!bstatus) {
                qWarning()
                     << "Failed to copy reference database to working directory";
            }
            return bstatus;

        ....

 

Hope this is of some value to you

Developer
Posts: 237
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: Question About QSqlDatabase

Hi, I'm checking first the database file available or not.

If not available I'm creating table

 

Here is my code 

bool DatabaseManager::openDB()
    {
    // Find QSLite driver
	iDb = QSqlDatabase::addDatabase("QSQLITE");
    // NOTE: We have to store database file into user home folder
    QString path = QDir::currentPath() + "/data/myApp.db";
                   // before was QDir::currentPath() + "/app/native/assets/myApp.db";
    iDb.setDatabaseName(path);

    // Open database
    return iDb.open();
    }

 So I'm wrong to save database on assets folder, so I changed to data folder and database work.

 

Thanks

Highlighted
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Question About QSqlDatabase

You're welcome it's an easy thing to miss.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.