Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySql VCL Connector

Status
Not open for further replies.

Prattaratt

Technical User
Aug 6, 2000
291
US
Does anyone out there have knowledge of a FREE VCL component library that would facilitate direct connections to a MySql Backend over the internet? I have tried ODBC connections, and this works fine for most of our offices, but we have a few that have extremely slow connections, and the connection does not get made (think it may be timing out, as these offices are on Hughes net). I have downloaded MySQL's CPP connector libray, but still have not been able to get it compiled yet. Any suggestions would be welcomed
 
I believe there are some VCL components download-able from SourceForge.net I haven't tried them myself, so I cannot make any comment one way or the other.

I have not had success making the CPP connector from MySQL work, HOWEVER, I have gotten the C API to work (compile and actually transfer data back and forth from and to the server). There are a number of things you have to do, but the API does work with BCB. Several of the header files associated with the C API installation have to be 'amended' and there is one whole header file missing with the installation. Once you handle that, you can use the C API. The C API does use the "libmysql.dll" 'delivered' with practically everything downloaded from MySQL.

If you are interested, I can try my best to 'compile' my notes this evening as the work was done with my home PC.

You were specific about a "FREE VCL component" - I got that. That said, there are some very good components available for purchase.

Steve.
 
Hello Steve (smays),

While I'm not directly interested in the subject of the original post, I would be VERY interested in learning more about how you got the MySQL C API (not the C++ API) working from BCB.

If your kind offer to compile your notes on what tweaks you made to the MySQL C header files to make them BCB friendly is still on the table, I would very much appreciate it.

FYI -- Like you, I actually have achieved connectivity and basic queries with MySQL via the C API from Borland C++ Builder 6.0, but did this by excluding some of the required-or-recommended header files, specifically my_global.h and my_sys.h. Including mysql.h works fine. My concern with the exclusions is that some MACROS are not defined (not noticing a problem so far, but...) and apparently one of those header files is for Windows/Linus compatibility (ultimately this code will be compiled on Linux as well, and I'm concerned about potential data-type compatibility).

Also, I couldn't link with mysqlclient.lib as documented, but instead ran "implib libmysql_borland.lib libmysql.dll" and linked with the resulting .lib file instead (found this solution on the web and to my pleasant surprise, it seems to have worked -- unfortunately, I came across no solution to the header file problems).

I hope you are able to take the time to post your notes -- if so, THANK YOU VERY MUCH in advance.

Cheers,
-Brian
 
Although my "kind offer" is still on the table, basically I did everything you said and got the same results, so I really have little to show.

Sorry.

Steve.
 
Hey Steve,

although I'm saddened by its content, I quite appreciate your reply :).
Let's please keep each other posted here with any progress on this problem of compiling the C header files from the MySQL C API from Borland C++ Builder (BCB) (I'm spelling it out again here for the search engines).

Cheers and thanks!
-Brian
 
Here is a link to an article entitled "include MYSQL C API into Borland C++ Builder (BCB) Application" that I just came across:


Note that I have not attempted the header file modification described there, as I still have not run into problems doing what I described above, and of course prefer to not have to re-modify the MySQL headers every time we upgrade to a newer MySQL C API version. But I recognize that I still may have to go that route if any hiccups occur with my current technique.

Cheers,
-Brian
 
Thanks for the link, Brian. I am like you, I would hate to have to update the header file(s) every time I upgraded the C API. The trick is to convince MySQL to correct the header file(s) that ship with the C API product. I know the header files can be fixed to work with BCB without a lot of work, because I can download the SQLite amalgamation today, include it in a program, and compile/use it without any problem.

Steve.
 
Hey Steve,

another BCB requirement: it seems necessary to include the mysql.h file with QUAD WORD (8 byte) data alignment active. Since my BCB project settings are set to default to BYTE (1 byte) alignment, I used the following #pragma wrappers around the include:

Code:
#pragma pack(push, 8)
#include <mysql.h>
#pragma pack(pop)

This requirement only became apparent when I tried to bind 2 or more parameters to a Prepared Statement (via mysql_stmt_bind_param(...)). The above fixed the memory access exceptions that were triggered by the MySQL layer code.

Now if you have any pointers to a working thread-safe connection pool for this API, I'd appreciate any info! Haven't tried it myself yet, but googling has so far only turned up articles of concern regarding using a connection handle created in one thread by another thread.

Cheers again,
-Brian

 
For posterity, here's another requirement to get the application-side structure instances the same size as those expected in the MySQL dll: enums must be the size of ints. This was not the default setting in my BCB project, nor did I want to make it so, so here is how I did it in my source .c file:

Code:
#pragma option push -b	// Ensure 4-byte enums for Borland C
#pragma pack(push, 8)	// 8-byte data alignment for Borland C
#include <mysql.h>
#pragma pack(pop)
#pragma option pop

This requirement was NOT immediately obvious as all db functionality seemed to be working. I became suspicious of a problem when I tried to read a value from a "MYSQL" connection instance -- it wasn't what I expected. Further debug tests showed that mysql_init(MYSQL *conn) was zeroing out 968 bytes at conn, overshooting my pre-allocated buffer of only 960 bytes for an 8 byte buffer overrun.
The above #pragma makes my app-side MYSQL structure 968 bytes, the same size as the Microsoft-compiled MySQL C API DLL.

Hope this helps someone one day.
Cheers,
-Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top