comp.lang.ada
 help / color / mirror / Atom feed
* Problem in GNATColl when using prepared queries: GNATCOLL.SQL.POSTGRES.GNADE.POSTGRESQL_ERROR is raised
@ 2011-02-25 15:45 Thomas Løcke
  2011-02-25 16:05 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 16+ messages in thread
From: Thomas Løcke @ 2011-02-25 15:45 UTC (permalink / raw)


If I do this:

    declare
       --  ... stuff
       Cur : Forward_Cursor;
       Q : constant SQL_Query := SQL_Select
         (Fields   => Tmp.Id & Tmp.Name,
          From     => Tmp,
          Where    => Tmp.Name = Text_Param (1));

       P : constant Prepared_Statement := Prepare
         (Query       => Q,
          On_Server   => True);
    begin
       Cur.Fetch (Connection => Connection,
                  Stmt       => P,
                  Params     => (1 => +Some_Name'Access));
       while Cur.Has_Row loop
          Put_Line ("id=" & Cur.Integer_Value (0)'Img);
          Put_Line ("name=" & Cur.Value (1));
          Cur.Next;
       end loop;
       Put_Line (Cur.Processed_Rows'Img);
    end;

Then this exception is raised:

    GNATCOLL.SQL.POSTGRES.GNADE.POSTGRESQL_ERROR

and I get no output at all.

But if I instead do this

    declare
       --  ... stuff
       Cur : Forward_Cursor;
       Q : constant SQL_Query := SQL_Select
         (Fields   => Tmp.Id & Tmp.Name,
          From     => Tmp,
          Where    => Tmp.Name = Some_Name);
    begin
       Cur.Fetch (Connection => Connection,
                  Query      => Q);
       while Cur.Has_Row loop
          Put_Line ("id=" & Cur.Integer_Value (0)'Img);
          Put_Line ("name=" & Cur.Value (1));
          Cur.Next;
       end loop;
       Put_Line (Cur.Processed_Rows'Img);
    end;

Then I get some nice output, and everything works.

But I don't want to use the latter solution. I want to use prepared and
parameterized queries, but for some odd reason it wont work.

If I get rid of the Cur.Integer_Value (0) and Cur.Value (1) calls in
the while loop from the prepared example, then I also get rid of the
exception, so it appears to be some sort of issue with the *Value
functions and prepared queries.

The exception is raised in gnatcoll-sql-postgres-gnade.adb:1122.

Oh, and both queries do fetch the same amount of data - I check that
with the Processed_Rows function after the loop. It's just that the
prepared query wont allow me to "get to" the data, unless I leave out
the *Value calls.

-- 
Thomas L�cke

Email: tl at ada-dk.org
Web: http//:ada-dk.org
http://identi.ca/thomaslocke



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-03-01 20:54 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-25 15:45 Problem in GNATColl when using prepared queries: GNATCOLL.SQL.POSTGRES.GNADE.POSTGRESQL_ERROR is raised Thomas Løcke
2011-02-25 16:05 ` Dmitry A. Kazakov
2011-02-25 18:24   ` Thomas Løcke
2011-02-25 20:08     ` Dmitry A. Kazakov
2011-02-25 21:50       ` Thomas Løcke
2011-02-26 19:33         ` Dmitry A. Kazakov
2011-02-27 14:53           ` Thomas Løcke
2011-02-27 15:36             ` Dmitry A. Kazakov
2011-02-27 15:49               ` Thomas Løcke
2011-02-27 20:15                 ` Dmitry A. Kazakov
2011-02-27 21:53                   ` Thomas Løcke
2011-02-28 13:49             ` Emmanuel Briot
2011-03-01  8:34               ` Thomas Løcke
2011-03-01 10:28                 ` Emmanuel Briot
2011-03-01 20:33                   ` Thomas Løcke
2011-03-01 20:54                     ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox