www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - DDBI and MySQL

reply "Chris R. Miller" <lordSaurontheGreat gmail.com> writes:
I've been working to attempt to get DDBI to work with MySQL.
Unfortunately I'm stuck with the Windows platform for lack of the
impetus and know-how to get the compiler working elsewhere.

I use a slightly modified version of DDBI to get SQLite to work.  I
don't think that would disrupt the workings of MySQL.

Once I found the correct library file to use (buried in a large download
of MySQL - the server, which was annoying) I found that the whole
she-bang didn't work at all.  It was all tied to a strange external
declaration in imp_win.d, which apparently decided that on Windows the
MySQL support is provided by extern(Windows) instead of extern(C).

Once I got that cleared up, I started a bunch of "cannot implicitly cast
foo* to foo*" errors, which mystified me.  I think it's because one is
tossing an alias of something to something that's expecting the
un-aliased something, and so it's having some issues.

So attempting to fix the issues didn't work terribly well.  I beat
through a few pointer issues to get hung up on a weird pointer issue
which emits this error:

dbi\mysql\MysqlDatabase.d(194): constructor
dbi.mysql.MysqlResult.MysqlResult.th
is (st_mysql_res*) does not match parameter types (st_mysql_res*)
dbi\mysql\MysqlDatabase.d(194): Error: cannot implicitly convert
expression (cas
t(st_mysql_res*)*results) of type st_mysql_res* to st_mysql_res*

I'm pretty puzzled.  I've tried casting it explicitly, and it doesn't
work.  I'd really appreciate it if someone knew what is going on.  When
I explicitly cast it, it still give the same error.

This is DMD version 1.033.
Aug 29 2008
next sibling parent reply Don <nospam nospam.com.au> writes:
Chris R. Miller wrote:
 I've been working to attempt to get DDBI to work with MySQL.
 Unfortunately I'm stuck with the Windows platform for lack of the
 impetus and know-how to get the compiler working elsewhere.
 
 I use a slightly modified version of DDBI to get SQLite to work.  I
 don't think that would disrupt the workings of MySQL.
 
 Once I found the correct library file to use (buried in a large download
 of MySQL - the server, which was annoying) I found that the whole
 she-bang didn't work at all.  It was all tied to a strange external
 declaration in imp_win.d, which apparently decided that on Windows the
 MySQL support is provided by extern(Windows) instead of extern(C).
I hope you changed that to extern(System) ? It sounds like an old MySQL file.
 
 Once I got that cleared up, I started a bunch of "cannot implicitly cast
 foo* to foo*" errors, which mystified me.  I think it's because one is
 tossing an alias of something to something that's expecting the
 un-aliased something, and so it's having some issues.
 
 So attempting to fix the issues didn't work terribly well.  I beat
 through a few pointer issues to get hung up on a weird pointer issue
 which emits this error:
 
 dbi\mysql\MysqlDatabase.d(194): constructor
 dbi.mysql.MysqlResult.MysqlResult.th
 is (st_mysql_res*) does not match parameter types (st_mysql_res*)
 dbi\mysql\MysqlDatabase.d(194): Error: cannot implicitly convert
 expression (cas
 t(st_mysql_res*)*results) of type st_mysql_res* to st_mysql_res*
 
 I'm pretty puzzled.  I've tried casting it explicitly, and it doesn't
 work.  I'd really appreciate it if someone knew what is going on.  When
 I explicitly cast it, it still give the same error.
 
 This is DMD version 1.033.
 
Aug 29 2008
parent reply "Chris R. Miller" <lordSaurontheGreat gmail.com> writes:
Don wrote:
 Chris R. Miller wrote:
 I've been working to attempt to get DDBI to work with MySQL.
 Unfortunately I'm stuck with the Windows platform for lack of the
 impetus and know-how to get the compiler working elsewhere.

 I use a slightly modified version of DDBI to get SQLite to work.  I
 don't think that would disrupt the workings of MySQL.

 Once I found the correct library file to use (buried in a large downlo=
ad
 of MySQL - the server, which was annoying) I found that the whole
 she-bang didn't work at all.  It was all tied to a strange external
 declaration in imp_win.d, which apparently decided that on Windows the=
 MySQL support is provided by extern(Windows) instead of extern(C).
=20 I hope you changed that to extern(System) ? It sounds like an old MySQL=
 file.
No, it all links properly with extern(C).
Aug 29 2008
parent reply Max Samukha <samukha voliacable.com.removethis> writes:
On Fri, 29 Aug 2008 01:07:35 -0700, "Chris R. Miller"
<lordSaurontheGreat gmail.com> wrote:

Don wrote:
 Chris R. Miller wrote:
 I've been working to attempt to get DDBI to work with MySQL.
 Unfortunately I'm stuck with the Windows platform for lack of the
 impetus and know-how to get the compiler working elsewhere.

 I use a slightly modified version of DDBI to get SQLite to work.  I
 don't think that would disrupt the workings of MySQL.

 Once I found the correct library file to use (buried in a large download
 of MySQL - the server, which was annoying) I found that the whole
 she-bang didn't work at all.  It was all tied to a strange external
 declaration in imp_win.d, which apparently decided that on Windows the
 MySQL support is provided by extern(Windows) instead of extern(C).
I hope you changed that to extern(System) ? It sounds like an old MySQL file.
No, it all links properly with extern(C).
MySQL API uses stdcall calling convention on Windows so extern(Windows) in imp_win.d is correct. Here is an import library for libmysql.dll that works for me http://d-coding.com/downloads/libmysql.lib
Aug 29 2008
parent reply "Chris R. Miller" <lordSaurontheGreat gmail.com> writes:
Max Samukha wrote:
 On Fri, 29 Aug 2008 01:07:35 -0700, "Chris R. Miller"
 <lordSaurontheGreat gmail.com> wrote:
=20
 Don wrote:
 Chris R. Miller wrote:
 I've been working to attempt to get DDBI to work with MySQL.
 Unfortunately I'm stuck with the Windows platform for lack of the
 impetus and know-how to get the compiler working elsewhere.

 I use a slightly modified version of DDBI to get SQLite to work.  I
 don't think that would disrupt the workings of MySQL.

 Once I found the correct library file to use (buried in a large down=
load
 of MySQL - the server, which was annoying) I found that the whole
 she-bang didn't work at all.  It was all tied to a strange external
 declaration in imp_win.d, which apparently decided that on Windows t=
he
 MySQL support is provided by extern(Windows) instead of extern(C).
I hope you changed that to extern(System) ? It sounds like an old MyS=
QL
 file.
No, it all links properly with extern(C).
=20 MySQL API uses stdcall calling convention on Windows so extern(Windows) in imp_win.d is correct. Here is an import library for libmysql.dll that works for me http://d-coding.com/downloads/libmysql.lib
Changed it back to extern(Windows) and still no joy. I also tried using your supplied library file, but nothing worked, either. As soon as I changed it from extern(C) I was greeted by these errors thou= gh: dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_init 4 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_real_connect 32 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_errno 4 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_error 4 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _D3dbi5mysql10MysqlError17specificToGeneralFkZE3dbi9 ErrorCode9ErrorCode dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_close 4 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_real_query 12 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_store_result 4 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_insert_id 4 dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _mysql_get_client_version 0 dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult) Error 42: Symbol Undefined _mysql_fetch_row 4 dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult) Error 42: Symbol Undefined _mysql_fetch_lengths 4 dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult) Error 42: Symbol Undefined _mysql_free_result 4 dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult) Error 42: Symbol Undefined _mysql_num_fields 4 dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult) Error 42: Symbol Undefined _mysql_fetch_fields 4 I'm not an expert at all, but I think that's because it can't discover the functions to link against. If I change it back to extern(C) I get th= is: dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase) Error 42: Symbol Undefined _D3dbi5mysql10MysqlError17specificToGeneralFkZE3dbi9 ErrorCode9ErrorCode Which is a regression from what I had when I had changed it to ignore imp_win.d and to use imp.d instead. So I'm thoroughly confused. I suspect that I *almost* had it working with the imp.d save for the cast problems (which could be a compiler bug - if it's not, then there's a lot I'm going to be learning about pointers in my upcoming CS 102 class!)
Aug 29 2008
parent Max Samukha <samukha voliacable.com.removethis> writes:
On Fri, 29 Aug 2008 20:16:22 -0700, "Chris R. Miller"
<lordSaurontheGreat gmail.com> wrote:

dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_init 4
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_real_connect 32
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_errno 4
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_error 4
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined
_D3dbi5mysql10MysqlError17specificToGeneralFkZE3dbi9
ErrorCode9ErrorCode
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_close 4
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_real_query 12
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_store_result 4
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_insert_id 4
dsss_objs\D\dbi-mysql-MysqlDatabase.obj(dbi-mysql-MysqlDatabase)
 Error 42: Symbol Undefined _mysql_get_client_version 0
dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult)
 Error 42: Symbol Undefined _mysql_fetch_row 4
dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult)
 Error 42: Symbol Undefined _mysql_fetch_lengths 4
dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult)
 Error 42: Symbol Undefined _mysql_free_result 4
dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult)
 Error 42: Symbol Undefined _mysql_num_fields 4
dsss_objs\D\dbi-mysql-MysqlResult.obj(dbi-mysql-MysqlResult)
 Error 42: Symbol Undefined _mysql_fetch_fields 4
All those symbols are exported by the lib I supplied. I guess you are still trying to link against a wrong lib. Check your lib paths.
I'm not an expert at all, but I think that's because it can't discover
the functions to link against.  If I change it back to extern(C) I get this:
Even if you manage to link using extern(C), your program won't work correctly, because C and Windows calling conventions differ not only in name decorations. So you must use either extern(Windows) or extern(System).
Aug 30 2008
prev sibling parent reply Fawzi Mohamed <fmohamed mac.com> writes:
On 2008-08-29 09:47:30 +0200, "Chris R. Miller" 
<lordSaurontheGreat gmail.com> said:

 [...]
 Once I got that cleared up, I started a bunch of "cannot implicitly cast
 foo* to foo*" errors, which mystified me.  I think it's because one is
 tossing an alias of something to something that's expecting the
 un-aliased something, and so it's having some issues.
 
 So attempting to fix the issues didn't work terribly well.  I beat
 through a few pointer issues to get hung up on a weird pointer issue
 which emits this error:
 
 dbi\mysql\MysqlDatabase.d(194): constructor
 dbi.mysql.MysqlResult.MysqlResult.th
 is (st_mysql_res*) does not match parameter types (st_mysql_res*)
 dbi\mysql\MysqlDatabase.d(194): Error: cannot implicitly convert
 expression (cas
 t(st_mysql_res*)*results) of type st_mysql_res* to st_mysql_res*
 
 I'm pretty puzzled.  I've tried casting it explicitly, and it doesn't
 work.  I'd really appreciate it if someone knew what is going on.  When
 I explicitly cast it, it still give the same error.
I had a similar error today in my template code with int* and int* (I think also connected with aliases and nesting of templates). I haven't distilled it yet, but using cast(T*)(cast(size_t)a+cast(size_t)b) in my case fixed the issue... Fawzi
Aug 29 2008
parent "Chris R. Miller" <lordSaurontheGreat gmail.com> writes:
Fawzi Mohamed wrote:
 On 2008-08-29 09:47:30 +0200, "Chris R. Miller"
 <lordSaurontheGreat gmail.com> said:
=20
 [...]
 Once I got that cleared up, I started a bunch of "cannot implicitly ca=
st
 foo* to foo*" errors, which mystified me.  I think it's because one is=
 tossing an alias of something to something that's expecting the
 un-aliased something, and so it's having some issues.

 So attempting to fix the issues didn't work terribly well.  I beat
 through a few pointer issues to get hung up on a weird pointer issue
 which emits this error:

 dbi\mysql\MysqlDatabase.d(194): constructor
 dbi.mysql.MysqlResult.MysqlResult.th
 is (st_mysql_res*) does not match parameter types (st_mysql_res*)
 dbi\mysql\MysqlDatabase.d(194): Error: cannot implicitly convert
 expression (cas
 t(st_mysql_res*)*results) of type st_mysql_res* to st_mysql_res*

 I'm pretty puzzled.  I've tried casting it explicitly, and it doesn't
 work.  I'd really appreciate it if someone knew what is going on.  Whe=
n
 I explicitly cast it, it still give the same error.
=20 I had a similar error today in my template code with int* and int* (I think also connected with aliases and nesting of templates). I haven't distilled it yet, but using =20 cast(T*)(cast(size_t)a+cast(size_t)b) =20 in my case fixed the issue... =20 Fawzi
Glad it worked for you! I wasn't so lucky.
Aug 29 2008