11-22-2012 04:34 PM
I am trying for 2 hours to solve this problem. I am building a basic application, which uses SQLite database using SqlDataAccess wrapper. This is my database creation code, which gets executed only if db/database.db file does not exist.
// Create an SqlDataAccess object SqlDataAccess sda("db/database.db"); sda.execute("CREATE TABLE Profiles (profile_id INTEGER PRIMARY KEY, profile_name TEXT, is_sel INTEGER, max_number INTEGER, number_to_generate INTEGER);"); sda.execute("INSERT INTO Profiles (profile_name, is_sel, max_number, number_to_generate) VALUES ('Test', 1, 39, 7);"); sda.disconnect();
Otherwise I select the data in table and display it in QML. The select code:
SqlDataAccess sda("db/database.db"); QVariant list = sda.execute("SELECT * FROM Profiles;");
But I never get to this point. SELECT always returns empty QVariant, which is normal because data is never inserted. I tried inserting data immediately before SELECT, but also nothing. The INSERT clause is valid and does not display any error (using DataAccessError) and is executed successfully. The schema is created successfully, but the data is never inserted.
According to this example it should work: https://developer.blackberry.com/cascades/document
What am I doing wrong?
12-04-2012 09:12 AM
I think I had similar problem, try without a semicolon at the end:
just: "INSERT INTO table (col,col2,col3) VALUES (3,4,5)"
Another thing, before continuing it is good to check if previous operation was successfull:
12-04-2012 12:43 PM
Thank you for your reply. I have tried all queries with and without semicolon, does not make any difference. And I also tested each query with sda.hasError() function, like you said, but there are no errors at all. Just the data is not saved.
12-04-2012 01:07 PM - edited 12-04-2012 01:09 PM
Are you sure that the result of SELECT query is correct? Did you cast it to QVariantList? Maybe check
12-04-2012 01:14 PM
I have tested the SELECT query many times, even in online SQL validators. The select statement is not the problem, because the INSERT is not performed. I can also check this by filesize, because the database file does not change size after creating tables. I cannot imagine that 5 selects do not add a single byte to the database.
12-04-2012 01:20 PM
12-04-2012 01:22 PM
12-04-2012 02:50 PM
For debugging purposes scp file over to your Linux (may work with windows) machine and download apt-get with ubuntu) sqlite3 This way you can verify that your tables are there, schema is as you think it is, and see what records are there.
.tables // will show tables
.schema <tablename> // show you the schema
select * from <tablename>; // note semicolin fo rthis command only