Tour Preview

Find the Best Demos and Examples

Check out this quick tour to find the best demos and examples for you, and to see how the Felgo SDK can help you to develop your next app or game!

Forums

OverviewFelgo 2 Support (Qt 5) › Accessing a column in an SQLite db

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #23991

    Gabor

    Hi,

    I have been trying to fix this problem for a while unsuccessfully. I have the following code:

    function dbInit() {
        var db = LocalStorage.openDatabaseSync("ListViewTest", "",
                                               "Wordlist", 1000000)
        try {
            db.transaction(function (tx) {
                tx.executeSql(
                            'CREATE TABLE IF NOT EXISTS wordTable ( wordField TEXT, sectionField TEXT)')
                console.log("Table created.")
            })
        } catch (err) {
            console.log("Error creating table in database: " + err)
        }
        ;
    }
    
    //Open database
    function dbGetHandle() {
        dbInit()
        try {
            var db = LocalStorage.openDatabaseSync("ListViewTest", "",
                                                   "Wordlist", 1000000)
        } catch (err) {
            console.log("Error opening database: " + err)
        }
        return db
    }
    
    //Read the wordField and sectionField content from the db
    function dbGetWordList() {
    
        var db = dbGetHandle()
    
        db.transaction(function (tx) {
            var results = tx.executeSql(
                        'SELECT  wordField, sectionField FROM wordTable ORDER BY sectionField ASC ')
            for (var i = 0; i < results.rows.length; i++) {
    
                listModel.append({
                                     "sectionField": results.rows.item(
                                                         i).sectionField,
                                     "wordField": results.rows.item(i).wordField,
                                     "checked": ""
                                 })
            }
        })
    }
    
    

    When I run it it gives me the following error message:

     

    Error: no such column: sectionField Unable to execute statement on the lineĀ 

     var results = tx.executeSql(

    As far as I can see there is a sectionField column, but for some reason it is disregarded.

    I would appreciate any input why this might be happening.

    Thank you for your help.

    #24002

    Filippo
    Felgo Team

    Hi Gabor,

     

    Thank you for reaching us. I’ve just pasted the code in an empty project and I’m able to execute it correctly.

     

    My guess is that there is something funny going on with your local database. Could you try completely deleting your database, dropping every table, and see if that fixes your issue?

Viewing 2 posts - 1 through 2 (of 2 total)

RSS feed for this thread

You must be logged in to reply to this topic.