[gtkada] APQ connection and callback

Matthias Teege matthias-gtkada at mteege.de
Wed Aug 25 10:20:45 CEST 2004


Moin,

I build a small application with glade/gtkada and apq (postgresql
connection). I need results of database querys in the callback
functions but I don't know, how to handle the database connection. At
the moment I create a new connection for each query like this:

procedure On_Combo1_Realize
     (Object : access Gtk_Combo_Record'Class)
     is
         Combo1_Items : String_List.Glist;
    begin
         Mdt.Fill_Combo(Combo1_Items,"mdt","ort");
	 Combo.Set_Popdown_Strings(Window1.Combo1, Combo1_Items);
         Free_String_List (Combo1_Items);
         Call_Statusbar("real");
end On_Combo1_Realize;

where Mdt.fill_Combo is:

procedure Fill_Combo(L : in out String_List.Glist;
                     Table : in String;
		     Field : in String) is
use APQ.PostgreSQL, APQ.PostgreSQL.Client;

      C : Connection_Type;
      Q : Root_Query_Type'Class := New_Query(C);
      R : String(1 .. 50);
		  
    begin
       Set_DB_Name(C,"ldb");
       Set_Notify_Proc(C,Standard_Error_Notify);
       Connect(C);
       Prepare(Q, "SELECT "&field);
       Append_Line(Q, "FROM "&Table&" group by "&Field&" order by "&Field&";");
       Execute_Checked(Q,C);
      
      loop
          begin
              Fetch(Q);
          exception
              when No_Tuple =>
          exit;
          end;
     
      begin
          Value(Q,1,R);
          String_List.Append(L, R);
      end;
end loop;

How to I handle the connection correct?
Matthias

-- 
Matthias Teege -- http://www.mteege.de
make world not war



More information about the gtkada mailing list