Prev: "(if-else-)" conditional expression from the waste land
Next: When a conditional expression is static, where can it be used?
From: tonyg on 30 Jun 2010 05:40 On 30 June, 10:29, tonyg <tonytheg...(a)googlemail.com> wrote: > On 30 June, 10:23, Ludovic Brenta <ludo...(a)ludovic-brenta.org> wrote: > > > > > > > tonyg wrote on comp.lang.ada: > > > > On 30 June, 09:34, tonyg <tonytheg...(a)googlemail.com> wrote: > > >> I am calling this gnade function in the mysql package to get some > > >> debug info > > > >> Put_Line(To_String(String_Field (TheDatabase, TheHeaterQuery, 1))); > > > >> it unfortunately hangs though and the task stops > > > >> I am thinking perhaps the whole task has either hung or terminated > > >> without telling me. > > > >> Would gnat tell me if this task had crashed? > > > > I put the code in a straight procedure and I get a constraint error > > > which is > > > > raised CONSTRAINT_ERROR : gnu-db-mysql.adb:883 invalid data > > > > I am wondering what field types are good to use in a ada mysql > > > database connection and what I am doing wrong here - has anybody any > > > ideas ? > > > Looking at gnu-db-mysql.adb:883 (for gnade 1.6.1 or 1.6.2) indicates > > that your variable TheHeaterQuery is not initialized. > > > -- > > Ludovic Brenta. > > Do you have some example code I can take a look at that retrieves a > string from a database? btw I use the Nbr_Of_Rows function and I get an answer of 2 which indicates that the query has operated and retrieved the data correctly and I try the query out in the mysql query browser to make sure the query works so I do think the query has correctly initialised but its when I go to access the string that things fall over. But I am very confused about this problem as well ...
From: Ludovic Brenta on 30 Jun 2010 08:20 tonyg writes on comp.lang.ada: >>>> On 30 June, 09:34, tonyg <tonytheg...(a)googlemail.com> wrote: >>>>> I am calling this gnade function in the mysql package to get some >>>>> debug info >>>>> >>>>> Put_Line(To_String(String_Field (TheDatabase, TheHeaterQuery, 1))); >>>>> >>>>> it unfortunately hangs though and the task stops >>>>> >>>>> I am thinking perhaps the whole task has either hung or terminated >>>>> without telling me. >>>>> >>>>> Would gnat tell me if this task had crashed? >>>> >>>> I put the code in a straight procedure and I get a constraint error >>>> which is >>>> >>>> raised CONSTRAINT_ERROR : gnu-db-mysql.adb:883 invalid data >>>> >>>> I am wondering what field types are good to use in a ada mysql >>>> database connection and what I am doing wrong here - has anybody any >>>> ideas ? >>>> >>> Looking at gnu-db-mysql.adb:883 (for gnade 1.6.1 or 1.6.2) indicates >>> that your variable TheHeaterQuery is not initialized. >>> >>> -- >>> Ludovic Brenta. >> >> Do you have some example code I can take a look at that retrieves a >> string from a database? > > btw I use the Nbr_Of_Rows function and I get an answer of 2 which > indicates that the query has operated and retrieved the data correctly > and I try the query out in the mysql query browser to make sure the > query works so I do think the query has correctly initialised but its > when I go to access the string that things fall over. But I am very > confused about this problem as well ... The closest thing to an example is the documentation in gnu-db-mysql.ads; have you read it? In particular, the Query_ID must be the result of calling Query and the Query_ID must not have been dropped. Without your full sources it is very difficult to diagnose your problem any further. From what you say, I have a hunch that maybe you issue the query in one task and then try to use it in another task? Don't do that :) -- Ludovic Brenta.
From: tonyg on 30 Jun 2010 08:53 I've sanistised this source of the password and ip address with GNU.DB.MySQL; with GNU.DB; use GNU.DB.MySQL; use GNU.DB; with Ada.Text_Io; use Ada.Text_Io; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; procedure trymysql is TheDatabase : MySQL.Object; TheQuery : MySQL.Query_Id; TheField : MYSQL.Field_Number; begin Initialize(TheDatabase); User (TheDatabase, "heating"); Password (TheDatabase,""); Connect (TheDatabase,""); Select_DB (TheDatabase, "heating"); TheQuery := Query (TheDatabase, "select * from userid "); TheField := Get_Field_Number (TheDatabase, TheQuery, "email"); put_line ("Number of Rows :" & Integer'Image(Nbr_of_Rows(TheDatabase,TheQuery))); put_line (" Field Number of Email field : " & Integer'Image(TheField)); Put_Line(Natural'image (Get_Field_Length(TheDatabase,TheQuery, 1))); Put_Line(Field_Type'image(Get_Field_Type(TheDatabase,TheQuery, 1))); Put_Line(To_String(String_Field (TheDatabase, TheQuery, "email"))); end trymysql; Out put is tony(a)tony-laptop:~/snugbug/main/adastuff/heating/src$ ./trymysql Number of Rows : 4 Field Number of Email field : 1 14 raised CONSTRAINT_ERROR : gnu-db-mysql.adb:883 invalid data tony(a)tony-laptop:~/snugbug/main/adastuff/heating/src$ Other information is that the email field in the database table is a VARCHAR(80) and a primary key
From: Ludovic Brenta on 1 Jul 2010 05:44 tonyg wrote on comp.lang.ada: > I've sanistised this source of the password and ip address > > with GNU.DB.MySQL; > with GNU.DB; > use GNU.DB.MySQL; > use GNU.DB; > with Ada.Text_Io; use Ada.Text_Io; > with Ada.Strings.Unbounded; > use Ada.Strings.Unbounded; > > procedure trymysql is > > TheDatabase : MySQL.Object; > TheQuery : MySQL.Query_Id; > TheField : MYSQL.Field_Number; > begin > Initialize(TheDatabase); > User (TheDatabase, "heating"); > Password (TheDatabase,""); > Connect (TheDatabase,""); > Select_DB (TheDatabase, "heating"); > > TheQuery := Query (TheDatabase, "select * from userid "); > TheField := Get_Field_Number (TheDatabase, TheQuery, "email"); > > put_line ("Number of Rows :" & > Integer'Image(Nbr_of_Rows(TheDatabase,TheQuery))); > > put_line (" Field Number of Email field : " & > Integer'Image(TheField)); > > Put_Line(Natural'image (Get_Field_Length(TheDatabase,TheQuery, > 1))); > Put_Line(Field_Type'image(Get_Field_Type(TheDatabase,TheQuery, > 1))); > > Put_Line(To_String(String_Field (TheDatabase, TheQuery, > "email"))); > end trymysql; > > Out put is > > tony(a)tony-laptop:~/snugbug/main/adastuff/heating/src$ ./trymysql > Number of Rows : 4 > Field Number of Email field : 1 > 14 > > raised CONSTRAINT_ERROR : gnu-db-mysql.adb:883 invalid data > tony(a)tony-laptop:~/snugbug/main/adastuff/heating/src$ > > Other information is that the email field in the database table is a > VARCHAR(80) and a primary key It seems the exception is not raised in the String_Field line as you initially said, but in the previous line that calls Get_Field_Type directly (String_Field also calls Get_Field_Type). The exception message "invalid data" indicates an uninitialized variable. At first I thought this would be the TheQuery (of type Query_ID) but now I'm not so sure anymore. I suggest you run this small program in a debugger and inspect all the parameters passed to Get_Field_Type. I do not use gnade myself, or MySQL. I no longer maintain gnade in Debian; Stephe Leake took over and dropped support fro MySQL because it was out of sync with recent versions of MySQL. So that, in fact, might be the cause of your problems. What platform do you use? What version of gnade? What version of MySQL? Maybe you should use the ODBC interface instead; it is more stable than the MySQL-specific API. -- Ludovic Brenta.
From: tonyg on 1 Jul 2010 06:19
On Jul 1, 10:44 am, Ludovic Brenta <ludo...(a)ludovic-brenta.org> wrote: > tonyg wrote on comp.lang.ada: > > > > > I've sanistised this source of the password and ip address > > > with GNU.DB.MySQL; > > with GNU.DB; > > use GNU.DB.MySQL; > > use GNU.DB; > > with Ada.Text_Io; use Ada.Text_Io; > > with Ada.Strings.Unbounded; > > use Ada.Strings.Unbounded; > > > procedure trymysql is > > > TheDatabase : MySQL.Object; > > TheQuery : MySQL.Query_Id; > > TheField : MYSQL.Field_Number; > > begin > > Initialize(TheDatabase); > > User (TheDatabase, "heating"); > > Password (TheDatabase,""); > > Connect (TheDatabase,""); > > Select_DB (TheDatabase, "heating"); > > > TheQuery := Query (TheDatabase, "select * from userid "); > > TheField := Get_Field_Number (TheDatabase, TheQuery, "email"); > > > put_line ("Number of Rows :" & > > Integer'Image(Nbr_of_Rows(TheDatabase,TheQuery))); > > > put_line (" Field Number of Email field : " & > > Integer'Image(TheField)); > > > Put_Line(Natural'image (Get_Field_Length(TheDatabase,TheQuery, > > 1))); > > Put_Line(Field_Type'image(Get_Field_Type(TheDatabase,TheQuery, > > 1))); > > > Put_Line(To_String(String_Field (TheDatabase, TheQuery, > > "email"))); > > end trymysql; > > > Out put is > > > tony(a)tony-laptop:~/snugbug/main/adastuff/heating/src$ ./trymysql > > Number of Rows : 4 > > Field Number of Email field : 1 > > 14 > > > raised CONSTRAINT_ERROR : gnu-db-mysql.adb:883 invalid data > > tony(a)tony-laptop:~/snugbug/main/adastuff/heating/src$ > > > Other information is that the email field in the database table is a > > VARCHAR(80) and a primary key > > It seems the exception is not raised in the String_Field line as you > initially said, but in the previous line that calls Get_Field_Type > directly (String_Field also calls Get_Field_Type). The exception > message "invalid data" indicates an uninitialized variable. At first I > thought this would be the TheQuery (of type Query_ID) but now I'm not > so sure anymore. I suggest you run this small program in a debugger > and inspect all the parameters passed to Get_Field_Type. > > I do not use gnade myself, or MySQL. I no longer maintain gnade in > Debian; Stephe Leake took over and dropped support fro MySQL because > it was out of sync with recent versions of MySQL. So that, in fact, > might be the cause of your problems. > > What platform do you use? > What version of gnade? > What version of MySQL? > > Maybe you should use the ODBC interface instead; it is more stable > than the MySQL-specific API. > > -- > Ludovic Brenta. Thanks for your help Ludovic, I'll try the odbc or another binding. |