SaLz
asked on
Convert libmysql.dll to .pas unit
hi, need some help converting this code from dll to .pas unit, so it wont need an external dll, it be apart of the app, insink, just like a normal unit, just want this libmysql being one of them, than an external file.
understand what am after? need it converting from dll to unit pas, the libmysql also needs 2 work when its been converted,
please display your Code below when u have converted it, and the query sample as well.
unit libmysql;
interface
uses
sysutils;
const
mysql_errmsg_size=200;
field_type_decimal=0;
field_type_tiny=1;
field_type_short=2;
field_type_long=3;
field_type_float=4;
field_type_double=5;
field_type_null=6;
field_type_timestamp=7;
field_type_longlong=8;
field_type_int24=9;
field_type_date=10;
field_type_time=11;
field_type_datetime=12;
field_type_enum=247;
field_type_set=248;
field_type_tiny_blob=249;
field_type_medium_blob=250 ;
field_type_long_blob=251;
field_type_blob=252;
field_type_var_string=253;
field_type_string=254;
type
enum_field_types=byte;
my_bool= shortint;
gptr= pchar;
socket= word;
mysql_status=(
mysql_status_ready,mysql_s tatus_get_ result,mys ql_status_ use_result );
pused_mem=^used_mem;
err_proc=procedure;
used_mem=record
next:pused_mem;
left,size:word
end;
pmem_root=^mem_root;
mem_root=record
free,used:pused_mem;
min_malloc,block_size:word ;
error_handler:err_proc;
end;
net=record
fd: socket;
fcntl: integer;
buff,buff_end,write_pos: pchar;
last_error:array[01..mysql _errmsg_si ze] of char;
last_errno,max_packet,time out,pkt_vn r: integer;
error,return_errno:my_bool ;
end;
pmysql_field=^mysql_field;
mysql_field=record
name,table,def: pchar;
_type: enum_field_types;
length,max_length,flags,de cimals:int eger;
end;
pmysql_rows=^mysql_rows;
mysql_rows=record
next: pmysql_rows;
data:pointer ;
end;
mysql_row=array[00..$ffff div sizeof(pchar)] of pchar;
pmysql_row=^mysql_row;
pmysql_data=pointer;
pmysql_res=^mysql_res;
mysql_res= record
row_count: longint;
field_count, current_field:word;
fields: pmysql_field;
data: pmysql_data;
data_cursor:pmysql_rows;
field_alloc:pmem_root;
row:pmysql_row;
current_row:pmysql_row;
lengths:^word;
handle:word;
eof:my_bool;
end;
pmysql=^mysql;
mysql= record
_net: net;
host,user,passwd,
unix_socket,
server_version,
host_info,
info,db: pchar;
port,client_flag,server_ca pabilities ,
protocol_version,field_cou nt: integer;
thread_id,
affected_rows,
insert_id,
extra_info:longint;
status: mysql_status;
fields: pmysql_field;
field_alloc: mem_root;
free_me,reconnect:my_bool;
end;
const thelib='libmysql.dll';
Function mysql_num_rows (res : pmysql_res) : Cardinal;
Function mysql_affected_rows (res:pmysql):longint;
Function mysql_num_fields(res : pmysql_res) : Cardinal;
function mysql_drop_db(_mysql:pmysq l; const db:Pchar) : Integer; Stdcall;external thelib;
//function mysql_connect ( _mysql: pmysql; const host,user,passwd,port:pcha r):pmysql;
function mysql_connect( _mysql: pmysql; const host,user,passwd:pchar):pm ysql;stdca ll;externa l thelib;
function mysql_init (_mysql: pmysql):pmysql;stdcall;ext ernal thelib;
function mysql_real_connect(mysql : pmysql;host,user, passwd, db:pchar; port:cardinal; unix_socket:pchar; clientflag:integer): PMYSQL; stdcall; external thelib;
procedure mysql_close( _mysql: pmysql);stdcall;external thelib;
function mysql_stat(_mysql:pmysql): pchar;stdc all;extern al thelib;
Function mysql_shutdown(mysql : PMYSQL) : longint; stdcall;external thelib;
Function mysql_get_host_info(mysql : PMYSQL) : pchar;stdcall; external thelib;
Function mysql_get_server_info(mysq l : PMYSQL) : pchar;stdcall; external thelib;
Function mysql_get_client_info : pchar;stdcall; external thelib;
Function mysql_get_proto_info(mysql : PMYSQL) : Cardinal;stdcall; external thelib;
function mysql_create_db(_mysql : pmysql; db : pchar) : longint;stdcall;external thelib;
Function mysql_error(mysql : PMYSQL) : Pchar;
function mysql_list_dbs(_mysql:pmys ql;wild:
pchar):pmysql_res;stdcall; external thelib;
function mysql_list_tables(_mysql: pmysql; const wild:
pchar):pmysql_res;stdcall; external thelib;
function mysql_list_fields(_mysql: pmysql;const table,wild:
pchar):pmysql_res;stdcall; external thelib;
function mysql_list_processes(_mysq l: pmysql):pmysql_res;stdcall ;external thelib;
function mysql_select_db(_mysql:pmy sql;const db:
pchar):integer;stdcall;ext ernal thelib;
function mysql_query(_mysql:pmysql; const query:
pchar):integer;stdcall;ext ernal thelib;
function mysql_store_result(_mysql: pmysql):pm ysql_res;s tdcall;ext ernal thelib;
function mysql_use_result(_mysql:pm ysql):pmys ql_res;std call;exter nal
thelib;
procedure mysql_free_result(result:p mysql_res) ;stdcall;e xternal thelib;
Function mysql_refresh(mysql : PMYSQL; refresh_options : cardinal) : longint;stdcall;external thelib;
function mysql_fetch_field(handle:
pmysql_res):pmysql_field;s tdcall;ext ernal thelib;
function mysql_fetch_row(res:pmysql _res):pmys ql_row;std call;exter nal
thelib;
function mysql_kill(_mysql:pmysql;p id:integer ):Integer; stdcall;ex ternal thelib;
implementation
Function mysql_affected_rows (res:pmysql):longint;
begin
mysql_affected_rows := res^.affected_rows;
end;
Function mysql_num_rows (res : pmysql_res) : Cardinal;
begin
mysql_num_rows:=res^.row_c ount
end;
Function mysql_num_fields(res : PMYSQL_RES) : Cardinal;
begin
mysql_num_fields:=res^.fie ld_count;
end;
Function mysql_error(mysql : pmysql) : PChar;
begin
mysql_error := @mysql^._net.last_error;
end;
{
function mysql_connect ( _mysql: pmysql; const host,user,passwd,port:pcha r):pmysql;
var
puerto : Cardinal;
begin
puerto := strtoint (strpas(port));
mysql_connect := mysql_real_connect (_mysql, host, user, passwd, puerto, '0', 0);
end;
}
end.
a sample query:
procedure TForm1.Button1Click(Sender : TObject);
var
sock2,sock : pmysql;
begin
sock2 := mysql_init(nil);
sock := mysql_real_connect(sock2,' Host','Use r','Passwo rd','Datab ase',port, '0',0);
if sock = nil then
messagedlg('Connection to MySQL server failed!', mtError, [mbok],0)
else
if mysql_Query(sock, 'CREATE TABLE Test (aux varchar(50))' < 0 then
messagedlg(strpas(mysql_er ror(sock)) , mterror, [mbok],0);
MySQL_Close(Sock);
end;
Sal.
understand what am after? need it converting from dll to unit pas, the libmysql also needs 2 work when its been converted,
please display your Code below when u have converted it, and the query sample as well.
unit libmysql;
interface
uses
sysutils;
const
mysql_errmsg_size=200;
field_type_decimal=0;
field_type_tiny=1;
field_type_short=2;
field_type_long=3;
field_type_float=4;
field_type_double=5;
field_type_null=6;
field_type_timestamp=7;
field_type_longlong=8;
field_type_int24=9;
field_type_date=10;
field_type_time=11;
field_type_datetime=12;
field_type_enum=247;
field_type_set=248;
field_type_tiny_blob=249;
field_type_medium_blob=250
field_type_long_blob=251;
field_type_blob=252;
field_type_var_string=253;
field_type_string=254;
type
enum_field_types=byte;
my_bool= shortint;
gptr= pchar;
socket= word;
mysql_status=(
mysql_status_ready,mysql_s
pused_mem=^used_mem;
err_proc=procedure;
used_mem=record
next:pused_mem;
left,size:word
end;
pmem_root=^mem_root;
mem_root=record
free,used:pused_mem;
min_malloc,block_size:word
error_handler:err_proc;
end;
net=record
fd: socket;
fcntl: integer;
buff,buff_end,write_pos: pchar;
last_error:array[01..mysql
last_errno,max_packet,time
error,return_errno:my_bool
end;
pmysql_field=^mysql_field;
mysql_field=record
name,table,def: pchar;
_type: enum_field_types;
length,max_length,flags,de
end;
pmysql_rows=^mysql_rows;
mysql_rows=record
next: pmysql_rows;
data:pointer ;
end;
mysql_row=array[00..$ffff div sizeof(pchar)] of pchar;
pmysql_row=^mysql_row;
pmysql_data=pointer;
pmysql_res=^mysql_res;
mysql_res= record
row_count: longint;
field_count, current_field:word;
fields: pmysql_field;
data: pmysql_data;
data_cursor:pmysql_rows;
field_alloc:pmem_root;
row:pmysql_row;
current_row:pmysql_row;
lengths:^word;
handle:word;
eof:my_bool;
end;
pmysql=^mysql;
mysql= record
_net: net;
host,user,passwd,
unix_socket,
server_version,
host_info,
info,db: pchar;
port,client_flag,server_ca
protocol_version,field_cou
thread_id,
affected_rows,
insert_id,
extra_info:longint;
status: mysql_status;
fields: pmysql_field;
field_alloc: mem_root;
free_me,reconnect:my_bool;
end;
const thelib='libmysql.dll';
Function mysql_num_rows (res : pmysql_res) : Cardinal;
Function mysql_affected_rows (res:pmysql):longint;
Function mysql_num_fields(res : pmysql_res) : Cardinal;
function mysql_drop_db(_mysql:pmysq
//function mysql_connect ( _mysql: pmysql; const host,user,passwd,port:pcha
function mysql_connect( _mysql: pmysql; const host,user,passwd:pchar):pm
function mysql_init (_mysql: pmysql):pmysql;stdcall;ext
function mysql_real_connect(mysql : pmysql;host,user, passwd, db:pchar; port:cardinal; unix_socket:pchar; clientflag:integer): PMYSQL; stdcall; external thelib;
procedure mysql_close( _mysql: pmysql);stdcall;external thelib;
function mysql_stat(_mysql:pmysql):
Function mysql_shutdown(mysql : PMYSQL) : longint; stdcall;external thelib;
Function mysql_get_host_info(mysql : PMYSQL) : pchar;stdcall; external thelib;
Function mysql_get_server_info(mysq
Function mysql_get_client_info : pchar;stdcall; external thelib;
Function mysql_get_proto_info(mysql
function mysql_create_db(_mysql : pmysql; db : pchar) : longint;stdcall;external thelib;
Function mysql_error(mysql : PMYSQL) : Pchar;
function mysql_list_dbs(_mysql:pmys
pchar):pmysql_res;stdcall;
function mysql_list_tables(_mysql: pmysql; const wild:
pchar):pmysql_res;stdcall;
function mysql_list_fields(_mysql: pmysql;const table,wild:
pchar):pmysql_res;stdcall;
function mysql_list_processes(_mysq
function mysql_select_db(_mysql:pmy
pchar):integer;stdcall;ext
function mysql_query(_mysql:pmysql;
pchar):integer;stdcall;ext
function mysql_store_result(_mysql:
function mysql_use_result(_mysql:pm
thelib;
procedure mysql_free_result(result:p
Function mysql_refresh(mysql : PMYSQL; refresh_options : cardinal) : longint;stdcall;external thelib;
function mysql_fetch_field(handle:
pmysql_res):pmysql_field;s
function mysql_fetch_row(res:pmysql
thelib;
function mysql_kill(_mysql:pmysql;p
implementation
Function mysql_affected_rows (res:pmysql):longint;
begin
mysql_affected_rows := res^.affected_rows;
end;
Function mysql_num_rows (res : pmysql_res) : Cardinal;
begin
mysql_num_rows:=res^.row_c
end;
Function mysql_num_fields(res : PMYSQL_RES) : Cardinal;
begin
mysql_num_fields:=res^.fie
end;
Function mysql_error(mysql : pmysql) : PChar;
begin
mysql_error := @mysql^._net.last_error;
end;
{
function mysql_connect ( _mysql: pmysql; const host,user,passwd,port:pcha
var
puerto : Cardinal;
begin
puerto := strtoint (strpas(port));
mysql_connect := mysql_real_connect (_mysql, host, user, passwd, puerto, '0', 0);
end;
}
end.
a sample query:
procedure TForm1.Button1Click(Sender
var
sock2,sock : pmysql;
begin
sock2 := mysql_init(nil);
sock := mysql_real_connect(sock2,'
if sock = nil then
messagedlg('Connection to MySQL server failed!', mtError, [mbok],0)
else
if mysql_Query(sock, 'CREATE TABLE Test (aux varchar(50))' < 0 then
messagedlg(strpas(mysql_er
MySQL_Close(Sock);
end;
Sal.
Using the above, you are going to also require the libmysql.dll to be installed.
This is the only Delphi implementation, that I know of, where you don't need libmysql.dll:
DAC for MySQL TM 2.3
By Microolap Technologies Ltd. DAC for MySQL (also known as MySQLDAC) is the most powerful
component suite for Delphi/C++Builder and MySQL.
This component suite allows you to create Delphi/C++Builder applications with direct access to
MySQL DB without BDE and ODBC.
Top 10 reasons to use DAC for MySQL:
No additional library (even libmysql.dll) is required;
DAC for MySQL is a royalty-free product;
100% native Delphi code;
support for Delphi 5-7, C++Builder 5-6 and MySQL 3.xx/4.0.x/5.x;
adding only 300-400 Kb to your .exe file;
full compatibility with all the existing data-aware controls and report designers;
full support of the BLOB fields;
TDBImageEx component for JPEG images support included in the package for free (with sources);
detailed help system and a lot of various demo applications;
and much more.
Trial (work while IDE is running)
Source: On purchase/registration
Price: $59
Source Price: $99
http://microolap.com/dac/mysql/index.htm
This is the only Delphi implementation, that I know of, where you don't need libmysql.dll:
DAC for MySQL TM 2.3
By Microolap Technologies Ltd. DAC for MySQL (also known as MySQLDAC) is the most powerful
component suite for Delphi/C++Builder and MySQL.
This component suite allows you to create Delphi/C++Builder applications with direct access to
MySQL DB without BDE and ODBC.
Top 10 reasons to use DAC for MySQL:
No additional library (even libmysql.dll) is required;
DAC for MySQL is a royalty-free product;
100% native Delphi code;
support for Delphi 5-7, C++Builder 5-6 and MySQL 3.xx/4.0.x/5.x;
adding only 300-400 Kb to your .exe file;
full compatibility with all the existing data-aware controls and report designers;
full support of the BLOB fields;
TDBImageEx component for JPEG images support included in the package for free (with sources);
detailed help system and a lot of various demo applications;
and much more.
Trial (work while IDE is running)
Source: On purchase/registration
Price: $59
Source Price: $99
http://microolap.com/dac/mysql/index.htm
ASKER
rgr, what next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
if its got all the minimum querys and works with the near 2 latest versions and it can be complied then it be good for me, let me check it out.
I have been using DirectSQL for about 2 years now and have found it to be very stable.
Hello
Try Zeos Library, it's had drivers for MySQL , PostgreSQL , Firebird, InterBase , MS SQL , Sybase ASE, Oracle , SQLite 2.8
and it's open source ;-)
http://www.zeoslib.net/
Try Zeos Library, it's had drivers for MySQL , PostgreSQL , Firebird, InterBase , MS SQL , Sybase ASE, Oracle , SQLite 2.8
and it's open source ;-)
http://www.zeoslib.net/
mnasman, Zeos will still internally call the libmysql.dll ;-)
ASKER
ok, I have to test and explore this stuff
ASKER
after looks and testing and all that, DAC seems 2 be the best :D much better than using libmysql.dll, with dac u can complie it into your app as a pas, which is what I wanted, 1 sole app, not 1 app and a dll :S plus I converted the dac to 1 pas file, to keep everything short.
thanks
Sal.
thanks
Sal.
However, they *are* some commercial DAC (Direct-Access Components):
http://microolap.com/dac/mysql/index.htm
http://crlab.com/mydac/ordering.html