François K. kirjoitti ke joulukuuta 30 00:07:29 2015 GMT+0200:

> How would you make such a thing ? Use the destructor of the proxy to update 
> the database ?

The remorse would just delete the item from the QML list model, and then you 
could have a update timer (to prevent updating the whole list at db every time 
the user changes the proxy list) that starts running when the list's count has 
changed (for example. Doesn't work when you do something else than add/remove). 
The timer would then execute a loop like this:

function saveListToDB()  {
    dbOpenConnection()
    dbDropTable() // the risky part
    var i = 0
    for (i<list.count;i++) {
        dbUpdateFunction(list.get(i))
    }
}

The other way to do stuff:

The remorse could look like this:

remorse.execute("deleting item...", deleteItem(title, index), 5000)

function deleteItem(title, index) {
    list.remove(index)
    dbOpenConnection()
    dbRemoveItem(title)
}

And the SQL executed by dbRemoveItem(title or other identifier) would be 
something like

(DELETE FROM table WHERE title=?;)[title]

The second option is much safer, but doesn't allow rearranging the items.

Please keep in mind I just woke up like 10 minutes ago and wrote all this on my 
phone without IDE or any documentation.
 
> I have to admit that I don't really like this approach, it sounds kinda risky 
> to me. 

The second one is pretty safe :)

> And it also means that I have to add extra loops for something that shouldn't 
> require it.

Efficiency-wice it doesn't really matter, after all your QSQLModel must read 
the database as well.

I am also working on something that has a modifiable list stored with SQL. I'll 
link you the code after I'm done with it.
 
> Thanks again :)

No problem, I might accidentally learn something while doing this.
 
Cheers,
jollailija 

-- 
Lähetetty Jollastani
_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org

Reply via email to