From: Tomek Walkuski on
Hi,

when interacting with MySQL database I should invoke mysql_library_init
() function first. GNADE does not have it implemented so I tried to do
this on my own:

function mysql_library_init (
argc : int;
argv : chars_ptr;
groups : chars_ptr
) return int;
pragma Import (C, mysql_library_init, "mysql_library_init");

used as:
... := mysql_library_init (0, Null_Ptr, Null_Ptr);

I build my program with -I/usr/include/mysql -L/usr/lib64/mysql -
lmysqlcient and get:
undefined reference to `mysql_library_init'
collect2: ld returned 1 exit status
gnatlink: error when calling /usr/bin/gcc
gnatmake: *** link failed.

I tested my build setting with mysql_init() and mysql_close() and it
is fine, I cannot get mysql_library_init() and mysql_library_end
working.

Simple C application with these functions works.

Any ideas?

From: Maciej Sobczak on
On 5 Gru, 23:41, Tomek Walkuski <tomek.walku...(a)gmail.com> wrote:

> when interacting with MySQL database I should invoke mysql_library_init
> () function first. GNADE does not have it implemented

> Any ideas?

According to MySQL docs, you do not have to call this function,
because mysql_init does it implicitly - you have to just ensure that
you do not call it from multiple threads, which seems straightforward
as it is an initialization function.

You might also want to have a look at the SOCI-Ada library:

http://www.inspirel.com/soci-ada

--
Maciej Sobczak * www.msobczak.com * www.inspirel.com
From: Tomek Walkuski on
On 6 Gru, 00:03, Maciej Sobczak <see.my.homep...(a)gmail.com> wrote:
> According to MySQL docs, you do not have to call this function,
> because mysql_init does it implicitly - you have to just ensure that
> you do not call it from multiple threads, which seems straightforward
> as it is an initialization function.
>
MySQL docs say:

"In a nonmulti-threaded environment, the call to mysql_library_init()
may be omitted, because mysql_init() will invoke it automatically as
necessary. However, mysql_library_init() is not thread-safe in a multi-
threaded environment, and thus neither is mysql_init(), which calls
mysql_library_init(). You must either call mysql_library_init() prior
to spawning any threads, or else use a mutex to protect the call,
whether you invoke mysql_library_init() or indirectly via mysql_init
(). This should be done prior to any other client library call."

So in multi-threaded environment mysql_library_init CANNOT be ommited.

And how about mysql_library_end() ? I could not import it to Ada and
this function performs some memory clean up after disconnection.
From: Stephen Leake on
Tomek Walkuski <tomek.walkuski(a)gmail.com> writes:

> Hi,
>
> when interacting with MySQL database I should invoke mysql_library_init
> () function first. GNADE does not have it implemented so I tried to do
> this on my own:
>
> function mysql_library_init (
> argc : int;
> argv : chars_ptr;
> groups : chars_ptr
> ) return int;
> pragma Import (C, mysql_library_init, "mysql_library_init");
>
> used as:
> ... := mysql_library_init (0, Null_Ptr, Null_Ptr);
>
> I build my program with -I/usr/include/mysql -L/usr/lib64/mysql -
> lmysqlcient and get:
> undefined reference to `mysql_library_init'
> collect2: ld returned 1 exit status
> gnatlink: error when calling /usr/bin/gcc
> gnatmake: *** link failed.
>
> I tested my build setting with mysql_init() and mysql_close() and it
> is fine, I cannot get mysql_library_init() and mysql_library_end
> working.
>
> Simple C application with these functions works.
>
> Any ideas?

Are you building GNADE from scratch? It contains many imports similar
to yours, so it's hard to see why yours would fail but those succeed.

On the other hand, I recently updated the Debian package for GNADE,
and discovered that the MySQL code is severly broken; the Ada types
that are supposed to duplicate C types don't; the C types have
changed.

--
-- Stephe
From: Tomek Walkuski on
On 6 Gru, 16:59, Stephen Leake <stephen_le...(a)stephe-leake.org> wrote:
> Are you building GNADE from scratch? It contains many imports similar
> to yours, so it's hard to see why yours would fail but those succeed.
>
I have prepared small program only for testing purposes. I have tried
to import only these two functions.