[odb-users] arbitrary query returning tuples

Boris Kolpackov boris at codesynthesis.com
Thu Dec 14 03:47:23 EST 2023


Патрушев Данил Андреевич <d.patrushev at prosoftsystems.ru> writes:

> I spent some time digging in the sources and realized libodb-pgsql
> does some preprocessing even for this kind of super low-level view,
> adding "WHERE" if the text of the query doesn't meet certain criteria,
> which results in invalid SQL. That was news to me. So, the question
> is:  is that a feature?

The reason we do this is because you can either specify the entire
query of just the WHERE condition and we need to distinguish these
two cases (there is also the stored procedure call complication).
The way we do it is by looking for the leading word like SELECT,
EXEC, etc.


> If it is, is there still a way to execute an arbitrary query
> returning tuples (for any database backend, not just libodb-pgsql)?

There is a note in odb/relational/processor.cxx:1183:

//@@ We need to recognize database-specific list of prefixes. For
//   example, PG has WITH. Alternatively (or in addition) we could
//   do the same comment trick (e.g., /*SELECT*/ to treat it as a
//   SELECT-like queiry).

So /*SELECT*/ could be one way to support this.

Also, I am actually not sure whether INSERT returns results in the
same way as SELECT; that's the compilation I refer to with stored
procedure calls -- for some databases the result is returned
differently. In fact, you can probably try /*CALL*/ INSERT to
see if this maybe already works.



More information about the odb-users mailing list