SQLite plugin, new ExecuteSQL() do not throw?

Hi Guys,

continue reading and testing SQLite of Xojo,
I have take latest Xojo 2019r3.2
opened example Databases/SQLite/SQLiteExample.xojo_binary_project

In the EditWindow, Save button Action() I have changed query to have error,
City have no assigned:
Var sql As String = “UPDATE Team SET Name = ?, Coach = ?, City WHERE ID = ?”

issue1: This Action() handler still have OLD deprecated SQLExecute() call, and it is in try-catch.

Try
  ps.ExecuteSQL
Catch err As DatabaseException
  MessageDialog.Show("DB Error: " + err.Message)
  Return
End Try

Self.Close

An exception of course NOT happens, because method is old.

issue2: I have changed it to new ExecuteSQL() and Hmm, still there is no exception.

This is a bug, right?

1 Like

It may be the titlecase, could be case a sensitive query?

in your example, is ps as PreparedStatement or a Database object?

Two bugs.

  1. This example should not be using a prepared statement as executeSQL is a prepared statement, and obviously trying to catch an exception on SQLExecute is not going to happen.
  2. PreparedStatement.ExecuteSQL should throw an exception, but doesn’t.

I now very rarely use prepared statements anymore it is much more convenient to just pass the parameters using exececuteSQL.

1 Like

This is Example of Xojo
Full text of method is:

// Get the values from the TextFields
Var name As String = NameField.Value
Var coach As String = CoachField.Value
Var city As String = CityField.Value

// Use an UPDATE statement to modify the row with the values from
// the TextFields.
Var sql As String = "UPDATE Team SET Name = ?, Coach = ?, City WHERE ID = ?"
Var ps As SQLitePreparedStatement = App.DB.Prepare(sql)

// Set the type and value for each parameter in the SQL
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(0, name)
ps.BindType(1, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(1, coach)
ps.BindType(2, SQLitePreparedStatement.SQLITE_TEXT)
ps.Bind(2, city)
ps.BindType(3, SQLitePreparedStatement.SQLITE_INTEGER)
ps.Bind(3, mPk)

Try
  ps.ExecuteSQL
Catch err As DatabaseException
  MessageDialog.Show("DB Error: " + err.Message)
  Return
End Try

Self.Close

Just to be clear, ExecuteSQL is a prepared statement under the hood.

Ah! You can greatly simplify this code now:

// Get the values from the TextFields
Var name As String = NameField.Value
Var coach As String = CoachField.Value
Var city As String = CityField.Value

// Use an UPDATE statement to modify the row with the values from
// the TextFields.
Var sql As String = "UPDATE Team SET Name = ?, Coach = ?, City = ? WHERE ID = ?"

try
  App.DB.ExecuteSQL(sql, name, coach, city, mPk)
Catch err as DatabaseException
  MessageDialog.Show("DB Error: " + err.Message)
  Return
End Try

Self.Close

And I suspect this will throw exceptions like you expect to.

Oh and BTW, the problem is that you’ve defined three “variables” and supplied four properties. I had to add “= ?” after “city” in the SQL statement.

1 Like

Greg, please understand me correctly :slight_smile:

We here develop Valentina DB plugin, and SQLite Server,
so I did learn once again Xojo docs and examples.

And I see some inconsistency and even bugs.

Stmt.ExecuteSql() - must throw, but it not throws. Looks as a bug. In Xojo.

I think he took that out a-purpose to provoke/test for an exception.

1 Like

Looking at the docs, it does not say that PreparedSQLStatement.ExecuteSQL throws exceptions either, whereas Database.ExecuteSQL explicitly does. I’m not saying that you’re incorrect, just that the fact that it doesn’t throw and we documented it that way may mean that it was intentional. We’ll have to wait for more engineers to get to their desks before we can determine that. I’ll ask @William_Yu to respond.

This is all dependent on what the database back end reports to us. If it doesn’t report an error we don’t throw. You may find SQLite to be one of the most lax in error reporting out of all the databases.

Hi,

have a look at Feedback case 59604.

1 Like

:slight_smile: Or we fixed this.

1 Like

So… what?
The user must guess?
Never trust the try catch and rely i other error checking?
Use API 1to be sure?

Aha, for the next 2020r1 build. Great! :slight_smile:

THEN let me point that page about PreparedSQLStatement.ExecuteSQL() really do NOT mention exception, as Greg has pointed also.

And this should be fixed in Xojo Docs, I guess. Yes?

The same for PreparedSQLStatement.SelectSQL

  1. PreparedSQLStatement — Xojo documentation
  2. PreparedSQLStatement — Xojo documentation
  3. PreparedSQLStatement — Xojo documentation - I guess this page also can mention exceptions like it was made for Database class.

No, this was fixed in April so we should already have seen it. Also, that is a different error than the deliberate one done by the OP.

Both the error in the OP’s code, and the different error in 59604 generate an exception when the ExecuteSQL runs. I don’t know why the prepare doesn’t generate one, but anyone who wants to know could ask on the SQLite Users’ Forum I imagine.

Meanwhile you should all follow @Greg O’Lone’s advice. You don’t need to use prepared statements here.

Sorry but not. It is not included into 2019 r3.2

and in Feedback, this issue marked: Release: Xojo 2020r1
I think it was fixed in the “special” GIT branch ))

The shortcut as shown by Greg is included in 2019r3.2.

Well it’s in the docs anyway. The fix isn’t. Our doc system doesn’t have a way to deal with this at the moment when we do a point release so late in the cycle of the next one.

At which XOJO version did we do away with preparedstatements? I am running 2019r1.1