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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Regular Contributor
mdmdev
Posts: 75
Registered: ‎11-30-2012
My Carrier: airtel

Creating a sqlite DB in BB10 app

I want to create sqlite db through my app.

 

I tried the below code but it returns false.. so how to create a DB and where does the default db file exists.?

 

db = QSqlDatabase::addDatabase("QSQLITE");

db.setDatabaseName("my.db");

// Open databasee
bool dbOpen = db.open(); <- dbOpen is false here

Please use plain text.
Developer
zezke
Posts: 831
Registered: ‎12-12-2010
My Carrier: Mobile Vikings

Re: Creating a sqlite DB in BB10 app

In my application I created a SQLite database using an external application. In my code I check if a database file is present and if that's not the case, I copy the default database from the assets folder. It's pretty much the same logic as used in the quotes sample, so you might want to check that.

 

If you insist on completely creating your SQLite database in your code then I am not much of help I'm afraid.

-------------------------------------------
Your like is much appreciated!
Samples: Park in Ghent
Feeling generous? Nominate me for BB Elite member!
Please use plain text.
Developer
dridk
Posts: 91
Registered: ‎09-25-2012
My Carrier: free

Re: Creating a sqlite DB in BB10 app

Maybe you cannot write data ... 

 

Try : setDatabasename("/path/to/writable/db.sqlite")

a lover of Qt
Please use plain text.
Developer
simon_hain
Posts: 13,817
Registered: ‎07-29-2008
My Carrier: O2 Germany

Re: Creating a sqlite DB in BB10 app

I create the database like this:

 

QString databaseName = "dbname.db";
QString dataFolder = QDir::homePath();
QString databaseFileName = dataFolder + "/" + databaseName;
QFile databaseFile(databaseFileName);
databaseFile.open(QIODevice::ReadWrite);
sqlDataAccess = new SqlDataAccess(databaseFileName);

 took the code from some sample and modified it a bit.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.