Link to home
Start Free TrialLog in
Avatar of SaLz
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_status_get_result,mysql_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_size] of char;
       last_errno,max_packet,timeout,pkt_vnr: 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,decimals:integer;
            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_capabilities,
        protocol_version,field_count: 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:pmysql; const db:Pchar) : Integer; Stdcall;external thelib;
//function mysql_connect ( _mysql: pmysql; const host,user,passwd,port:pchar):pmysql;
function mysql_connect( _mysql: pmysql; const host,user,passwd:pchar):pmysql;stdcall;external thelib;
function mysql_init (_mysql: pmysql):pmysql;stdcall;external 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;stdcall;external 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(mysql : 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:pmysql;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(_mysql: pmysql):pmysql_res;stdcall;external thelib;
function mysql_select_db(_mysql:pmysql;const db:
pchar):integer;stdcall;external thelib;
function mysql_query(_mysql:pmysql;const query:
pchar):integer;stdcall;external thelib;
function mysql_store_result(_mysql:pmysql):pmysql_res;stdcall;external thelib;
function mysql_use_result(_mysql:pmysql):pmysql_res;stdcall;external
thelib;
procedure mysql_free_result(result:pmysql_res);stdcall;external thelib;
Function mysql_refresh(mysql : PMYSQL; refresh_options : cardinal) : longint;stdcall;external thelib;
function mysql_fetch_field(handle:
pmysql_res):pmysql_field;stdcall;external thelib;
function mysql_fetch_row(res:pmysql_res):pmysql_row;stdcall;external
thelib;
function mysql_kill(_mysql:pmysql;pid:integer):Integer;stdcall;external 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_count
end;

Function mysql_num_fields(res : PMYSQL_RES) : Cardinal;
begin
  mysql_num_fields:=res^.field_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:pchar):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','User','Password','Database',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_error(sock)), mterror, [mbok],0);
               MySQL_Close(Sock);
end;

Sal.
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

I doubt that anyone here would be free enough to take the entire source for the .DLL and convert it to Pascal...

However, they *are* some commercial DAC (Direct-Access Components):
http://microolap.com/dac/mysql/index.htm
http://crlab.com/mydac/ordering.html
Avatar of Eddie Shipman
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 
Avatar of SaLz
SaLz

ASKER

rgr, what next
ASKER CERTIFIED SOLUTION
Avatar of DragonSlayer
DragonSlayer
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SaLz

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/
mnasman, Zeos will still internally call the libmysql.dll ;-)
Avatar of SaLz

ASKER

ok, I have to test and explore this stuff
Avatar of SaLz

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.