SQlite database problem in qml



  • Hi, I've created a js file with a SQlite database that is pouplating my app in qml, but when i try to run it's giving the following warnings:
    v -Error: no such table: searchtable Unable to execute statement
    I've found many threads with same problem, but they all have their databases written in C++ and I don't know ho to proceed with js file.
    Here's my database.
    Edit: qt sdk give this warning also with other projects that don't have a sqlite database.

    @var DatabaseName = "SearchDatabase";
    var DatabaseDescription = "Search list items";

    var db = openDatabaseSync(DatabaseName, "1.0", DatabaseDescription, 1000000);
    var db = openDatabaseSync("SearchDatabase", "1.0", "Search list items", 1000000);
    function createDb() {
    var db = openDatabaseSync(DatabaseName, "1.0", DatabaseDescription, 1000000);
    db.transaction(
    function(createDbTransaction) {
    createDbTransaction.executeSql("CREATE TABLE IF NOT EXISTS searchtable (name TEXT, url TEXT)");
    }
    );
    }
    function addItem(name, url) {
    db.transaction(
    function(addItemTransaction) {
    addItemTransaction.executeSql("INSERT INTO searchtable VALUES(?, ?)", [ name, url ]);
    }
    );
    }
    function dropTable()
    {
    db.transaction(
    function(tx){
    tx.executeSql("DROP TABLE IF EXISTS searchtable");
    }
    )
    }
    function deleteTodo(name)
    {
    db.transaction(
    function(tx){
    tx.executeSql("DELETE FROM searchtable WHERE name = ?", [name]);
    }
    )
    }
    function updateModel(model) {
    var db = openDatabaseSync("SearchDatabase", "1.0", "Search list items", 1000000);

    db.transaction(function(getRowsTransaction) {
                       var rows = getRowsTransaction.executeSql("SELECT * FROM searchtable");
        model.clear();
    
        for (var i = 0; i < rows.rows.length; i++) {
            var item = rows.rows.item(i);
            model.append({"name": item.name,
                          "url": item.url});
        }
    });
    

    }@



  • Update: Now i solved this warning: QSqlDatabasePrivate::removeDatabase: connection ‘qt_sql_default_connection’ is still in use, all queries will cease to work.(when exiting). But still I have: error no such table


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.