CPP builder 6 and MySQL with or without VCL ?

L

Lotfi

Hi

I am trying to access MySQL DB with C++ Builder 6 pro,
I have Apache 2 under W2000 pro and MySQL 4

I found
http://crlab.com/mydac/
but it is not free :-(
but the trial version seems to work

I will also have a look to :
http://zeoslib.sourceforge.net/modules.php?name=Downloads

I need things simpler with no VCL
SO I found an example of :
____________________________________________
Author: Jethro Wright, III TS : 3/ 4/1998 9:15 */
/* Date: 02/18/1998 */
/* mytest.c : do some testing of the libmySQL.DLL.... */
/* */
/* History: */
/* 02/18/1998 jw3 also sprach zarathustra.... */
____________________________________________

it works under C++builder 6 pro in consoile mode and "C" syntax

after rebuilding the .lib .def with implib impdef in order to link them with
his C source

but If I rename its file to .CPP
and rebuild it gives lot of errors (that where warnings before) because of
the use of :
char * pszT;
and mysql DLL functions are returning a const char *

also when I include <VCL.h> file (in order to use VCL forms) then no
building is possible :-(

mysql_com.h
gives errors near :

ypedef struct st_net {
Vio* vio;
unsigned char *buff,*buff_end,*write_pos,*read_pos;
----->>>> my_socket fd; /* For Perl DBI/dbd */
unsigned long max_packet,max_packet_size;


My QUESTION :
Has anybody succeded to compile C++ VCL forms with the standard libmySQL.DLL
given with MySQL

I just need to connect to MySQL DB and do some queries, but I need the full
VCL environement...

give me website or tutorial example / help :)

Thanks in advance.

Ciao
 
J

Jack Klein

Hi

I am trying to access MySQL DB with C++ Builder 6 pro,
I have Apache 2 under W2000 pro and MySQL 4

You are asking your question in the wrong place. Neither comp.lang.c
nor comp.lang.c++ discuss third party libraries like MySQL nor
specific implementations like C++ Builder.

I found
http://crlab.com/mydac/
but it is not free :-(
but the trial version seems to work

I will also have a look to :
http://zeoslib.sourceforge.net/modules.php?name=Downloads

I need things simpler with no VCL

That's good, it is very hard to imaging anything more off-topic in
these newsgroups than Borland's VCL, which is not C or C++ at all but
written in their own proprietary extended version of Pascal.
SO I found an example of :
____________________________________________
Author: Jethro Wright, III TS : 3/ 4/1998 9:15 */
/* Date: 02/18/1998 */
/* mytest.c : do some testing of the libmySQL.DLL.... */

Presumably, given the name, this program was written in C.
/* */
/* History: */
/* 02/18/1998 jw3 also sprach zarathustra.... */
____________________________________________

it works under C++builder 6 pro in consoile mode and "C" syntax

....and according to you, it works as when compiled as C.
after rebuilding the .lib .def with implib impdef in order to link them with
his C source

but If I rename its file to .CPP
and rebuild it gives lot of errors (that where warnings before) because of
the use of :
char * pszT;
and mysql DLL functions are returning a const char *

Apparently you do not understand that C is not a subset of C++. There
are programs that are perfectly valid C that are not valid C++ at all.
There are several things you can do about this. You could make sure
you understand the differences between C and C++, and manually convert
the source to C++. Or you could look for another source, in C++. You
could write your own C++ code. Or you could buy C++ source code.
also when I include <VCL.h> file (in order to use VCL forms) then no
building is possible :-(

Anything at all involving Borland's VCL is completely off-topic here.
As I said, it is not even C or C++. This is discussed in Borland's
support groups, some of which even have .vcl in their names. Try the
family of groups on the server
newsgroups.borland.com.
mysql_com.h
gives errors near :

ypedef struct st_net {
Vio* vio;
unsigned char *buff,*buff_end,*write_pos,*read_pos;
----->>>> my_socket fd; /* For Perl DBI/dbd */
unsigned long max_packet,max_packet_size;


My QUESTION :
Has anybody succeded to compile C++ VCL forms with the standard libmySQL.DLL
given with MySQL

I just need to connect to MySQL DB and do some queries, but I need the full
VCL environement...

give me website or tutorial example / help :)

Thanks in advance.

Ciao

None of your issues have anything to do with the C or C++ languages,
but with non-standard extensions and third party libraries. Your best
bet is the Borland support groups.
 
L

Lotfi

None of your issues have anything to do with the C or C++ languages,
but with non-standard extensions and third party libraries. Your best
bet is the Borland support groups.


thanks for your polite answer
 
Joined
Jul 28, 2006
Messages
1
Reaction score
0
Ciao's question

Hi Ciao

It's Ishmael here, howzit?

In aswering your question; 'has any oner succeeded compiling MySQL....'

You need MyODBC connector (data source) and any MySQL database server will do, I used MySQL 4.1, XAMMP server.Then on your application place any TDatabase/TQuery component, and for the driver, select your MyODBC datasource and thence you should be able to connect to your mysql database server.

As soon as you have collected all these packages, just come back to me and I will hook you up with some sample codes on how to run a simple INSERT and SELECT SQL statments.

Hope this help, keep well.
Ishmael
 
Joined
Dec 28, 2008
Messages
1
Reaction score
0
the solution

if you are a true programmer....


1.download xampp from apachefriends dot org
2install it,
3download free pascal from www dot freepascal dot org /download dot var
4compile this
-----------------------------------------
program qtest;

uses
mysql4;

Const

DataBase : Pchar = 'cdcol';
Query : Pchar = 'Select * from cds';



var
count,num : longint;
code : integer;
sock : PMYSQL;
qmysql : TMYSQL;
qbuf : string [160];
rowbuf : TMYSQL_ROW;
dummy : string;
recbuf : PMYSQL_RES;

begin
if paramcount=1 then
begin
Dummy:=Paramstr(1)+#0;
DataBase:=@Dummy[1];
end;
Write ('Connecting to MySQL...');
mysql_init(PMySQL(@qmysql));
sock := mysql_real_connect(PMysql(@qmysql),'localhost','root','123456',nil,0,nil,0);

if sock=Nil then
begin
Writeln (stderr,'Couldn''t connect to MySQL.');
Writeln (stderr,mysql_error(@qmysql));
halt(1);
end;
Writeln ('Done.');
Writeln ('Connection data:');
{$ifdef Unix}
writeln ('Mysql_port : ',mysql_port);
writeln ('Mysql_unix_port : ',mysql_unix_port);
{$endif}
writeln ('Host info : ',mysql_get_host_info(sock));
writeln ('Server info : ',mysql_stat(sock));
writeln ('Client info : ',mysql_get_client_info);

Writeln ('Selecting Database ',DataBase,'...');
if mysql_select_db(sock,DataBase) < 0 then
begin
Writeln (stderr,'Couldn''t select database ',Database);
Writeln (stderr,mysql_error(sock));
halt (1);
end;

writeln ('Executing query : ',Query,'...');
if (mysql_query(sock,Query) < 0) then
begin
Writeln (stderr,'Query failed ');
writeln (stderr,mysql_error(sock));
Halt(1);
end;

recbuf := mysql_store_result(sock);
if RecBuf=Nil then
begin
Writeln ('Query returned nil result.');
mysql_close(sock);
halt (1);
end;
Writeln ('Number of records returned : ',mysql_num_rows (recbuf));
Writeln ('Number of fields per record : ',mysql_num_fields(recbuf));

rowbuf := mysql_fetch_row(recbuf);
while (rowbuf <>nil) do
begin
Write ('(Id: ', rowbuf[0]);
Write (', Name: ', rowbuf[1]);
Writeln(', Email : ', rowbuf[2],')');
rowbuf := mysql_fetch_row(recbuf);
end;
Writeln ('Freeing memory occupied by result set...');
mysql_free_result (recbuf);

Writeln ('Closing connection with MySQL.');
mysql_close(sock);
readln;
halt(0);
end.
---------------------------------------------------------


5 using your methods you can create a dll around mysql functions included in that pascal unit,

6if you don't know how to build an dll in pascal ,here is a sample
----------------------------------------------------------
program dlltest;

function Test(bool:integer): boolean; external 'dll' index 1;

begin
writeln(Test(1));
writeln(Test(0));

writeln('Main: press enter');
readln;
end.

----------------------------------------------------------

then use libmySQL.dll from xampp\apache\bin\
in the same directory with your dll/your executable


nothing more, good luck!

:driver: HaPpY new YeAr PASCAL!!!:driver: :flute: :flute: :flute:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top