- Hello, I am updating an SQLite table with data from an input screen. The first method works fine. The second, which involves a lot less work, does not.
I would prefer to use the second method as there are fewer possibilites of a typo, which isn't that important but as there are nearly 30 fields to update there is clearly far less work involved and easier to notice any field omissions etc.
The second method doesn't throw an error and gives the impression it has completed but does not update the table. The SQL code line is fine and checks out in DBBrowser. Is this an issue in PB or have I got some syntax wrong?
Many thanks, C87
Code: Select all
;SQLite Database
REPL$ = "UPDATE PWS10 SET "
REPL$ = REPL$ + "GROUPBY= '" + fmGroupBy + "', "
REPL$ = REPL$ + "WEBSITE='" + fmWebsite + "', "
REPL$ = REPL$ + "EMAIL='" + fmEmail +"', "
REPL$ = REPL$ + "NAME= '" + fmName + "', "
REPL$ = REPL$ + "ACCTYPE='" + fmAccType + "'"
REPL$ = REPL$ + " WHERE RECNO=?"
;
If DatabaseUpdate(0,REPL$)
;
MessageRequester("UPDATE COMPLETED","Your changes have been saved",#PB_MessageRequester_Ok)
;
Else
;
MessageRequester("ERROR UPDATING RECORD","Changes have not been saved, please try again."+Chr(10)+Chr(10)+"Error: "+ DatabaseError(), #PB_MessageRequester_Info)
EndIf
; ▲ ▲ ▲ the above works Ok
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; ▼ ▼ ▼ the code below goes to UPDATE COMPLETED i.e., no error on update but the PWS10 table is not updated with the changes
SetDatabaseLong(0,0,DBRECNO)
SetDatabaseString(0,1,fmGroupBy)
SetDatabaseString(0,2,fmWebsite)
SetDatabaseString(0,3,fmEmail)
SetDatabaseString(0,4,fmName)
SetDatabaseString(0,5,fmAccType)
;
If DatabaseUpdate(0,"UPDATE PWS10 SET GROUPBY=?, WEBSITE=?, EMAIL=?, NAME=?,ACCTYPE=? WHERE RECNO=?" ) ; this messages Saved but doesn't do the save
;
MessageRequester("UPDATE COMPLETED","Your changes have been saved",#PB_MessageRequester_Ok)
Else
;
MessageRequester("ERROR UPDATING RECORD","Changes have not been saved, please try again."+Chr(10)+Chr(10) + "Error: " +DatabaseError(), #PB_MessageRequester_Info)
EndIf