ADD, EDIT, DELETE ITEM IN A DATABASE FILE
Today,we learn to use datas in sqlite database with somes gambas 2 sources codes examples.
A) Add data to database
To add data to database, use the CREATE command in your connection :
(Translation french to english : maconnexion=myconnection, matable= mytable, monresultat=myresult)
PUBLIC maconnexion AS new connection
PUBLIC matable AS table
PUBLIC monresultat AS result
PUBLIC sql AS String
maconnexion.type = lower("sqlite3")
maconnexion.host = application.path
maconnexion.name = "mybddFile"
maconnexion.login = ""
maconnexion.password = ""
maconnexion.port = ""
maconnexion.OPEN()
maconnexion.begin
monresultat = maconnexion.create("mytable")
monresultat.update
maconnexion.commit
maconnexion.CLOSE |
B) Edit data in database.
I use the EDIT command
DIM maconnexion AS new connection
DIM matable AS table
DIM monresultat AS result
maconnexion.type = lower("sqlite3") 'type de bdd
maconnexion.host = application.path
maconnexion.name = "bdddata"
maconnexion.login = ""
maconnexion.password = ""
maconnexion.port = ""
'ouvre la connexion a la bdd sqlite
maconnexion.OPEN()
monresultat = maconnexion.edit("mytable", "id=" & id) |
then EDIT data :
monresultat!monchamp = manouvellevaleur |
then update database to save edition:
monresultat.update
maconnexion.commit
maconnexion.CLOSE |
3) Delete a line in database.
Same as before but use
DELETE command:
monresultat = maconnexion.delete("mytable", "id=" & myid) |
Informations:
When you write in your IDE this code :
myconnection. you have help with all possibles commands as this :
Look at documentation for help , this is very interesting.
Thanks for your attention.
Regards