[Gambas-user] gb.db local change
benoit.minisini at gambas-basic.org
Sat Dec 10 13:05:35 CET 2022
Le 09/12/2022 à 09:14, BB a écrit :
> I need a bit of help here. In our local version of the interpreter I
> want to implement a "small" change to use the "RETURNING *" optional SQL
> command. This works fine for postgresql but not for sqlite (at this
> stage of debian's distros). I understand (I'm pretty sure) the object
> model but I can't write the C code.
> Within the following patch I want to test the "THIS->conn->" database
> type and only include the RETURNING clause if its a PostgreSQL database
> we are talking to.
> +++ b/main/lib/db/CResult.c
> @@ -716,7 +716,7 @@ BEGIN_METHOD_VOID(Result_Update)
> q_add(" )");
> + q_add(" RETURNING * "); <----- but only if PostgreSQL
> if (!THIS->driver->Exec(&THIS->conn->db, q_get(), NULL, "Cannot create record: &1"))
> This is a LOCAL change as the RETURNING clause is not universally
> supported. In fact I'm not sure if it is conformant to the SQL standard,
> but we really need it here.
> I have had many tries at working this out but have had no success.
> Can anyone help me here, please.
This is just for your hack, as it should not be done like that:
if (!strcmp(THIS->driver->name, "postgresql"))
q_add(" RETURNING *");
The correct way is adding a flag in the 'flags' field of the DB_DATABASE
structure that tells if we can add "RETURNING", and set that flag in the
open_database() method of the drivers that support it (with a test on
the database version possibly).
More information about the User