mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-08 10:39:29 +02:00
+ MySQL 3 dynamic connection by Bram Kuijvenhoven
This commit is contained in:
parent
bbbcc17171
commit
00a68932dc
@ -7,7 +7,7 @@ name=mysql
|
||||
version=1.9.8
|
||||
|
||||
[target]
|
||||
units=mysql4_com mysql4_version mysql4 mysql4dyn mysql4_comdyn mysql3_com mysql3_version mysql3
|
||||
units=mysql4_com mysql4_version mysql4 mysql4dyn mysql4_comdyn mysql3_com mysql3_version mysql3 mysql3_comdyn mysql3_dyn
|
||||
examples=testdb4 testdb3
|
||||
|
||||
[require]
|
||||
@ -17,4 +17,4 @@ libc=y
|
||||
fpcpackage=y
|
||||
|
||||
[default]
|
||||
fpcdir=../../..
|
||||
fpcdir=../../..
|
@ -12,17 +12,27 @@ unit mysql3;
|
||||
|
||||
updated to mysql version 3.23 header files by Bernhard Steffen
|
||||
(bernhard.steffen@gmx.net)
|
||||
|
||||
split into mysql/mysqldyn libraries by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
{$mode objfpc}{$h+}
|
||||
{$macro on}
|
||||
{$r+,i+,o+}
|
||||
|
||||
interface
|
||||
|
||||
uses mysql3_com, mysql3_version;
|
||||
{$ifdef win32}
|
||||
Const mysqllib = 'libmysql';
|
||||
{$else}
|
||||
Const mysqllib = 'mysqlclient';
|
||||
{$endif}
|
||||
|
||||
{$IFDEF Unix}
|
||||
{$DEFINE extdecl:=cdecl}
|
||||
const
|
||||
Mysqllib = 'mysqlclient';
|
||||
{$ENDIF}
|
||||
{$IFDEF Win32}
|
||||
{$DEFINE extdecl:=stdcall}
|
||||
const
|
||||
Mysqllib = 'libmysql';
|
||||
{$ENDIF}
|
||||
|
||||
{$ifndef win32}
|
||||
{$linklib c}
|
||||
@ -32,317 +42,72 @@ Const mysqllib = 'mysqlclient';
|
||||
|
||||
{$packrecords C}
|
||||
|
||||
type
|
||||
my_bool = byte;
|
||||
gptr = pchar;
|
||||
Socket = Longint;
|
||||
PCardinal = ^Cardinal;
|
||||
{$i mysql3types.inc}
|
||||
|
||||
{$ifdef linux}
|
||||
Var
|
||||
mysql_port : cardinal; external name 'mysql_port';
|
||||
mysql_unix_port : pchar; external name 'mysql_unix_port';
|
||||
{$endif}
|
||||
Function mysql_num_rows (res : PMYSQL_RES) : my_ulonglong; extdecl; external mysqllib;
|
||||
Function mysql_num_fields(res : PMYSQL_RES) : Cardinal; extdecl; external mysqllib;
|
||||
Function mysql_eof(res : PMYSQL_RES) : my_bool; extdecl; external mysqllib;
|
||||
Function mysql_fetch_field_direct(res : PMYSQL_RES; fieldnr : Cardinal) : PMYSQL_FIELD; extdecl; external mysqllib;
|
||||
Function mysql_fetch_fields(res : PMYSQL_RES) : PMYSQL_FIELD; extdecl; external mysqllib;
|
||||
Function mysql_row_tell(res : PMYSQL_RES) : PMYSQL_ROWS; extdecl; external mysqllib;
|
||||
Function mysql_field_tell(res : PMYSQL_RES) : Cardinal; extdecl; external mysqllib;
|
||||
Function mysql_affected_rows(mysql : PMYSQL): my_ulonglong; extdecl; external mysqllib;
|
||||
Function mysql_insert_id(mysql : PMYSQL): my_ulonglong; extdecl; external mysqllib;
|
||||
Function mysql_errno(mysql : PMYSQL) : Cardinal; extdecl; external mysqllib;
|
||||
Function mysql_info(mysql : PMYSQL): Pchar; extdecl; external mysqllib;
|
||||
Function mysql_thread_id(mysql : PMYSQL) : ptruint; extdecl; external mysqllib;
|
||||
Function mysql_error(mysql : PMYSQL) : pchar; extdecl; external mysqllib;
|
||||
|
||||
{$ifdef darwin}
|
||||
Var
|
||||
mysql_port : cardinal; external mysqllib name 'mysql_port';
|
||||
mysql_unix_port : pchar; external mysqllib name 'mysql_unix_port';
|
||||
{$endif}
|
||||
|
||||
{
|
||||
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
|
||||
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
|
||||
#define IS_BLOB(n) ((n) & BLOB_FLAG)
|
||||
#define IS_NUM(t) ((t) <= FIELD_TYPE_INT24)
|
||||
}
|
||||
Type
|
||||
st_mysql_field = record
|
||||
name : Pchar; { Name of column }
|
||||
table : pchar; { Table of column if column was a field }
|
||||
def: pchar; { Default value (set by mysql_list_fields) }
|
||||
ftype : enum_field_types; { Type of field. See mysql_com.h for types }
|
||||
length : cardinal; { Width of column }
|
||||
max_length : cardinal; { Max width of selected set }
|
||||
flags : cardinal; { Div flags }
|
||||
decimals : cardinal; { Number of decimals in field }
|
||||
end;
|
||||
TMYSQL_FIELD = st_mysql_field;
|
||||
PMYSQL_FIELD = ^TMYSQL_FIELD;
|
||||
|
||||
TMYSQL_ROW = PPchar; { return data as array of strings }
|
||||
TMYSQL_FIELD_OFFSET = cardinal; { offset to current field }
|
||||
|
||||
{$ifndef oldmysql}
|
||||
my_ulonglong=qword;
|
||||
{$else}
|
||||
my_longlong=cardinal;
|
||||
{$endif}
|
||||
|
||||
PST_MYSQL_Rows = ^st_mysql_rows;
|
||||
st_mysql_rows = Record
|
||||
next : pst_mysql_rows; { list of rows }
|
||||
Data : TMYSQL_ROW;
|
||||
end;
|
||||
TMYSQL_ROWS = st_mysql_rows;
|
||||
PMYSQL_ROWS = ^TMYSQL_ROWS;
|
||||
|
||||
|
||||
TMYSQL_ROW_OFFSET = PMYSQL_ROWS; { offset to current row }
|
||||
|
||||
st_mysql_data = record
|
||||
rows : my_ulonglong;
|
||||
fields : cardinal;
|
||||
data : PMYSQL_ROWS;
|
||||
alloc : TMEM_ROOT;
|
||||
end;
|
||||
|
||||
TMYSQL_DATA = st_mysql_data;
|
||||
PMYSQL_DATA = ^TMYSQL_DATA;
|
||||
|
||||
st_mysql_options = record
|
||||
connect_timeout,client_flag : cardinal;
|
||||
compress,named_pipe : my_bool;
|
||||
port : cardinal;
|
||||
host,init_command,user,password,unix_socket,db : pchar;
|
||||
my_cnf_file,my_cnf_group : pchar;
|
||||
{$ifndef use_mysql_321}
|
||||
charset_dir, charset_name : pchar;
|
||||
use_ssl : my_bool;
|
||||
ssl_key, ssl_cert, ssl_ca, ssl_capath : pchar;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
{$ifndef use_mysql_321}
|
||||
mysql_option = (MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
|
||||
MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
|
||||
MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
|
||||
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME);
|
||||
{$endif}
|
||||
|
||||
mysql_status = (MYSQL_STATUS_READY,
|
||||
MYSQL_STATUS_GET_RESULT,
|
||||
MYSQL_STATUS_USE_RESULT);
|
||||
|
||||
{$ifndef use_mysql_321}
|
||||
(*
|
||||
charset_info_st = Record
|
||||
number : cardinal;
|
||||
name : pchar;
|
||||
ctype : pointer {uchar*};
|
||||
to_lower : pointer {uchar*};
|
||||
to_upper : pointer {uchar*};
|
||||
sort_order : pointer {uchar*};
|
||||
strxfrm_multiply : cardinal;
|
||||
|
||||
{ einige nicht näher definierte Felder }
|
||||
a, strxfrm, strnncoll, strnxfrm, like_range : pointer;
|
||||
mbmaxlen : cardinal;
|
||||
ismbchar, ismbhead, mbcharlen : pointer;
|
||||
end;
|
||||
*)
|
||||
{$endif}
|
||||
|
||||
st_mysql = Record
|
||||
NET : TNET; { Communication parameters }
|
||||
{$ifndef use_mysql_321}
|
||||
connector_fd : gptr;
|
||||
{$endif}
|
||||
host,user,passwd,unix_socket,server_version,host_info,
|
||||
info,db : pchar;
|
||||
port,client_flag,server_capabilities : cardinal;
|
||||
protocol_version : cardinal;
|
||||
field_count : cardinal;
|
||||
{$ifndef use_mysql_321}
|
||||
server_status : cardinal;
|
||||
{$endif}
|
||||
thread_id : ptruint; { Id for connection in server }
|
||||
affected_rows : my_ulonglong;
|
||||
insert_id : my_ulonglong; { id if insert on table with NEXTNR }
|
||||
extra_info : my_ulonglong; { Used by mysqlshow }
|
||||
packet_length : sizeint;
|
||||
status : mysql_status;
|
||||
fields : PMYSQL_FIELD;
|
||||
field_alloc : TMEM_ROOT;
|
||||
free_me : my_bool; { If free in mysql_close }
|
||||
reconnect : my_bool; { set to 1 if automatic reconnect }
|
||||
options : st_mysql_options;
|
||||
{$ifndef use_mysql_321}
|
||||
scramble_buf : array[0..8] of char;
|
||||
charset : pointer { struct charset_info_st};
|
||||
server_language : cardinal;
|
||||
{$endif}
|
||||
end;
|
||||
TMYSQL = st_mysql;
|
||||
PMYSQL = ^TMYSQL;
|
||||
|
||||
|
||||
st_mysql_res = record
|
||||
row_count : my_ulonglong;
|
||||
field_count, current_field : cardinal;
|
||||
fields : PMYSQL_FIELD;
|
||||
data : PMYSQL_DATA;
|
||||
data_cursor : PMYSQL_ROWS;
|
||||
field_alloc : TMEM_ROOT;
|
||||
row : TMYSQL_ROW; { If unbuffered read }
|
||||
current_row : TMYSQL_ROW; { buffer to current row }
|
||||
lengths : psizeint; { column lengths of current row }
|
||||
handle : PMYSQL; { for unbuffered reads }
|
||||
eof : my_bool; { Used my mysql_fetch_row }
|
||||
end;
|
||||
TMYSQL_RES = st_mysql_res;
|
||||
PMYSQL_RES = ^TMYSQL_RES;
|
||||
|
||||
|
||||
{ Translated Macros }
|
||||
|
||||
Function mysql_num_rows (res : PMYSQL_RES) : my_ulonglong;
|
||||
Function mysql_num_fields(res : PMYSQL_RES) : Cardinal;
|
||||
Function mysql_eof(res : PMYSQL_RES) : my_bool;
|
||||
Function mysql_fetch_field_direct(res : PMYSQL_RES; fieldnr : Cardinal) : TMYSQL_FIELD;
|
||||
Function mysql_fetch_fields(res : PMYSQL_RES) : PMYSQL_FIELD;
|
||||
Function mysql_row_tell(res : PMYSQL_RES) : PMYSQL_ROWS;
|
||||
Function mysql_field_tell(res : PMYSQL_RES) : Cardinal;
|
||||
Function mysql_affected_rows(mysql : PMYSQL): my_ulonglong;
|
||||
Function mysql_insert_id(mysql : PMYSQL): my_ulonglong;
|
||||
Function mysql_errno(mysql : PMYSQL) : Cardinal;
|
||||
Function mysql_info(mysql : PMYSQL): Pchar;
|
||||
Function mysql_reload(mysql : PMYSQL) : Longint;
|
||||
Function mysql_thread_id(mysql : PMYSQL) : ptruint;
|
||||
Function mysql_error(mysql : PMYSQL) : pchar;
|
||||
|
||||
{ Original functions }
|
||||
|
||||
function mysql_connect (mysql : PMYSQL; host,user,passwd: pchar) : PMYSQL;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_connect';
|
||||
function mysql_init(mysql: PMYSQL) : PMYSQL;extdecl; external mysqllib name 'mysql_init';
|
||||
function mysql_connect (mysql : PMYSQL; host,user,passwd: pchar) : PMYSQL;extdecl; external mysqllib name 'mysql_connect';
|
||||
function mysql_real_connect (mysql : PMYSQL; const host,user,passwd : pchar;
|
||||
port : cardinal;
|
||||
unix_socket : pchar;
|
||||
clientflag : cardinal) : PMYSQL;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib;
|
||||
clientflag : cardinal) : PMYSQL;extdecl; external mysqllib;
|
||||
|
||||
function mysql_close(sock : PMYSQL) : longint ;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_close';
|
||||
function mysql_select_db(MYSQL : PMYSQL; db : Pchar) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_select_db';
|
||||
function mysql_query(mysql : PMYSQL; q : pchar) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_query';
|
||||
function mysql_real_query(mysql : PMYSQL; q : Pchar; length : longint) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_real_query';
|
||||
function mysql_create_db(mysql : PMYSQL; db : pchar) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_create_db';
|
||||
Function mysql_drop_db(mysql : PMYSQL; DB : Pchar) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_drop_db';
|
||||
Function mysql_shutdown(mysql : PMYSQL) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_shutdown';
|
||||
Function mysql_dump_debug_info(mysql : PMYSQL) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_dump_debug_info';
|
||||
Function mysql_refresh(mysql : PMYSQL; refresh_options : cardinal) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_refresh';
|
||||
Function mysql_kill(mysql : PMYSQL; pid : Cardinal) : longint;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_kill';
|
||||
Function mysql_stat(mysql : PMYSQL) : Pchar;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_stat';
|
||||
Function mysql_get_server_info(mysql : PMYSQL) : pchar;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_get_server_info';
|
||||
Function mysql_get_client_info : pchar;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib;
|
||||
Function mysql_get_host_info(mysql : PMYSQL) : pchar;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_get_host_info';
|
||||
Function mysql_get_proto_info(mysql : PMYSQL) : Cardinal;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_get_proto_info';
|
||||
Function mysql_list_dbs(mysql : PMYSQL;wild : Pchar) : PMYSQL_RES;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_list_dbs';
|
||||
Function mysql_list_tables(mysql : PMYSQL;Wild : Pchar) : PMYSQL_RES;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_list_tables';
|
||||
Function mysql_list_fields(mysql : PMYSQL; table,wild : pchar) : PMYSQL_RES;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_list_fields';
|
||||
Function mysql_list_processes(mysql : PMYSQL) : PMYSQL_RES;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_list_processes';
|
||||
Function mysql_store_result(mysql : PMYSQL) : PMYSQL_RES;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_store_result';
|
||||
Function mysql_use_result(mysql : PMYSQL) : PMYSQL_RES;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_use_result';
|
||||
Procedure mysql_free_result(res : PMYSQL_RES);{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_free_result';
|
||||
Procedure mysql_data_seek(mysql : PMYSQL_RES; offs : cardinal);{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_data_seek';
|
||||
Function mysql_row_seek(mysql : PMYSQL_RES; Offs: TMYSQL_ROW_OFFSET): TMYSQL_ROW_OFFSET;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_row_seek';
|
||||
Function mysql_field_seek(musql : PMYSQL_RES;offs : TMYSQL_FIELD_OFFSET): TMYSQL_FIELD_OFFSET;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_field_seek';
|
||||
function mysql_fetch_row(mysql : PMYSQL_RES) : TMYSQL_ROW;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_fetch_row';
|
||||
function mysql_fetch_lengths(mysql : PMYSQL_RES) : PCardinal;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_fetch_lengths';
|
||||
function mysql_fetch_field(handle : PMYSQL_RES) : PMYSQL_FIELD;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_fetch_field';
|
||||
Function mysql_escape_string(escto,escfrom : pchar; length : Cardinal) : cardinal;{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_escape_string';
|
||||
Procedure mysql_debug(debug : pchar);{$ifdef win32}stdcall{$else}cdecl{$endif}; external mysqllib name 'mysql_debug';
|
||||
function mysql_close(sock : PMYSQL) : longint ;extdecl; external mysqllib name 'mysql_close';
|
||||
function mysql_select_db(MYSQL : PMYSQL; db : Pchar) : longint;extdecl; external mysqllib name 'mysql_select_db';
|
||||
function mysql_query(mysql : PMYSQL; q : pchar) : longint;extdecl; external mysqllib name 'mysql_query';
|
||||
function mysql_real_query(mysql : PMYSQL; q : Pchar; length : longint) : longint;extdecl; external mysqllib name 'mysql_real_query';
|
||||
function mysql_create_db(mysql : PMYSQL; db : pchar) : longint;extdecl; external mysqllib name 'mysql_create_db';
|
||||
Function mysql_drop_db(mysql : PMYSQL; DB : Pchar) : longint;extdecl; external mysqllib name 'mysql_drop_db';
|
||||
Function mysql_shutdown(mysql : PMYSQL) : longint;extdecl; external mysqllib name 'mysql_shutdown';
|
||||
Function mysql_dump_debug_info(mysql : PMYSQL) : longint;extdecl; external mysqllib name 'mysql_dump_debug_info';
|
||||
Function mysql_refresh(mysql : PMYSQL; refresh_options : cardinal) : longint;extdecl; external mysqllib name 'mysql_refresh';
|
||||
Function mysql_kill(mysql : PMYSQL; pid : Cardinal) : longint;extdecl; external mysqllib name 'mysql_kill';
|
||||
Function mysql_stat(mysql : PMYSQL) : Pchar;extdecl; external mysqllib name 'mysql_stat';
|
||||
Function mysql_get_server_info(mysql : PMYSQL) : pchar;extdecl; external mysqllib name 'mysql_get_server_info';
|
||||
Function mysql_get_client_info : pchar;extdecl; external mysqllib;
|
||||
Function mysql_get_host_info(mysql : PMYSQL) : pchar;extdecl; external mysqllib name 'mysql_get_host_info';
|
||||
Function mysql_get_proto_info(mysql : PMYSQL) : Cardinal;extdecl; external mysqllib name 'mysql_get_proto_info';
|
||||
Function mysql_list_dbs(mysql : PMYSQL;wild : Pchar) : PMYSQL_RES;extdecl; external mysqllib name 'mysql_list_dbs';
|
||||
Function mysql_list_tables(mysql : PMYSQL;Wild : Pchar) : PMYSQL_RES;extdecl; external mysqllib name 'mysql_list_tables';
|
||||
Function mysql_list_fields(mysql : PMYSQL; table,wild : pchar) : PMYSQL_RES;extdecl; external mysqllib name 'mysql_list_fields';
|
||||
Function mysql_list_processes(mysql : PMYSQL) : PMYSQL_RES;extdecl; external mysqllib name 'mysql_list_processes';
|
||||
Function mysql_store_result(mysql : PMYSQL) : PMYSQL_RES;extdecl; external mysqllib name 'mysql_store_result';
|
||||
Function mysql_use_result(mysql : PMYSQL) : PMYSQL_RES;extdecl; external mysqllib name 'mysql_use_result';
|
||||
Procedure mysql_free_result(res : PMYSQL_RES);extdecl; external mysqllib name 'mysql_free_result';
|
||||
Procedure mysql_data_seek(mysql : PMYSQL_RES; offs : cardinal);extdecl; external mysqllib name 'mysql_data_seek';
|
||||
Function mysql_row_seek(mysql : PMYSQL_RES; Offs: TMYSQL_ROW_OFFSET): TMYSQL_ROW_OFFSET;extdecl; external mysqllib name 'mysql_row_seek';
|
||||
Function mysql_field_seek(musql : PMYSQL_RES;offs : TMYSQL_FIELD_OFFSET): TMYSQL_FIELD_OFFSET;extdecl; external mysqllib name 'mysql_field_seek';
|
||||
function mysql_fetch_row(mysql : PMYSQL_RES) : TMYSQL_ROW;extdecl; external mysqllib name 'mysql_fetch_row';
|
||||
function mysql_fetch_lengths(mysql : PMYSQL_RES) : PCardinal;extdecl; external mysqllib name 'mysql_fetch_lengths';
|
||||
function mysql_fetch_field(handle : PMYSQL_RES) : PMYSQL_FIELD;extdecl; external mysqllib name 'mysql_fetch_field';
|
||||
Function mysql_escape_string(escto,escfrom : pchar; length : Cardinal) : cardinal;extdecl; external mysqllib name 'mysql_escape_string';
|
||||
Procedure mysql_debug(debug : pchar);extdecl; external mysqllib name 'mysql_debug';
|
||||
|
||||
implementation
|
||||
|
||||
|
||||
|
||||
Function mysql_error(mysql : PMYSQL) : pchar;
|
||||
|
||||
begin
|
||||
mysql_error:=mysql^.net.last_error
|
||||
end;
|
||||
|
||||
Function mysql_num_rows (res : PMYSQL_RES) : my_ulonglong;
|
||||
|
||||
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_eof(res : PMYSQL_RES) : my_bool;
|
||||
|
||||
begin
|
||||
mysql_eof:=res^.eof
|
||||
end;
|
||||
|
||||
Function mysql_fetch_field_direct(res : PMYSQL_RES; fieldnr : Cardinal) : TMYSQL_FIELD;
|
||||
|
||||
begin
|
||||
mysql_fetch_field_direct:=res^.fields[fieldnr];
|
||||
end;
|
||||
|
||||
Function mysql_fetch_fields(res : PMYSQL_RES) : PMYSQL_FIELD;
|
||||
|
||||
begin
|
||||
mysql_fetch_fields:=res^.fields
|
||||
end;
|
||||
|
||||
Function mysql_row_tell(res : PMYSQL_RES) : PMYSQL_ROWS;
|
||||
|
||||
begin
|
||||
mysql_row_tell:=res^.data_cursor
|
||||
end;
|
||||
|
||||
Function mysql_field_tell(res : PMYSQL_RES) : Cardinal;
|
||||
|
||||
begin
|
||||
mysql_field_tell:=res^.current_field
|
||||
end;
|
||||
|
||||
Function mysql_affected_rows(mysql : PMYSQL): my_ulonglong;
|
||||
|
||||
begin
|
||||
mysql_affected_rows:=mysql^.affected_rows
|
||||
end;
|
||||
|
||||
Function mysql_insert_id(mysql : PMYSQL): my_ulonglong;
|
||||
|
||||
begin
|
||||
mysql_insert_id:=mysql^.insert_id
|
||||
end;
|
||||
|
||||
Function mysql_errno(mysql : PMYSQL) : Cardinal;
|
||||
|
||||
begin
|
||||
mysql_errno:=mysql^.net.last_errno
|
||||
end;
|
||||
|
||||
Function mysql_info(mysql : PMYSQL): Pchar;
|
||||
|
||||
begin
|
||||
mysql_info:=mysql^.info
|
||||
end;
|
||||
|
||||
Function mysql_reload(mysql : PMYSQL) : Longint;
|
||||
|
||||
begin
|
||||
mysql_reload:=mysql_refresh(mysql,REFRESH_GRANT)
|
||||
end;
|
||||
|
||||
Function mysql_thread_id(mysql : PMysql) : ptruint;
|
||||
|
||||
begin
|
||||
mysql_thread_id:=mysql^.thread_id
|
||||
end;
|
||||
{$i mysql3impl.inc}
|
||||
|
||||
end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.4 2005-02-14 17:13:19 peter
|
||||
Revision 1.5 2005-03-25 12:03:53 michael
|
||||
+ MySQL 3 dynamic connection by Bram Kuijvenhoven
|
||||
|
||||
Revision 1.4 2005/02/14 17:13:19 peter
|
||||
* truncate log
|
||||
|
||||
}
|
||||
}
|
@ -4,18 +4,24 @@ unit mysql3_com;
|
||||
|
||||
{ updated to match version 3.23 header files of mysql by Bernhard Steffen
|
||||
(bernhard.steffen@gmx.net)
|
||||
|
||||
split into mysql/mysqldyn libraries by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
|
||||
{$mode objfpc}{$h+}
|
||||
{$macro on}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
mysql3_version;
|
||||
|
||||
{$ifdef win32}
|
||||
Const mysqllib = 'libmysql';
|
||||
{$else}
|
||||
Const mysqllib = 'mysqlclient';
|
||||
{$endif}
|
||||
{$IFDEF Unix}
|
||||
{$DEFINE extdecl:=cdecl}
|
||||
{$ENDIF}
|
||||
{$IFDEF Win32}
|
||||
{$DEFINE extdecl:=stdcall}
|
||||
{$ENDIF}
|
||||
|
||||
{$ifndef win32}
|
||||
{$linklib c}
|
||||
@ -24,240 +30,37 @@ Const mysqllib = 'mysqlclient';
|
||||
{$endif}
|
||||
{$r+,i+,o+}
|
||||
|
||||
|
||||
{
|
||||
Common definition between mysql server & client
|
||||
}
|
||||
|
||||
{$packrecords c}
|
||||
{ Extra types introduced for pascal }
|
||||
Type
|
||||
pbyte = ^byte;
|
||||
pcardinal = ^cardinal;
|
||||
Socket = longint;
|
||||
my_bool = byte;
|
||||
|
||||
Const
|
||||
NAME_LEN = 64 ; { Field/table name length }
|
||||
LOCAL_HOST : pchar = 'localhost' ;
|
||||
|
||||
MYSQL_PORT = 3306; { Alloced by ISI for MySQL }
|
||||
MYSQL_UNIX_ADDR : pchar = '/tmp/mysql.sock';
|
||||
|
||||
Type
|
||||
enum_server_command = ( COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
|
||||
COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,COM_REFRESH,
|
||||
COM_SHUTDOWN,COM_STATISTICS,
|
||||
COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
|
||||
COM_DEBUG);
|
||||
|
||||
Const
|
||||
NOT_NULL_FLAG = 1; { Field can't be NULL }
|
||||
PRI_KEY_FLAG = 2; { Field is part of a primary key }
|
||||
UNIQUE_KEY_FLAG = 4; { Field is part of a unique key }
|
||||
MULTIPLE_KEY_FLAG = 8; { Field is part of a key }
|
||||
BLOB_FLAG = 16; { Field is a blob }
|
||||
UNSIGNED_FLAG = 32; { Field is unsigned }
|
||||
ZEROFILL_FLAG = 64; { Field is zerofill }
|
||||
BINARY_FLAG = 128;
|
||||
{ The following are only sent to new clients }
|
||||
ENUM_FLAG = 256; { field is an enum }
|
||||
AUTO_INCREMENT_FLAG = 512; { field is a autoincrement field }
|
||||
TIMESTAMP_FLAG = 1024; { Field is a timestamp }
|
||||
PART_KEY_FLAG = 16384; { Intern; Part of some key }
|
||||
GROUP_FLAG = 32768; { Intern group field }
|
||||
{$ifndef use_mysql_321}
|
||||
UNIQUE_FLAG = 65536; { Intern: Used by sql_yacc }
|
||||
{$endif}
|
||||
|
||||
REFRESH_GRANT = 1; { Refresh grant tables }
|
||||
REFRESH_LOG = 2; { Start on new log file }
|
||||
REFRESH_TABLES = 4; { close all tables }
|
||||
{$ifndef use_mysql_321}
|
||||
REFRESH_HOSTS = 8; { Flush host cache }
|
||||
REFRESH_STATUS = 16; { Flush status variables }
|
||||
REFRESH_THREADS = 32; { Flush status variables }
|
||||
REFRESH_SLAVE = 64; { Reset master info and restart slave
|
||||
thread }
|
||||
REFRESH_MASTER = 128; { Remove all bin logs in the index
|
||||
and truncate the index }
|
||||
{$endif}
|
||||
|
||||
{$ifndef use_mysql_321}
|
||||
{ The following can't be set with mysql_refresh() }
|
||||
REFRESH_READ_LOCK = 16384; { Lock tables for read }
|
||||
REFRESH_FAST = 32768; { Intern flag }
|
||||
{$endif}
|
||||
|
||||
CLIENT_LONG_PASSWORD = 1; { new more secure passwords }
|
||||
CLIENT_FOUND_ROWS = 2; { Found instead of affected rows }
|
||||
CLIENT_LONG_FLAG = 4; { Get all column flags }
|
||||
{$ifndef use_mysql_321}
|
||||
CLIENT_CONNECT_WITH_DB = 8; { One can specify db on connect }
|
||||
CLIENT_NO_SCHEMA = 16; { Don't allow database.table.column }
|
||||
CLIENT_COMPRESS = 32; { Can use compression protocol }
|
||||
CLIENT_ODBC = 64; { Odbc client }
|
||||
CLIENT_LOCAL_FILES = 128; { Can use LOAD DATA LOCAL }
|
||||
CLIENT_IGNORE_SPACE = 256; { Ignore spaces before '(' }
|
||||
CLIENT_CHANGE_USER = 512; { Support the mysql_change_user() }
|
||||
CLIENT_INTERACTIVE = 1024; { This is an interactive client }
|
||||
CLIENT_SSL = 2048; { Switch to SSL after handshake }
|
||||
CLIENT_IGNORE_SIGPIPE = 4096; { IGNORE sigpipes }
|
||||
CLIENT_TRANSACTIONS = 8192; { Client knows about transactions }
|
||||
|
||||
SERVER_STATUS_IN_TRANS = 1; { Transaction has started }
|
||||
SERVER_STATUS_AUTOCOMMIT = 2; { Server in auto_commit mode }
|
||||
{$endif}
|
||||
|
||||
MYSQL_ERRMSG_SIZE = 200;
|
||||
NET_READ_TIMEOUT = 30; { Timeout on read }
|
||||
NET_WRITE_TIMEOUT = 60; { Timeout on write }
|
||||
NET_WAIT_TIMEOUT = 8*60*60; { Wait for new query }
|
||||
|
||||
Type
|
||||
pst_used_mem = ^st_used_mem;
|
||||
st_used_mem = record { struct for once_alloc }
|
||||
next : pst_used_mem; { Next block in use }
|
||||
left : cardinal; { memory left in block }
|
||||
size : cardinal; { size of block }
|
||||
end;
|
||||
|
||||
TUSED_MEM = st_used_mem;
|
||||
PUSED_MEM = ^TUSED_MEM;
|
||||
|
||||
TError_handler = Procedure;
|
||||
|
||||
st_mem_root = record
|
||||
free : PUSED_MEM;
|
||||
used : PUSED_MEM;
|
||||
{$ifndef use_mysql_321}
|
||||
pre_alloc: PUSED_MEM;
|
||||
{$endif use_mysql_321}
|
||||
min_malloc : cardinal;
|
||||
block_size : cardinal;
|
||||
error_handler : TERROR_Handler;
|
||||
end;
|
||||
TMEM_ROOT = st_mem_root;
|
||||
PMEM_ROOT = ^TMEM_ROOT;
|
||||
|
||||
Type
|
||||
net_type = (NET_TYPE_TCPIP, NET_TYPE_SOCKET, NETTYPE_NAMEDPIPE);
|
||||
st_net = record
|
||||
nettype : net_type; //DT
|
||||
fd : Socket;
|
||||
fcntl : Longint;
|
||||
buff,buff_end,write_pos,read_pos : Pchar;//DT
|
||||
last_error : array [0..MYSQL_ERRMSG_SIZE-1] of char;
|
||||
last_errno,max_packet,timeout,pkt_nr : Cardinal;
|
||||
error,return_errno : my_bool;
|
||||
compress : my_bool; //DT
|
||||
{$ifndef use_mysql_321}
|
||||
no_send_ok : my_bool;
|
||||
{$endif}
|
||||
remain_in_buf,r_length, buf_length, where_b : ptruint; //DT
|
||||
{$ifndef use_mysql_321}
|
||||
return_status : ^Cardinal;
|
||||
reading_or_writing : my_bool;
|
||||
{$else}
|
||||
more : my_bool;//DT
|
||||
{$endif}
|
||||
save_char : char; //DT
|
||||
end;
|
||||
TNET = st_net;
|
||||
PNET = ^TNET;
|
||||
|
||||
Const
|
||||
packet_error : longint = -1;
|
||||
|
||||
Type
|
||||
enum_field_types = ( FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
|
||||
FIELD_TYPE_SHORT, FIELD_TYPE_LONG,
|
||||
FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE,
|
||||
FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP,
|
||||
FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
|
||||
FIELD_TYPE_DATE, FIELD_TYPE_TIME,
|
||||
FIELD_TYPE_DATETIME,
|
||||
{$ifndef use_mysql_321}
|
||||
FIELD_TYPE_YEAR,
|
||||
FIELD_TYPE_NEWDATE,
|
||||
{$endif}
|
||||
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);
|
||||
|
||||
Const
|
||||
FIELD_TYPE_CHAR = FIELD_TYPE_TINY; { For compability }
|
||||
FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM; { For compability }
|
||||
|
||||
{
|
||||
extern unsigned long max_allowed_packet;
|
||||
extern unsigned long net_buffer_length;
|
||||
}
|
||||
|
||||
{
|
||||
#define net_new_transaction(net) ((net)->pkt_nr=0)
|
||||
}
|
||||
|
||||
|
||||
Type
|
||||
TRand_struct = record
|
||||
seed,seed2,max_value : Cardinal;
|
||||
max_value_dbl : double;
|
||||
end;
|
||||
PRand_struct = ^TRand_struct;
|
||||
|
||||
{ The following is for user defined functions }
|
||||
|
||||
Item_result = (STRING_RESULT,REAL_RESULT,INT_RESULT);
|
||||
|
||||
st_udf_args = record
|
||||
arg_count : cardinal; { Number of arguments }
|
||||
arg_type : ^Item_result; { Pointer to item_results }
|
||||
args : ppchar; { Pointer to argument }
|
||||
lengths : PCardinal; { Length of string arguments }
|
||||
end;
|
||||
TUDF_ARGS = st_udf_args;
|
||||
PUDPF_ARGS = ^TUDF_ARGS;
|
||||
|
||||
{ This holds information about the result }
|
||||
|
||||
st_udf_init = record
|
||||
maybe_null : my_bool; { 1 if function can return NULL }
|
||||
decimals : cardinal; { for real functions }
|
||||
max_length : Cardinal; { For string functions }
|
||||
ptr : PChar; { free pointer for function data }
|
||||
end;
|
||||
TUDF_INIT = st_udf_init;
|
||||
PUDF_INIT = TUDF_INIT;
|
||||
{$i mysql3_comtypes.inc}
|
||||
|
||||
{ Prototypes to password functions }
|
||||
|
||||
Procedure sql_free (root : PMEM_ROOT);stdcall;external;
|
||||
Procedure init_alloc_root (root: PMEM_ROOT;block_size : Cardinal);stdcall;external;
|
||||
Function sql_alloc_first_block(root : PMEM_ROOT) : my_bool;stdcall;external;
|
||||
Function sql_alloc_root(mem_root : PMEM_ROOT;len : Cardinal) : longint;stdcall;external;
|
||||
Function sql_strdup_root(root : PMEM_ROOT;st : pchar) : pchar;stdcall;external;
|
||||
Function sql_memdup_root(root: PMEM_ROOT;st : pchar; len : Cardinal) : longint;stdcall;external;
|
||||
Function my_net_init(net :PNET; fd : Socket) : Longint;stdcall;external;
|
||||
procedure net_end(net : PNET);stdcall;external;
|
||||
Procedure net_clear(net : PNET);stdcall;external;
|
||||
Function net_flush(net : PNET) : longint;stdcall;external;
|
||||
Function my_net_write(net : PNET;packet : pbyte;len : cardinal) : longint;stdcall;external;
|
||||
Function net_write_command(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;stdcall;external;
|
||||
Function net_real_write(net : PNET;packet : pbyte; len : Cardinal) : longint;stdcall;external;
|
||||
Function my_net_read(net : PNET) : Cardinal;stdcall;external;
|
||||
procedure randominit(rand : Prand_struct; seed1,seed2 : Cardinal);stdcall;external;
|
||||
Function rnd(rand : Prand_struct) : double;stdcall;external;
|
||||
procedure make_scrambled_password(toarg, passwd : Pchar);stdcall;external;
|
||||
procedure get_salt_from_password(res : pcardinal; password : pchar);stdcall;external;
|
||||
procedure scramble(toarg,message,password : pchar; old_ver : my_bool);stdcall;external;
|
||||
function check_scramble(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;stdcall;external;
|
||||
function get_tty_password(opt_message: pchar) : pchar;stdcall;external;
|
||||
Procedure sql_free (root : PMEM_ROOT);extdecl;external;
|
||||
Procedure init_alloc_root (root: PMEM_ROOT;block_size : Cardinal);extdecl;external;
|
||||
Function sql_alloc_first_block(root : PMEM_ROOT) : my_bool;extdecl;external;
|
||||
Function sql_alloc_root(mem_root : PMEM_ROOT;len : Cardinal) : longint;extdecl;external;
|
||||
Function sql_strdup_root(root : PMEM_ROOT;st : pchar) : pchar;extdecl;external;
|
||||
Function sql_memdup_root(root: PMEM_ROOT;st : pchar; len : Cardinal) : longint;extdecl;external;
|
||||
Function my_net_init(net :PNET; fd : Socket) : Longint;extdecl;external;
|
||||
procedure net_end(net : PNET);extdecl;external;
|
||||
Procedure net_clear(net : PNET);extdecl;external;
|
||||
Function net_flush(net : PNET) : longint;extdecl;external;
|
||||
Function my_net_write(net : PNET;packet : pbyte;len : cardinal) : longint;extdecl;external;
|
||||
Function net_write_command(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;extdecl;external;
|
||||
Function net_real_write(net : PNET;packet : pbyte; len : Cardinal) : longint;extdecl;external;
|
||||
Function my_net_read(net : PNET) : Cardinal;extdecl;external;
|
||||
procedure randominit(rand : Prand_struct; seed1,seed2 : Cardinal);extdecl;external;
|
||||
Function rnd(rand : Prand_struct) : double;extdecl;external;
|
||||
procedure make_scrambled_password(toarg, passwd : Pchar);extdecl;external;
|
||||
procedure get_salt_from_password(res : pcardinal; password : pchar);extdecl;external;
|
||||
procedure scramble(toarg,message,password : pchar; old_ver : my_bool);extdecl;external;
|
||||
function check_scramble(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;extdecl;external;
|
||||
function get_tty_password(opt_message: pchar) : pchar;extdecl;external;
|
||||
|
||||
(*
|
||||
#define NULL_LENGTH ((unsigned long) ~0) { For net_store_length }
|
||||
@ -267,8 +70,13 @@ implementation
|
||||
|
||||
|
||||
end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.4 2005-02-14 17:13:19 peter
|
||||
Revision 1.5 2005-03-25 12:03:53 michael
|
||||
+ MySQL 3 dynamic connection by Bram Kuijvenhoven
|
||||
|
||||
Revision 1.4 2005/02/14 17:13:19 peter
|
||||
* truncate log
|
||||
|
||||
}
|
||||
|
114
packages/base/mysql/mysql3_comdyn.pp
Normal file
114
packages/base/mysql/mysql3_comdyn.pp
Normal file
@ -0,0 +1,114 @@
|
||||
{
|
||||
Contains the MySQL_com functions calls
|
||||
|
||||
Call InitialiseMysql3_com before using any of the calls, and call ReleaseMysql3_com
|
||||
when finished.
|
||||
}
|
||||
unit mysql3_comdyn;
|
||||
|
||||
{
|
||||
Adapted from mysql4_comdyn by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
{$MACRO on}
|
||||
|
||||
interface
|
||||
|
||||
uses dynlibs, sysutils;
|
||||
|
||||
{$IFDEF Unix}
|
||||
{$DEFINE extdecl:=cdecl}
|
||||
const
|
||||
Mysqllib = 'libmysqlclient.so';
|
||||
{$ENDIF}
|
||||
{$IFDEF Win32}
|
||||
{$DEFINE extdecl:=stdcall}
|
||||
const
|
||||
Mysqllib = 'libmysql.dll';
|
||||
{$ENDIF}
|
||||
|
||||
{$PACKRECORDS C}
|
||||
|
||||
{$i mysql3_comtypes.inc}
|
||||
|
||||
var
|
||||
sql_free : procedure(root : PMEM_ROOT);extdecl;
|
||||
init_alloc_root : procedure(root: PMEM_ROOT;block_size : Cardinal);extdecl;
|
||||
sql_alloc_first_block : function(root : PMEM_ROOT) : my_bool;extdecl;
|
||||
sql_alloc_root : function(mem_root : PMEM_ROOT;len : Cardinal) : longint;extdecl;
|
||||
sql_strdup_root : function(root : PMEM_ROOT;st : pchar) : pchar;extdecl;
|
||||
sql_memdup_root : function(root: PMEM_ROOT;st : pchar; len : Cardinal) : longint;extdecl;
|
||||
my_net_init : function(net :PNET; fd : Socket) : Longint;extdecl;
|
||||
net_end : procedure(net : PNET);extdecl;
|
||||
net_clear : procedure(net : PNET);extdecl;
|
||||
net_flush : function(net : PNET) : longint;extdecl;
|
||||
my_net_write : function(net : PNET;packet : pbyte;len : cardinal) : longint;extdecl;
|
||||
net_write_command : function(net : PNET; command : char;packet : pbyte;len : cardinal) : longint;extdecl;
|
||||
net_real_write : function(net : PNET;packet : pbyte; len : Cardinal) : longint;extdecl;
|
||||
my_net_read : function(net : PNET) : Cardinal;extdecl;
|
||||
randominit : procedure(rand : Prand_struct; seed1,seed2 : Cardinal);extdecl;
|
||||
rnd : function(rand : Prand_struct) : double;extdecl;
|
||||
make_scrambled_password : procedure(toarg, passwd : Pchar);extdecl;
|
||||
get_salt_from_password : procedure(res : pcardinal; password : pchar);extdecl;
|
||||
scramble : procedure(toarg,message,password : pchar; old_ver : my_bool);extdecl;
|
||||
check_scramble : function(scramble,message : pchar; salt : cardinal;old_ver:my_bool) : my_bool;extdecl;
|
||||
get_tty_password : function(opt_message: pchar) : pchar;extdecl;
|
||||
|
||||
Procedure InitialiseMysql3_com;
|
||||
Procedure ReleaseMysql3_com;
|
||||
|
||||
var Mysql3_comLibraryHandle : TLibHandle;
|
||||
|
||||
implementation
|
||||
|
||||
var RefCount : integer;
|
||||
|
||||
Procedure InitialiseMysql3_com;
|
||||
|
||||
begin
|
||||
inc(RefCount);
|
||||
if RefCount = 1 then
|
||||
begin
|
||||
Mysql3_comLibraryHandle := loadlibrary(Mysqllib);
|
||||
if Mysql3_comLibraryHandle = nilhandle then
|
||||
begin
|
||||
RefCount := 0;
|
||||
Raise EInOutError.Create('Can not load MySQL client. Is it installed? ('+Mysqllib+')');
|
||||
end;
|
||||
|
||||
pointer(sql_free) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_free');
|
||||
pointer(init_alloc_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'init_alloc_root');
|
||||
pointer(sql_alloc_first_block) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_alloc_first_block');
|
||||
pointer(sql_alloc_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_alloc_root');
|
||||
pointer(sql_strdup_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_strdup_root');
|
||||
pointer(sql_memdup_root) := GetProcedureAddress(Mysql3_comLibraryHandle,'sql_memdup_root');
|
||||
pointer(my_net_init) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_init');
|
||||
pointer(net_end) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_end');
|
||||
pointer(net_clear) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_clear');
|
||||
pointer(net_flush) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_flush');
|
||||
pointer(my_net_write) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_write');
|
||||
pointer(net_write_command) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_write_command');
|
||||
pointer(net_real_write) := GetProcedureAddress(Mysql3_comLibraryHandle,'net_real_write');
|
||||
pointer(my_net_read) := GetProcedureAddress(Mysql3_comLibraryHandle,'my_net_read');
|
||||
pointer(randominit) := GetProcedureAddress(Mysql3_comLibraryHandle,'randominit');
|
||||
pointer(rnd) := GetProcedureAddress(Mysql3_comLibraryHandle,'rnd');
|
||||
pointer(make_scrambled_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'make_scrambled_password');
|
||||
pointer(get_salt_from_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'get_salt_from_password');
|
||||
pointer(scramble) := GetProcedureAddress(Mysql3_comLibraryHandle,'scramble');
|
||||
pointer(check_scramble) := GetProcedureAddress(Mysql3_comLibraryHandle,'check_scramble');
|
||||
pointer(get_tty_password) := GetProcedureAddress(Mysql3_comLibraryHandle,'get_tty_password');
|
||||
end;
|
||||
end;
|
||||
|
||||
Procedure ReleaseMysql3_com;
|
||||
|
||||
begin
|
||||
if RefCount > 0 then dec(RefCount);
|
||||
if RefCount = 0 then
|
||||
begin
|
||||
if not UnloadLibrary(Mysql3_comLibraryHandle) then inc(RefCount);
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
213
packages/base/mysql/mysql3_comtypes.inc
Normal file
213
packages/base/mysql/mysql3_comtypes.inc
Normal file
@ -0,0 +1,213 @@
|
||||
{
|
||||
Contains the types needed for mysql3_com
|
||||
}
|
||||
|
||||
{
|
||||
Adapted from mysql3_com by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
|
||||
{ Extra types introduced for pascal }
|
||||
Type
|
||||
pbyte = ^byte;
|
||||
pcardinal = ^cardinal;
|
||||
Socket = longint;
|
||||
my_bool = byte;
|
||||
|
||||
Const
|
||||
NAME_LEN = 64 ; { Field/table name length }
|
||||
LOCAL_HOST : pchar = 'localhost' ;
|
||||
|
||||
MYSQL_PORT = 3306; { Alloced by ISI for MySQL }
|
||||
MYSQL_UNIX_ADDR : pchar = '/tmp/mysql.sock';
|
||||
|
||||
Type
|
||||
enum_server_command = ( COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
|
||||
COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,COM_REFRESH,
|
||||
COM_SHUTDOWN,COM_STATISTICS,
|
||||
COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
|
||||
COM_DEBUG);
|
||||
|
||||
Const
|
||||
NOT_NULL_FLAG = 1; { Field can't be NULL }
|
||||
PRI_KEY_FLAG = 2; { Field is part of a primary key }
|
||||
UNIQUE_KEY_FLAG = 4; { Field is part of a unique key }
|
||||
MULTIPLE_KEY_FLAG = 8; { Field is part of a key }
|
||||
BLOB_FLAG = 16; { Field is a blob }
|
||||
UNSIGNED_FLAG = 32; { Field is unsigned }
|
||||
ZEROFILL_FLAG = 64; { Field is zerofill }
|
||||
BINARY_FLAG = 128;
|
||||
{ The following are only sent to new clients }
|
||||
ENUM_FLAG = 256; { field is an enum }
|
||||
AUTO_INCREMENT_FLAG = 512; { field is a autoincrement field }
|
||||
TIMESTAMP_FLAG = 1024; { Field is a timestamp }
|
||||
PART_KEY_FLAG = 16384; { Intern; Part of some key }
|
||||
GROUP_FLAG = 32768; { Intern group field }
|
||||
{$ifndef use_mysql_321}
|
||||
UNIQUE_FLAG = 65536; { Intern: Used by sql_yacc }
|
||||
{$endif}
|
||||
|
||||
REFRESH_GRANT = 1; { Refresh grant tables }
|
||||
REFRESH_LOG = 2; { Start on new log file }
|
||||
REFRESH_TABLES = 4; { close all tables }
|
||||
{$ifndef use_mysql_321}
|
||||
REFRESH_HOSTS = 8; { Flush host cache }
|
||||
REFRESH_STATUS = 16; { Flush status variables }
|
||||
REFRESH_THREADS = 32; { Flush status variables }
|
||||
REFRESH_SLAVE = 64; { Reset master info and restart slave
|
||||
thread }
|
||||
REFRESH_MASTER = 128; { Remove all bin logs in the index
|
||||
and truncate the index }
|
||||
{$endif}
|
||||
|
||||
{$ifndef use_mysql_321}
|
||||
{ The following can't be set with mysql_refresh() }
|
||||
REFRESH_READ_LOCK = 16384; { Lock tables for read }
|
||||
REFRESH_FAST = 32768; { Intern flag }
|
||||
{$endif}
|
||||
|
||||
CLIENT_LONG_PASSWORD = 1; { new more secure passwords }
|
||||
CLIENT_FOUND_ROWS = 2; { Found instead of affected rows }
|
||||
CLIENT_LONG_FLAG = 4; { Get all column flags }
|
||||
{$ifndef use_mysql_321}
|
||||
CLIENT_CONNECT_WITH_DB = 8; { One can specify db on connect }
|
||||
CLIENT_NO_SCHEMA = 16; { Don't allow database.table.column }
|
||||
CLIENT_COMPRESS = 32; { Can use compression protocol }
|
||||
CLIENT_ODBC = 64; { Odbc client }
|
||||
CLIENT_LOCAL_FILES = 128; { Can use LOAD DATA LOCAL }
|
||||
CLIENT_IGNORE_SPACE = 256; { Ignore spaces before '(' }
|
||||
CLIENT_CHANGE_USER = 512; { Support the mysql_change_user() }
|
||||
CLIENT_INTERACTIVE = 1024; { This is an interactive client }
|
||||
CLIENT_SSL = 2048; { Switch to SSL after handshake }
|
||||
CLIENT_IGNORE_SIGPIPE = 4096; { IGNORE sigpipes }
|
||||
CLIENT_TRANSACTIONS = 8192; { Client knows about transactions }
|
||||
|
||||
SERVER_STATUS_IN_TRANS = 1; { Transaction has started }
|
||||
SERVER_STATUS_AUTOCOMMIT = 2; { Server in auto_commit mode }
|
||||
{$endif}
|
||||
|
||||
MYSQL_ERRMSG_SIZE = 200;
|
||||
NET_READ_TIMEOUT = 30; { Timeout on read }
|
||||
NET_WRITE_TIMEOUT = 60; { Timeout on write }
|
||||
NET_WAIT_TIMEOUT = 8*60*60; { Wait for new query }
|
||||
|
||||
Type
|
||||
pst_used_mem = ^st_used_mem;
|
||||
st_used_mem = record { struct for once_alloc }
|
||||
next : pst_used_mem; { Next block in use }
|
||||
left : cardinal; { memory left in block }
|
||||
size : cardinal; { size of block }
|
||||
end;
|
||||
|
||||
TUSED_MEM = st_used_mem;
|
||||
PUSED_MEM = ^TUSED_MEM;
|
||||
|
||||
TError_handler = Procedure;
|
||||
|
||||
st_mem_root = record
|
||||
free : PUSED_MEM;
|
||||
used : PUSED_MEM;
|
||||
{$ifndef use_mysql_321}
|
||||
pre_alloc: PUSED_MEM;
|
||||
{$endif use_mysql_321}
|
||||
min_malloc : cardinal;
|
||||
block_size : cardinal;
|
||||
error_handler : TERROR_Handler;
|
||||
end;
|
||||
TMEM_ROOT = st_mem_root;
|
||||
PMEM_ROOT = ^TMEM_ROOT;
|
||||
|
||||
Type
|
||||
net_type = (NET_TYPE_TCPIP, NET_TYPE_SOCKET, NETTYPE_NAMEDPIPE);
|
||||
st_net = record
|
||||
nettype : net_type; //DT
|
||||
fd : Socket;
|
||||
fcntl : Longint;
|
||||
buff,buff_end,write_pos,read_pos : Pchar;//DT
|
||||
last_error : array [0..MYSQL_ERRMSG_SIZE-1] of char;
|
||||
last_errno,max_packet,timeout,pkt_nr : Cardinal;
|
||||
error,return_errno : my_bool;
|
||||
compress : my_bool; //DT
|
||||
{$ifndef use_mysql_321}
|
||||
no_send_ok : my_bool;
|
||||
{$endif}
|
||||
remain_in_buf,r_length, buf_length, where_b : ptruint; //DT
|
||||
{$ifndef use_mysql_321}
|
||||
return_status : ^Cardinal;
|
||||
reading_or_writing : my_bool;
|
||||
{$else}
|
||||
more : my_bool;//DT
|
||||
{$endif}
|
||||
save_char : char; //DT
|
||||
end;
|
||||
TNET = st_net;
|
||||
PNET = ^TNET;
|
||||
|
||||
Const
|
||||
packet_error : longint = -1;
|
||||
|
||||
Type
|
||||
enum_field_types = ( FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY,
|
||||
FIELD_TYPE_SHORT, FIELD_TYPE_LONG,
|
||||
FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE,
|
||||
FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP,
|
||||
FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24,
|
||||
FIELD_TYPE_DATE, FIELD_TYPE_TIME,
|
||||
FIELD_TYPE_DATETIME,
|
||||
{$ifndef use_mysql_321}
|
||||
FIELD_TYPE_YEAR,
|
||||
FIELD_TYPE_NEWDATE,
|
||||
{$endif}
|
||||
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);
|
||||
|
||||
Const
|
||||
FIELD_TYPE_CHAR = FIELD_TYPE_TINY; { For compability }
|
||||
FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM; { For compability }
|
||||
|
||||
{
|
||||
extern unsigned long max_allowed_packet;
|
||||
extern unsigned long net_buffer_length;
|
||||
}
|
||||
|
||||
{
|
||||
#define net_new_transaction(net) ((net)->pkt_nr=0)
|
||||
}
|
||||
|
||||
|
||||
Type
|
||||
TRand_struct = record
|
||||
seed,seed2,max_value : Cardinal;
|
||||
max_value_dbl : double;
|
||||
end;
|
||||
PRand_struct = ^TRand_struct;
|
||||
|
||||
{ The following is for user defined functions }
|
||||
|
||||
Item_result = (STRING_RESULT,REAL_RESULT,INT_RESULT);
|
||||
|
||||
st_udf_args = record
|
||||
arg_count : cardinal; { Number of arguments }
|
||||
arg_type : ^Item_result; { Pointer to item_results }
|
||||
args : ppchar; { Pointer to argument }
|
||||
lengths : PCardinal; { Length of string arguments }
|
||||
end;
|
||||
TUDF_ARGS = st_udf_args;
|
||||
PUDPF_ARGS = ^TUDF_ARGS;
|
||||
|
||||
{ This holds information about the result }
|
||||
|
||||
st_udf_init = record
|
||||
maybe_null : my_bool; { 1 if function can return NULL }
|
||||
decimals : cardinal; { for real functions }
|
||||
max_length : Cardinal; { For string functions }
|
||||
ptr : PChar; { free pointer for function data }
|
||||
end;
|
||||
TUDF_INIT = st_udf_init;
|
||||
PUDF_INIT = TUDF_INIT;
|
||||
|
@ -30,8 +30,13 @@ Const
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.2 2005-02-14 17:13:19 peter
|
||||
Revision 1.3 2005-03-25 12:03:53 michael
|
||||
+ MySQL 3 dynamic connection by Bram Kuijvenhoven
|
||||
|
||||
Revision 1.2 2005/02/14 17:13:19 peter
|
||||
* truncate log
|
||||
|
||||
}
|
||||
|
180
packages/base/mysql/mysql3dyn.pp
Normal file
180
packages/base/mysql/mysql3dyn.pp
Normal file
@ -0,0 +1,180 @@
|
||||
{
|
||||
Contains the MySQL 3 functions calls
|
||||
|
||||
Call InitialiseMysql3 before using any of the calls, and call ReleaseMysql3
|
||||
when finished.
|
||||
}
|
||||
unit mysql3dyn;
|
||||
|
||||
{
|
||||
Adapted from mysql4dyn by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
{$MACRO on}
|
||||
|
||||
interface
|
||||
|
||||
uses dynlibs, classes, sysutils, mysql3_comdyn;
|
||||
|
||||
{$IFDEF Unix}
|
||||
{$DEFINE extdecl:=cdecl}
|
||||
const
|
||||
Mysqllib = 'libmysqlclient.so';
|
||||
{$ENDIF}
|
||||
{$IFDEF Win32}
|
||||
{$DEFINE extdecl:=stdcall}
|
||||
const
|
||||
Mysqllib = 'libmysql.dll';
|
||||
{$ENDIF}
|
||||
|
||||
{$PACKRECORDS C}
|
||||
|
||||
{$i mysql3types.inc}
|
||||
|
||||
type tpcharfunction = function : pchar; extdecl;
|
||||
|
||||
var
|
||||
mysql_num_rows : function(res : PMYSQL_RES) : my_ulonglong; extdecl;
|
||||
mysql_num_fields : function(res : PMYSQL_RES) : Cardinal; extdecl;
|
||||
mysql_eof : function(res : PMYSQL_RES) : my_bool; extdecl;
|
||||
mysql_fetch_field_direct : function(res : PMYSQL_RES; fieldnr : Cardinal) : PMYSQL_FIELD; extdecl;
|
||||
mysql_fetch_fields : function(res : PMYSQL_RES) : PMYSQL_FIELD; extdecl;
|
||||
mysql_row_tell : function(res : PMYSQL_RES) : PMYSQL_ROWS; extdecl;
|
||||
mysql_field_tell : function(res : PMYSQL_RES) : Cardinal; extdecl;
|
||||
mysql_affected_rows : function(mysql : PMYSQL): my_ulonglong; extdecl;
|
||||
mysql_insert_id : function(mysql : PMYSQL): my_ulonglong; extdecl;
|
||||
mysql_errno : function(mysql : PMYSQL) : Cardinal; extdecl;
|
||||
mysql_info : function(mysql : PMYSQL): Pchar; extdecl;
|
||||
mysql_thread_id : function(mysql : PMYSQL) : ptruint; extdecl;
|
||||
mysql_error : function(mysql : PMYSQL) : pchar; extdecl;
|
||||
|
||||
mysql_init : function(mysql: PMYSQL) : PMYSQL;extdecl;
|
||||
mysql_connect : function(mysql : PMYSQL; host,user,passwd: pchar) : PMYSQL;extdecl;
|
||||
mysql_real_connect : function(mysql : PMYSQL; const host,user,passwd : pchar;
|
||||
port : cardinal;
|
||||
unix_socket : pchar;
|
||||
clientflag : cardinal) : PMYSQL;extdecl;
|
||||
mysql_close : function(sock : PMYSQL) : longint ;extdecl;
|
||||
mysql_select_db : function(MYSQL : PMYSQL; db : Pchar) : longint;extdecl;
|
||||
mysql_query : function(mysql : PMYSQL; q : pchar) : longint;extdecl;
|
||||
mysql_real_query : function(mysql : PMYSQL; q : Pchar; length : longint) : longint;extdecl;
|
||||
mysql_create_db : function(mysql : PMYSQL; db : pchar) : longint;extdecl;
|
||||
mysql_drop_db : function(mysql : PMYSQL; DB : Pchar) : longint;extdecl;
|
||||
mysql_shutdown : function(mysql : PMYSQL) : longint;extdecl;
|
||||
mysql_dump_debug_info : function(mysql : PMYSQL) : longint;extdecl;
|
||||
mysql_refresh : function(mysql : PMYSQL; refresh_options : cardinal) : longint;extdecl;
|
||||
mysql_kill : function(mysql : PMYSQL; pid : Cardinal) : longint;extdecl;
|
||||
mysql_stat : function(mysql : PMYSQL) : Pchar;extdecl;
|
||||
mysql_get_server_info : function(mysql : PMYSQL) : pchar;extdecl;
|
||||
mysql_get_client_info : function : pchar;extdecl;
|
||||
mysql_get_host_info : function(mysql : PMYSQL) : pchar;extdecl;
|
||||
mysql_get_proto_info : function(mysql : PMYSQL) : Cardinal;extdecl;
|
||||
mysql_list_dbs : function(mysql : PMYSQL;wild : Pchar) : PMYSQL_RES;extdecl;
|
||||
mysql_list_tables : function(mysql : PMYSQL;Wild : Pchar) : PMYSQL_RES;extdecl;
|
||||
mysql_list_fields : function(mysql : PMYSQL; table,wild : pchar) : PMYSQL_RES;extdecl;
|
||||
mysql_list_processes : function(mysql : PMYSQL) : PMYSQL_RES;extdecl;
|
||||
mysql_store_result : function(mysql : PMYSQL) : PMYSQL_RES;extdecl;
|
||||
mysql_use_result : function(mysql : PMYSQL) : PMYSQL_RES;extdecl;
|
||||
mysql_free_result : procedure(res : PMYSQL_RES);extdecl;
|
||||
mysql_data_seek : procedure(mysql : PMYSQL_RES; offs : cardinal);extdecl;
|
||||
mysql_row_seek : function(mysql : PMYSQL_RES; Offs: TMYSQL_ROW_OFFSET): TMYSQL_ROW_OFFSET;extdecl;
|
||||
mysql_field_seek : function(musql : PMYSQL_RES;offs : TMYSQL_FIELD_OFFSET): TMYSQL_FIELD_OFFSET;extdecl;
|
||||
mysql_fetch_row : function(mysql : PMYSQL_RES) : TMYSQL_ROW;extdecl;
|
||||
mysql_fetch_lengths : function(mysql : PMYSQL_RES) : PCardinal;extdecl;
|
||||
mysql_fetch_field : function(handle : PMYSQL_RES) : PMYSQL_FIELD;extdecl;
|
||||
mysql_escape_string : function(escto,escfrom : pchar; length : Cardinal) : cardinal;extdecl;
|
||||
mysql_debug : procedure(debug : pchar);extdecl;
|
||||
|
||||
Procedure InitialiseMysql3;
|
||||
Procedure ReleaseMysql3;
|
||||
|
||||
var Mysql3LibraryHandle : TLibHandle;
|
||||
|
||||
implementation
|
||||
|
||||
var RefCount : integer;
|
||||
|
||||
Procedure InitialiseMysql3;
|
||||
|
||||
begin
|
||||
inc(RefCount);
|
||||
if RefCount = 1 then
|
||||
begin
|
||||
Mysql3LibraryHandle := loadlibrary(Mysqllib);
|
||||
if Mysql3LibraryHandle = nilhandle then
|
||||
begin
|
||||
RefCount := 0;
|
||||
Raise EInOutError.Create('Can not load MySQL client. Is it installed? ('+Mysqllib+')');
|
||||
end;
|
||||
pointer(mysql_get_client_info) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_get_client_info');
|
||||
|
||||
// To avoid the strangest problems for ppl using other client-libs
|
||||
if copy(strpas(mysql_get_client_info()),1,4) <> '3.23' then
|
||||
Raise EInOutError.Create('This program can only work with the MySQL client version 3.23.x. Please use the right version of '+Mysqllib+'.');
|
||||
|
||||
pointer(mysql_num_rows) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_num_rows');
|
||||
pointer(mysql_num_fields) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_num_fields');
|
||||
pointer(mysql_eof) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_eof');
|
||||
pointer(mysql_fetch_field_direct) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_fetch_field_direct');
|
||||
pointer(mysql_fetch_fields) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_fetch_fields');
|
||||
pointer(mysql_row_tell) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_row_tell');
|
||||
pointer(mysql_field_tell) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_field_tell');
|
||||
pointer(mysql_affected_rows) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_affected_rows');
|
||||
pointer(mysql_insert_id) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_insert_id');
|
||||
pointer(mysql_errno) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_errno');
|
||||
pointer(mysql_info) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_info');
|
||||
pointer(mysql_thread_id) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_thread_id');
|
||||
pointer(mysql_error) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_error');
|
||||
|
||||
pointer(mysql_init) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_init');
|
||||
pointer(mysql_connect) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_connect');
|
||||
pointer(mysql_real_connect) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_real_connect');
|
||||
pointer(mysql_close) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_close');
|
||||
pointer(mysql_select_db) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_select_db');
|
||||
pointer(mysql_query) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_query');
|
||||
pointer(mysql_real_query) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_real_query');
|
||||
pointer(mysql_create_db) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_create_db');
|
||||
pointer(mysql_drop_db) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_drop_db');
|
||||
pointer(mysql_shutdown) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_shutdown');
|
||||
pointer(mysql_dump_debug_info) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_dump_debug_info');
|
||||
pointer(mysql_refresh) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_refresh');
|
||||
pointer(mysql_kill) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_kill');
|
||||
pointer(mysql_stat) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_stat');
|
||||
pointer(mysql_get_server_info) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_get_server_info');
|
||||
pointer(mysql_get_host_info) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_get_host_info');
|
||||
pointer(mysql_get_proto_info) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_get_proto_info');
|
||||
pointer(mysql_list_dbs) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_list_dbs');
|
||||
pointer(mysql_list_tables) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_list_tables');
|
||||
pointer(mysql_list_fields) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_list_fields');
|
||||
pointer(mysql_list_processes) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_list_processes');
|
||||
pointer(mysql_store_result) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_store_result');
|
||||
pointer(mysql_use_result) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_use_result');
|
||||
pointer(mysql_free_result) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_free_result');
|
||||
pointer(mysql_data_seek) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_data_seek');
|
||||
pointer(mysql_row_seek) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_row_seek');
|
||||
pointer(mysql_field_seek) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_field_seek');
|
||||
pointer(mysql_fetch_row) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_fetch_row');
|
||||
pointer(mysql_fetch_lengths) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_fetch_lengths');
|
||||
pointer(mysql_fetch_field) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_fetch_field');
|
||||
pointer(mysql_escape_string) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_escape_string');
|
||||
pointer(mysql_debug) := GetProcedureAddress(Mysql3LibraryHandle,'mysql_debug');
|
||||
|
||||
InitialiseMysql3_com;
|
||||
end;
|
||||
end;
|
||||
|
||||
Procedure ReleaseMysql3;
|
||||
|
||||
begin
|
||||
if RefCount > 0 then dec(RefCount);
|
||||
if RefCount = 0 then
|
||||
begin
|
||||
if not UnloadLibrary(Mysql3LibraryHandle) then inc(RefCount);
|
||||
ReleaseMysql3_com;
|
||||
end;
|
||||
end;
|
||||
|
||||
{$i mysql3impl.inc}
|
||||
|
||||
end.
|
13
packages/base/mysql/mysql3impl.inc
Normal file
13
packages/base/mysql/mysql3impl.inc
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
Contains the non-external functions for MySQL v3
|
||||
}
|
||||
|
||||
{
|
||||
Adapted from mysql3.pp by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
|
||||
Function mysql_reload(mysql : PMYSQL) : Longint;
|
||||
|
||||
begin
|
||||
mysql_reload:=mysql_refresh(mysql,REFRESH_GRANT)
|
||||
end;
|
173
packages/base/mysql/mysql3types.inc
Normal file
173
packages/base/mysql/mysql3types.inc
Normal file
@ -0,0 +1,173 @@
|
||||
{
|
||||
Contains the types needed for use with MySQL v3
|
||||
}
|
||||
|
||||
{
|
||||
Adapted from mysql3.pp by Bram Kuijvenhoven (Hexis BV, The Netherlands)
|
||||
}
|
||||
|
||||
type
|
||||
my_bool = byte;
|
||||
gptr = pchar;
|
||||
Socket = Longint;
|
||||
PCardinal = ^Cardinal;
|
||||
|
||||
{$ifdef linux}
|
||||
Var
|
||||
mysql_port : cardinal; external name 'mysql_port';
|
||||
mysql_unix_port : pchar; external name 'mysql_unix_port';
|
||||
{$endif}
|
||||
|
||||
{$ifdef darwin}
|
||||
Var
|
||||
mysql_port : cardinal; external mysqllib name 'mysql_port';
|
||||
mysql_unix_port : pchar; external mysqllib name 'mysql_unix_port';
|
||||
{$endif}
|
||||
|
||||
{
|
||||
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
|
||||
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
|
||||
#define IS_BLOB(n) ((n) & BLOB_FLAG)
|
||||
#define IS_NUM(t) ((t) <= FIELD_TYPE_INT24)
|
||||
}
|
||||
Type
|
||||
st_mysql_field = record
|
||||
name : Pchar; { Name of column }
|
||||
table : pchar; { Table of column if column was a field }
|
||||
def: pchar; { Default value (set by mysql_list_fields) }
|
||||
ftype : enum_field_types; { Type of field. See mysql_com.h for types }
|
||||
length : cardinal; { Width of column }
|
||||
max_length : cardinal; { Max width of selected set }
|
||||
flags : cardinal; { Div flags }
|
||||
decimals : cardinal; { Number of decimals in field }
|
||||
end;
|
||||
TMYSQL_FIELD = st_mysql_field;
|
||||
PMYSQL_FIELD = ^TMYSQL_FIELD;
|
||||
|
||||
TMYSQL_ROW = PPchar; { return data as array of strings }
|
||||
TMYSQL_FIELD_OFFSET = cardinal; { offset to current field }
|
||||
|
||||
{$ifndef oldmysql}
|
||||
my_ulonglong=qword;
|
||||
{$else}
|
||||
my_longlong=cardinal;
|
||||
{$endif}
|
||||
|
||||
PST_MYSQL_Rows = ^st_mysql_rows;
|
||||
st_mysql_rows = Record
|
||||
next : pst_mysql_rows; { list of rows }
|
||||
Data : TMYSQL_ROW;
|
||||
end;
|
||||
TMYSQL_ROWS = st_mysql_rows;
|
||||
PMYSQL_ROWS = ^TMYSQL_ROWS;
|
||||
|
||||
|
||||
TMYSQL_ROW_OFFSET = PMYSQL_ROWS; { offset to current row }
|
||||
|
||||
st_mysql_data = record
|
||||
rows : my_ulonglong;
|
||||
fields : cardinal;
|
||||
data : PMYSQL_ROWS;
|
||||
alloc : TMEM_ROOT;
|
||||
end;
|
||||
|
||||
TMYSQL_DATA = st_mysql_data;
|
||||
PMYSQL_DATA = ^TMYSQL_DATA;
|
||||
|
||||
st_mysql_options = record
|
||||
connect_timeout,client_flag : cardinal;
|
||||
compress,named_pipe : my_bool;
|
||||
port : cardinal;
|
||||
host,init_command,user,password,unix_socket,db : pchar;
|
||||
my_cnf_file,my_cnf_group : pchar;
|
||||
{$ifndef use_mysql_321}
|
||||
charset_dir, charset_name : pchar;
|
||||
use_ssl : my_bool;
|
||||
ssl_key, ssl_cert, ssl_ca, ssl_capath : pchar;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
{$ifndef use_mysql_321}
|
||||
mysql_option = (MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
|
||||
MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
|
||||
MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
|
||||
MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME);
|
||||
{$endif}
|
||||
|
||||
mysql_status = (MYSQL_STATUS_READY,
|
||||
MYSQL_STATUS_GET_RESULT,
|
||||
MYSQL_STATUS_USE_RESULT);
|
||||
|
||||
{$ifndef use_mysql_321}
|
||||
(*
|
||||
charset_info_st = Record
|
||||
number : cardinal;
|
||||
name : pchar;
|
||||
ctype : pointer {uchar*};
|
||||
to_lower : pointer {uchar*};
|
||||
to_upper : pointer {uchar*};
|
||||
sort_order : pointer {uchar*};
|
||||
strxfrm_multiply : cardinal;
|
||||
|
||||
{ einige nicht näher definierte Felder }
|
||||
a, strxfrm, strnncoll, strnxfrm, like_range : pointer;
|
||||
mbmaxlen : cardinal;
|
||||
ismbchar, ismbhead, mbcharlen : pointer;
|
||||
end;
|
||||
*)
|
||||
{$endif}
|
||||
|
||||
st_mysql = Record
|
||||
NET : TNET; { Communication parameters }
|
||||
{$ifndef use_mysql_321}
|
||||
connector_fd : gptr;
|
||||
{$endif}
|
||||
host,user,passwd,unix_socket,server_version,host_info,
|
||||
info,db : pchar;
|
||||
port,client_flag,server_capabilities : cardinal;
|
||||
protocol_version : cardinal;
|
||||
field_count : cardinal;
|
||||
{$ifndef use_mysql_321}
|
||||
server_status : cardinal;
|
||||
{$endif}
|
||||
thread_id : ptruint; { Id for connection in server }
|
||||
affected_rows : my_ulonglong;
|
||||
insert_id : my_ulonglong; { id if insert on table with NEXTNR }
|
||||
extra_info : my_ulonglong; { Used by mysqlshow }
|
||||
packet_length : sizeint;
|
||||
status : mysql_status;
|
||||
fields : PMYSQL_FIELD;
|
||||
field_alloc : TMEM_ROOT;
|
||||
free_me : my_bool; { If free in mysql_close }
|
||||
reconnect : my_bool; { set to 1 if automatic reconnect }
|
||||
options : st_mysql_options;
|
||||
{$ifndef use_mysql_321}
|
||||
scramble_buf : array[0..8] of char;
|
||||
charset : pointer { struct charset_info_st};
|
||||
server_language : cardinal;
|
||||
{$endif}
|
||||
end;
|
||||
TMYSQL = st_mysql;
|
||||
PMYSQL = ^TMYSQL;
|
||||
|
||||
|
||||
st_mysql_res = record
|
||||
row_count : my_ulonglong;
|
||||
field_count, current_field : cardinal;
|
||||
fields : PMYSQL_FIELD;
|
||||
data : PMYSQL_DATA;
|
||||
data_cursor : PMYSQL_ROWS;
|
||||
field_alloc : TMEM_ROOT;
|
||||
row : TMYSQL_ROW; { If unbuffered read }
|
||||
current_row : TMYSQL_ROW; { buffer to current row }
|
||||
lengths : psizeint; { column lengths of current row }
|
||||
handle : PMYSQL; { for unbuffered reads }
|
||||
eof : my_bool; { Used my mysql_fetch_row }
|
||||
end;
|
||||
TMYSQL_RES = st_mysql_res;
|
||||
PMYSQL_RES = ^TMYSQL_RES;
|
||||
|
||||
{ Translated macros }
|
||||
Function mysql_reload(mysql : PMYSQL) : Longint;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user