[Gambas-user] Doing query of Stored procedure with no related data crashes gambas

Christof Thalhofer chrisml at deganius.de
Sun Feb 19 11:17:01 CET 2023

Am 19.02.23 um 09:23 schrieb BB:

> This is a gambas "bug" in one sense and not so in others.EXEC expects a
> Result object to be returned, no matter whether the provided parameter
> is a valid SQL sentence or not! In his case I believe it may have not
> returned such. Further, his report of the Gambas error "Query failed:
> Commands out of sync; you can't run this command now" indicates that
> there could be a further and actual bug in the Gambas db component.

In short: I cannot see a bug.

I just created a stored procedure in PG which does nothing (except 
querying some stuff inside):

> testdb=> CREATE PROCEDURE testcall()
> testdb-> LANGUAGE SQL
> testdb-> AS $$
> testdb$> select test from tbtest;
> testdb$> $$;

Tested it inside PG:

> testdb=> call testcall();

Ok, it runs so far...

So now let's execute it from Gambas:

 >     ConTest.Exec("call testcall();")
 >     Print "ok"

Runs the statement 'call testcall();' and prints ok.

>     res = ConTest.Exec("call testcall();")
>     Print "ok"

Also runs the statement 'call testcall();' and prints ok.

The Result object ('res') is returned and is empty.

A last test:

 >     res = ConTest.Exec("glibberish thing") ' No valid SQL!
 >     Print "ok"
>     Catch 
>         Print Error.Text

Gambas throws an error which contains the error, the database threw:

'Query failed: ERROR:  syntax error at or near "glibberish"'


So Conection.Exec() does what it has to do:

It sends a string to the DB and let the DB execute it.

If there's a result it returns a Result object.

If the result is empty it returns a Result object which is empty.

If the DB reports an error, it throws an error.

At least with Postgresql.

Alles Gute

Christof Thalhofer

Dies ist keine Signatur

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20230219/20a7caba/attachment.sig>

More information about the User mailing list