comp.lang.ada
 help / color / mirror / Atom feed
* QtSql problem
@ 2009-02-06  4:43 tworoses1
  2009-02-06  8:27 ` Vadim Godunko
  0 siblings, 1 reply; 14+ messages in thread
From: tworoses1 @ 2009-02-06  4:43 UTC (permalink / raw)


I'm trying to do some basic stuff with QtSql (a part of QtAda) but I
just can't figure it out.

      declare
         Query : constant Qt4.Sql_Queries.Q_Sql_Query
           := Qt4.Sql_Queries.Create (DB);
      begin

         Query.Exec (Qt4.Strings.From_Utf_16
                   ("create table images (id tinyint primary key, "
                      & "filename varchar(20))"));
         Query.Exec (Qt4.Strings.From_Utf_16
                   ("insert into images values(1, 'hello.jpg')"));

         Query.Exec(Qt4.Strings.From_Utf_16
                 ("select * from images"));

         while (Query.Next) loop
            Filename := Query.Value(0).To_String;
         end loop;

      end;

Compiles fine but crashes with:

raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
[2009-02-06 15:37:27] process exited with status1 (elapsed time:
00.59s)

Any ideas?

Thanks,
Claire.



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

* Re: QtSql problem
  2009-02-06  4:43 QtSql problem tworoses1
@ 2009-02-06  8:27 ` Vadim Godunko
  2009-02-06  8:31   ` Gautier
  0 siblings, 1 reply; 14+ messages in thread
From: Vadim Godunko @ 2009-02-06  8:27 UTC (permalink / raw)


On Feb 6, 5:43 am, tworos...@gmail.com wrote:
>
> Compiles fine but crashes with:
>
> raised PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION
> [2009-02-06 15:37:27] process exited with status1 (elapsed time:
> 00.59s)
>
> Any ideas?
>
Can you please rebuild your program with the -E binder's switch? This
enables to store traceback information in the exception occurrence, so
we can see where the exception occurs.

PS. The better place to ask QtAda related questions is the qtada-
users@lists.qtada.com list.

http://lists.qtada.com/mailman/listinfo/qtada-users_lists.qtada.com



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

* Re: QtSql problem
  2009-02-06  8:27 ` Vadim Godunko
@ 2009-02-06  8:31   ` Gautier
  2009-02-06 18:21     ` tworoses1
  2009-02-07 21:17     ` Georg Bauhaus
  0 siblings, 2 replies; 14+ messages in thread
From: Gautier @ 2009-02-06  8:31 UTC (permalink / raw)


Vadim Godunko wrote:

 > Can you please rebuild your program with the -E binder's switch? This
 > enables to store traceback information in the exception occurrence, so
 > we can see where the exception occurs.

He also may need to display the traceback...
------------------------------------------------------------------------------
--  File:            TB_Wrap.ads
--  Description:     Trace-back wrapper for GNAT 3.13p+ (spec.)
------------------------------------------------------------------------------

generic

   with procedure My_main_procedure;

procedure TB_Wrap;
------------------------------------------------------------------------------
--  File:            TB_Wrap.adb
--  Description:     Trace-back wrapper for GNAT 3.13p+ (body)
------------------------------------------------------------------------------

with GNAT.Traceback.Symbolic, Ada.Exceptions, Ada.Text_IO;
use Ada.Exceptions, Ada.Text_IO;

procedure TB_Wrap is
   --  pragma Compiler_options("-g");
   --  pragma Binder_options("-E");
begin
   My_main_procedure;
exception
   when E: others =>
     New_Line;
     Put_Line("--------------------[ Unhandled exception ]-----------------");
     Put_Line(" > Name of exception . . . . .: " &
              Ada.Exceptions.Exception_Name(E) );
     Put_Line(" > Message for exception . . .: " &
              Ada.Exceptions.Exception_Message(E) );
     Put_Line(" > Trace-back of call stack: " );
     Put_Line( GNAT.Traceback.Symbolic.Symbolic_Traceback(E) );
end TB_Wrap;
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



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

* Re: QtSql problem
  2009-02-06  8:31   ` Gautier
@ 2009-02-06 18:21     ` tworoses1
  2009-02-06 19:56       ` Gautier
  2009-02-06 22:51       ` sjw
  2009-02-07 21:17     ` Georg Bauhaus
  1 sibling, 2 replies; 14+ messages in thread
From: tworoses1 @ 2009-02-06 18:21 UTC (permalink / raw)


I should have mentioned in my first post that if I comment out the
line 'Filename := Query.Value(0).To_String;' I don't get the error.

Here's what I get after binding with -E

Execution terminated by unhandled exception
Exception name: PROGRAM_ERROR
Message: EXCEPTION_ACCESS_VIOLATION
Call stack traceback locations:
0x2b31dc5 0x77cc3097 0x77cc3069 0x77cc2efd 0x61f0129e
[2009-02-07 05:06:38] process exited with status1 (elapsed time:
00.41s)

When I make tb_wrap I get:
  Builder results (1 item)
    b~tb_wrap.adb (1 item)
      182:1 undefined reference to `_ada_tb_wrap'

Line 182 of b~tb_wrap.adb is '      Ada_Main_Program;'

Thanks for the help



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

* Re: QtSql problem
  2009-02-06 18:21     ` tworoses1
@ 2009-02-06 19:56       ` Gautier
  2009-02-06 20:44         ` tworoses1
  2009-02-06 22:51       ` sjw
  1 sibling, 1 reply; 14+ messages in thread
From: Gautier @ 2009-02-06 19:56 UTC (permalink / raw)


tworoses1@gmail.com:
> When I make tb_wrap I get:
>   Builder results (1 item)
>     b~tb_wrap.adb (1 item)
>       182:1 undefined reference to `_ada_tb_wrap'
> 
> Line 182 of b~tb_wrap.adb is '      Ada_Main_Program;'

TB_Wrap is generic, there is no sense to build them
(it's mysterious why this version of GNAT even tries to bind it).

Say, your program is QtSQL_Test. Then you make a mini file
QtSQL_Test_TB.ads with this:

with TB_Wrap, QtSQL_Test;
procedure QtSQL_Test_TB is new TB_Wrap(QtSQL_Test);

and you build QtSQL_Test_TB and you have your nice trace-back (you could ask: why the hell AdaCore 
just doesn't integrate something like the few lines of TB_Wrap in their binder code ?).
_________________________________________________________
Gautier's Ada programming -- http://sf.net/users/gdemont/
NB: For a direct answer, e-mail address on the Web site!



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

* Re: QtSql problem
  2009-02-06 19:56       ` Gautier
@ 2009-02-06 20:44         ` tworoses1
  0 siblings, 0 replies; 14+ messages in thread
From: tworoses1 @ 2009-02-06 20:44 UTC (permalink / raw)


Whoops, sorry about that.

I made movie_tb.ads:
with TB_Wrap, Movie;
procedure Movie_TB is new TB_Wrap(Movie);

but when I run it I still get

Execution terminated by unhandled exception
Exception name: PROGRAM_ERROR
Message: EXCEPTION_ACCESS_VIOLATION
Call stack traceback locations:
0x2ed1dc5 0x77cc3097 0x77cc3069 0x77cc2efd 0x61f0129e
[2009-02-07 07:39:01] process exited with status1 (elapsed time:
00.42s)

I think it's working though, because I've been deleting the sqlite db
file before running the program and if I don't delete it and run
movie_tb.ads I get:

--------------------[ Unhandled exception ]-----------------
 > Name of exception . . . . .: PROGRAM_ERROR
 > Message for exception . . .: qt4-sql_queries.adb:424 explicit raise
 > Trace-back of call stack:
03108ECB in ?? at ??:0
0040261C in ?? at crtstuff.c:0
00402C1D in ada_movie_tb at tb_wrap.adb:8
00401CD8 in main at b~movie_tb.adb:624
00401235 in ?? at crtstuff.c:0
00401286 in ?? at crtstuff.c:0
7656E3F1 in ?? at ??:0
77D1CFEB in ?? at ??:0
77D1D1FD in ?? at ??:0

[2009-02-07 07:27:20] process terminated successfully (elapsed time:
00.28s)



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

* Re: QtSql problem
  2009-02-06 18:21     ` tworoses1
  2009-02-06 19:56       ` Gautier
@ 2009-02-06 22:51       ` sjw
  2009-02-08  0:09         ` tworoses1
  1 sibling, 1 reply; 14+ messages in thread
From: sjw @ 2009-02-06 22:51 UTC (permalink / raw)


On Feb 6, 6:21 pm, tworos...@gmail.com wrote:
> I should have mentioned in my first post that if I comment out the
> line 'Filename := Query.Value(0).To_String;' I don't get the error.

Googling for 'EXCEPTION_ACCESS_VIOLATION comp.lang.ada' on Google
shows this is usually puzzling and possibly stack-overflow-related.

I think you need to rebuild the whole with -g (for example, gnatmake -
f -g ...) to get more info about what's happening inside your main
program.

You might be able to use addr2line -- for example,

  $ addr2line -e my_program 0x2ed1dc5 0x77cc3097 0x77cc3069 0x77cc2efd
0x61f0129e

However, (esp considering that you don't get the problem if you
comment out that line, and that the traceback isn't very deep) it
looks as though the exception is happening at the assignment rather
than within the call.

What sort of thing is 'Filename'?



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

* Re: QtSql problem
  2009-02-06  8:31   ` Gautier
  2009-02-06 18:21     ` tworoses1
@ 2009-02-07 21:17     ` Georg Bauhaus
  2009-02-10  3:09       ` Randy Brukardt
  1 sibling, 1 reply; 14+ messages in thread
From: Georg Bauhaus @ 2009-02-07 21:17 UTC (permalink / raw)


Gautier wrote:

> ------------------------------------------------------------------------------
> 
> --  File:            TB_Wrap.ads
> --  Description:     Trace-back wrapper for GNAT 3.13p+ (spec.)
> ------------------------------------------------------------------------------
> 
> 
> generic
> 
>   with procedure My_main_procedure;
> 
> procedure TB_Wrap;

However obvious this generic might be to those well versed
in Ada programming, TB_Wrap continues to deserve 5 stars. :-)

At least one non-GNAT Ada compiler produces tracebacks by
default, that is, ObjectAda. What do other compilers do?



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

* Re: QtSql problem
  2009-02-06 22:51       ` sjw
@ 2009-02-08  0:09         ` tworoses1
  2009-02-09 14:04           ` Vadim Godunko
  0 siblings, 1 reply; 14+ messages in thread
From: tworoses1 @ 2009-02-08  0:09 UTC (permalink / raw)


> I think you need to rebuild the whole with -g (for example, gnatmake -
> f -g ...) to get more info about what's happening inside your main
> program.

I have been building with -g.

>You might be able to use addr2line -- for example,

C:\Users\Claire\Ada\movie>addr2line -e movie.exe 0x2ed1dc5 0x77cc3097
0x77
cc3069 0x77cc2efd
??:0
??:0
??:0
??:0

I guess it didn't work :\

> What sort of thing is 'Filename'?

It's a Qt4.Strings.Q_String

The whole thing is: http://pastebin.com/f54bd5bab

I get this when I go Build > Make > movie.adb in GPS:

gnatmake -PC:\Users\Claire\Ada\movie\movie.gpr movie.adb -d
gcc -c -g -g -I- -gnatA C:\Users\Claire\Ada\movie\movie.adb
gnatbind -shared -E -I- -x C:\Users\Kyle\Programming\movie\movie.ali
gnatlink C:\Users\Claire\Ada\movie\movie.ali -shared-libgcc -g -
fprofile-generate -LC:\GNAT\2008\bin -lQtAdaGui -LC:\GNAT\2008\bin -
lQtAdaSql -LC:\GNAT\2008\bin -lQtAdaCore -o C:\Users\Claire\Ada\movie
\movie.exe

[2009-02-08 10:39:33] process terminated successfully (elapsed time:
02.33s)

Then I delete the file 'userdata' from C:\Users\Claire\Ada\movie\
which is the sqlite file that gets left after I run movie.exe and
makes movie.exe crash if it's not deleted.  Then I go Build > Run >
movie.exe in GPS, uncheck Use External Terminal in the Arguments
Selection box that pops up and hit OK.  Then I get:
C:\Users\Claire\Ada\movie\movie

Execution terminated by unhandled exception
Exception name: PROGRAM_ERROR
Message: EXCEPTION_ACCESS_VIOLATION
Call stack traceback locations:
0x2901dc5 0x77cc3097 0x77cc3069 0x77cc2efd 0x61f0129e
[2009-02-08 10:46:11] process exited with status1 (elapsed time:
00.40s)



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

* Re: QtSql problem
  2009-02-08  0:09         ` tworoses1
@ 2009-02-09 14:04           ` Vadim Godunko
  2009-02-09 15:55             ` Ivan Levashew
  0 siblings, 1 reply; 14+ messages in thread
From: Vadim Godunko @ 2009-02-09 14:04 UTC (permalink / raw)


On Feb 8, 3:09 am, tworos...@gmail.com wrote:
>
> Execution terminated by unhandled exception
> Exception name: PROGRAM_ERROR
> Message: EXCEPTION_ACCESS_VIOLATION
> Call stack traceback locations:
> 0x2901dc5 0x77cc3097 0x77cc3069 0x77cc2efd 0x61f0129e
> [2009-02-08 10:46:11] process exited with status1 (elapsed time:
> 00.40s)

I reproduced the behavior, here is two problems: first in your code -
Program_Error raised because error occurred until Query.Exec
execution; and second - even if statement executed successfully QtAda
has bug in Query.Value subprogram.

I recommend you download and use new QtAda snapshot, see

http://www.qtada.com/en/download.html

PS. Here is my test program, it also explains some changes in the
QtSql API:

with Qt4.Sql_Databases;
with Qt4.Sql_Errors;
with Qt4.Sql_Queries;
with Qt4.Strings;

procedure Test_296 is
   use type Qt4.Strings.Q_String;

   DB : aliased Qt4.Sql_Databases.Q_Sql_Database
     := Qt4.Sql_Databases.Add_Database (Qt4.Strings.From_Utf_16
("QSQLITE"));

begin
   DB.Set_Database_Name (Qt4.Strings.From_Utf_16 (":memory:"));

   if not DB.Open then
      raise Program_Error with "Unable to open database";
   end if;

   declare
      Query : aliased Qt4.Sql_Queries.Q_Sql_Query
        := Qt4.Sql_Queries.Create (DB);

   begin
      if not Query.Exec
              (Qt4.Strings.From_Utf_16
                ("CREATE TABLE images"
                   & " (id INTEGER PRIMARY KEY,"
                   & "  filename CHARACTER VARYING (20))"))
      then
         raise Program_Error with "Unable to create table";
      end if;

      if not Query.Exec
              (Qt4.Strings.From_Utf_16
                ("INSERT INTO images VALUES (1, 'hello.jpg')"))
      then
         raise Program_Error with "Unable to insert data";
      end if;

      if not Query.Exec
              (Qt4.Strings.From_Utf_16
                ("SELECT id, filename FROM images"))
      then
         raise Program_Error with "Unable to select data";
      end if;

      while Query.Next loop
         if Query.Value (0).To_String /= Qt4.Strings.From_Utf_16 ("1")
then
            raise Program_Error with "Invalid value for field #0";
         end if;

         if Query.Value (1).To_String
              /= Qt4.Strings.From_Utf_16 ("hello.jpg")
         then
            raise Program_Error with "Invalid value for field #1";
         end if;
      end loop;

      if not Query.Exec
              (Qt4.Strings.From_Utf_16 ("SELECT idx FROM images"))
      then
         declare
            Error : Qt4.Sql_Errors.Q_Sql_Error := Query.Last_Error;

         begin
            if Error.Text
                 /= Qt4.Strings.From_Utf_16
                     ("no such column: idx Unable to execute
statement")
            then
               raise Program_Error with "Unexpected error";
            end if;
         end;

      else
         raise Program_Error with "Invalid result of the query";
      end if;
   end;
end Test_296;



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

* Re: QtSql problem
  2009-02-09 14:04           ` Vadim Godunko
@ 2009-02-09 15:55             ` Ivan Levashew
  2009-02-10 10:32               ` Vadim Godunko
  0 siblings, 1 reply; 14+ messages in thread
From: Ivan Levashew @ 2009-02-09 15:55 UTC (permalink / raw)


Vadim Godunko wrote:
>               (Qt4.Strings.From_Utf_16
>                 ("CREATE TABLE images"
>                    & " (id INTEGER PRIMARY KEY,"
>                    & "  filename CHARACTER VARYING (20))"))

Why don't you guys locally rename Qt4.Strings.From_Utf_16 as "+"?

-- 
If you want to get to the top, you have to start at the bottom



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

* Re: QtSql problem
  2009-02-07 21:17     ` Georg Bauhaus
@ 2009-02-10  3:09       ` Randy Brukardt
  0 siblings, 0 replies; 14+ messages in thread
From: Randy Brukardt @ 2009-02-10  3:09 UTC (permalink / raw)


"Georg Bauhaus" <see.reply.to@maps.futureapps.de> wrote in message 
news:498dfa7f$0$30231$9b4e6d93@newsspool1.arcor-online.net...
...
> However obvious this generic might be to those well versed
> in Ada programming, TB_Wrap continues to deserve 5 stars. :-)
>
> At least one non-GNAT Ada compiler produces tracebacks by
> default, that is, ObjectAda. What do other compilers do?

Janus/Ada has *always* generated complete tracebacks with names and line 
numbers. Even on the compiler that ran on and targeted 48K Z80 CP/M machines 
back in 1981. We learned early on (from using a several compilers that had 
such tracebacks and some that did not at the University of Wisconsin) how 
much easier it was to debug programs with proper tracebacks. I recall 
beating my head against a wall with the original Unix C compiler, whose only 
run-time error message was "bus error - core dumped" (that's the complete 
message!) -- didn't want to do that with our own compiler.

We do provide an option for turning the overhead of the trace back off, but 
it generally is needed only in the most speed-critical routines. (There is a 
also an easy method for turning off the overhead in the runtime for our 
embedded customers, but hardly any of them have used it.)

I recall complaining to Tucker and the rest of the Ada 9x team that the 
definition of Ada.Exception_Information made it hard to include a full 
walkback. The definition was changed somewhat, and indeed, Janus/Ada 
includes a truncated version of the walkback in Exception_Information.

My limited experience with other Ada compilers is that most include a 
traceback by default -- a common feature that I link to think came about in 
part because their customers complained that the "cheap" Janus/Ada had this 
useful feature, and their expensive compilers didn't. (I know that happened 
because several customers have told me that they made such complaints at one 
point or another.)

                                                      Randy Brukardt.





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

* Re: QtSql problem
  2009-02-09 15:55             ` Ivan Levashew
@ 2009-02-10 10:32               ` Vadim Godunko
  2009-02-13  4:21                 ` tworoses1
  0 siblings, 1 reply; 14+ messages in thread
From: Vadim Godunko @ 2009-02-10 10:32 UTC (permalink / raw)


On Feb 9, 6:55 pm, Ivan Levashew <octag...@bluebottle.com> wrote:
> Vadim Godunko wrote:
> >               (Qt4.Strings.From_Utf_16
> >                 ("CREATE TABLE images"
> >                    & " (id INTEGER PRIMARY KEY,"
> >                    & "  filename CHARACTER VARYING (20))"))
>
> Why don't you guys locally rename Qt4.Strings.From_Utf_16 as "+"?
>
I avoid to use this trick, because it may hide real picture from the
beginners.



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

* Re: QtSql problem
  2009-02-10 10:32               ` Vadim Godunko
@ 2009-02-13  4:21                 ` tworoses1
  0 siblings, 0 replies; 14+ messages in thread
From: tworoses1 @ 2009-02-13  4:21 UTC (permalink / raw)


Thanks heaps, Vadim.  It's working great now.




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

end of thread, other threads:[~2009-02-13  4:21 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-06  4:43 QtSql problem tworoses1
2009-02-06  8:27 ` Vadim Godunko
2009-02-06  8:31   ` Gautier
2009-02-06 18:21     ` tworoses1
2009-02-06 19:56       ` Gautier
2009-02-06 20:44         ` tworoses1
2009-02-06 22:51       ` sjw
2009-02-08  0:09         ` tworoses1
2009-02-09 14:04           ` Vadim Godunko
2009-02-09 15:55             ` Ivan Levashew
2009-02-10 10:32               ` Vadim Godunko
2009-02-13  4:21                 ` tworoses1
2009-02-07 21:17     ` Georg Bauhaus
2009-02-10  3:09       ` Randy Brukardt

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