Archived

This topic is now archived and is closed to further replies.

flukus

MySQL Help!!

Recommended Posts

Hi, I''ve been trying to use a MySQL database for a little app that I''m creating. The trouble is that the database won''t innitialize. I''ve created the sql object: MYSQL *datesdb = NULL; and then I try to innitialize it: mysql_init(datesdb); Which returns a zero, which means no error occured according to the documentation but the pointer is still NULL afterwards. And attempting any other function calls crashes the program. So, any ideas on how to fix this are appreciated!

Share this post


Link to post
Share on other sites
Well datesdb is a pointer so it should do the same thing. The documentation says to pass a null pointer so I figured initializing a MYSQL pointer should be better than using the adress of. I tried adress of anyway and the same problem occured.

Another question though, Is MySQL suitable for a client side database? The stuff I downloaded for it weighs in at 22Mb, but is there a smaller subsection to distribute with it?

Share this post


Link to post
Share on other sites
quote:
Original post by flukus
Well datesdb is a pointer so it should do the same thing.
No it wouldn''t. But, anyway, read the documentation again:
http://www.mysql.com/documentation/mysql/bychapter/manual_Clients.html#mysql_init
. (it is not consistent with how you described it in the original post).

Please post your code, and it might be easier to spot.
quote:
Another question though, Is MySQL suitable for a client side database?
If you mean installing the server at clients, then maybe not. I think there are other "versions" of MySQL available for stuff like that.

Share this post


Link to post
Share on other sites
quote:

19.1.3.31 mysql_init()

MYSQL *mysql_init(MYSQL *mysql)
Description

Allocates or initializes a MYSQL object suitable for mysql_real_connect(). If mysql is a NULL pointer, the function allocates, initializes, and returns a new object. Otherwise, the object is initialized and the address of the object is returned. If mysql_init() allocates a new object, it will be freed when mysql_close() is called to close the connection.
Return Values

An initialized MYSQL* handle. NULL if there was insufficient memory to allocate a new object.
Errors

In case of insufficient memory, NULL is returned.




Is there something I'm missing there, because as far as I can seee thats what I have. Does "MYSQL *mysql_init" mean it's a function pointer or something? Because I've never dealt witht hem befor.

Also, do you know where I can find more information about those other "versions" of MySQL? Or what keywords I should google?

[edited by - flukus on January 24, 2004 7:14:57 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by flukus
quote:

19.1.3.31 mysql_init()

MYSQL *mysql_init(MYSQL *mysql)
Description

Allocates or initializes a MYSQL object suitable for mysql_real_connect(). If mysql is a NULL pointer, the function allocates, initializes, and returns a new object. Otherwise, the object is initialized and the address of the object is returned. If mysql_init() allocates a new object, it will be freed when mysql_close() is called to close the connection.
Return Values

An initialized MYSQL* handle. NULL if there was insufficient memory to allocate a new object.
Errors

In case of insufficient memory, NULL is returned.




Is there something I''m missing there, because as far as I can seee thats what I have. Does "MYSQL *mysql_init" mean it''s a function pointer or something? Because I''ve never dealt witht hem befor.
No function pointer

What I figure, mysql_init() has two modes:

1) You allocate (and is responsible for later freeing) a MYSQL data structure (not just a pointer). In this case you give mysql_init() the address of this structure.

2) You let the library allocate (and freeing) the MYSQL structure. You do this by passing a NULL pointer to mysql_init().

In both cases the function should return the address of the structure, whether you or the function allocated it. You said in the original post that a zero return indicated no error. However, the documentation I quoted previously says that a NULL means error.

So, it seems that MySQL fails to be initialized. I am *very* rusty on MySQL''s C API, but I think you can get what went wrong through the error function (mysql_error()?).
quote:
Also, do you know where I can find more information about those other "versions" of MySQL? Or what keywords I should google?
Actually, no. I''ve heard that there are libraries for "embedded" applications, and as I figure a way to have client and server in the same application. I don''t know any specifics, but you should be able to find info on www.mysql.com or try their mailing list or its archives (available from their site).

Share this post


Link to post
Share on other sites
I tried number 1 befor (sorry, I'm away from my computer right now so I can't try again) something like this:

MYSQL datesdb;

mysql_init(&datesdb);

So should I do something like:

MYSQL *datesdb = NULL;

datesdb = mysql_int(datesdb);

?


quote:

So, it seems that MySQL fails to be initialized. I am *very* rusty on MySQL's C API, but I think you can get what went wrong through the error function (mysql_error()?).



mysql_error() or mysql_errno() require an innitialized MYSQL object >

[edited by - flukus on January 24, 2004 8:22:28 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by flukus
I tried number 1 befor (sorry, I''m away from my computer right now so I can''t try again) something like this:

MYSQL datesdb;

mysql_init(&datesdb);
That will do, but:
quote:
MYSQL *datesdb = NULL;

datesdb = mysql_int(datesdb);
will also work. Although that you pass the null pointer to mysql_init() might indicate that you misunderstand it. This should be enough:

*datesdb = mysql_int(0);

Share this post


Link to post
Share on other sites
Ahh, I see now. It was the (MYSQL *mysql) in the documentation that threw me, I figured it was like the way you pass pointers to directx.

I'll gove it a try when I get home in a couple of days.

[edited by - flukus on January 24, 2004 8:26:16 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by flukus
I figured it was like the way you pass pointers to directx.
Yes, I considered it first too, but you were not passing a pointer to a pointer (which is the case in DirectX), hence my first comment.

Share this post


Link to post
Share on other sites