Updating database column error

I cannot find reason why the Update code is not working for the table. It must be some kind of syntax problem. What am I doing wrong in the code here?

Sub Action()
//Update the data in the database
db.ExecuteSQL(“UPDATE Characters SET Character_Name = ‘LittleAndre’ WHERE ID = 2”)

Screenshot 2022-08-21 at 13.54.23

End Sub

What’s the error?
Is your database read-only?

Yes, it’s writeable. I don’t see an error message, only this:
Screenshot 2022-08-21 at 14.08.24

possible that it is blocked because you open db browser. i guess it is sqlite.
for a test execute this statement in db browser.

The code seems to be OK:
Screenshot 2022-08-21 at 14.31.53

Check the exception in the debugger, click it and check the error message, there has to be one.

No error message there:
Screenshot 2022-08-21 at 14.39.18

isn’t there a NilErrorException ? I think db may be nil ?

Execption type ? DatabaseException ?

yep… thanks!

Usually Xojo shows an error area below that. Can you paste a complete screenshot that includes this part of the screen and the other part of Xojo too?

It looks like you are not connected to the database when you try to update. Or you are connected to a different db.

As Alberto said, inspect the db property before such update (break). I guess it is not what you expected.

I found the problem line. I placed a message box at the start of every Method to see where db was set to nil and…

Screenshot 2022-08-21 at 15.22.51

Not a very good advice to save memory :slight_smile:

1 Like

in my projects with database i subclass this xojo database class to have more control or debug output.

Next time you get into this situation, note that the highlighted line has not yet been executed. The icon to the left tells you that if you execute this line, there will be an error … but you are not told which one :disappointed:. To be told what the error is, click on the Play button: the line will be executed, the exception will be raised and you will get an explanation.

When working with a database, connect to the database when the application starts, and set db to the open database. If opening the database fails, the display an error message to the user stating that since the database failed to open, the app can’t run.

Each database manipulation should be in a try-catch block to avoid an unhandled exception.

Using MessageBoix for that is a real pain and a bad idea.

Use instead:


System.DebugLog "My meaningful sentence…"

and when you want to read the report, do back to the ide and click in the rightmost button:
image

then resume the run (or Cmd-Tab / Alt-Tab to go to the application).