unit SQLDLL_def;
interface
uses
Windows, Classes;
type
TConnection_Info =
packed record
Name: PChar;
ID: Integer;
Database: PChar;
Connected: Boolean;
end;
type
TQuery_Info =
packed Record
Name: PChar;
ID: Integer;
Connection_ID: Integer;
Connection_Name: PChar;
Database: PChar;
end;
const
DLL_FILE = '
SQLDLL.DLL';
DLL_INCOMPATIBLE = 0;
DLL_UNDEFINED = 1;
DLL_MISSING = 2;
DLL_READY = 3;
DLL_ERROR = 4;
var
SQL_ERROR_TEXT:
function(ErrorCode: Integer): PChar;
SQL_ERROR_CODE:
function() : Integer;
LOAD_SQL:
function(): Boolean;
stdcall;
UNLOAD_SQL:
function(): Boolean;
stdcall;
GET_CONNECTION_COUNT:
function(): Integer;
stdcall;
GET_QUERY_COUNT:
function(): Integer;
stdcall;
GET_CONNECTION_INFO:
function(Connection_ID: Integer): TConnection_Info;
stdcall;
GET_QUERY_INFO:
function(Query_ID: Integer): TQuery_Info;
stdcall;
CONNECTION_ADD:
function(Protocol: PChar; Host: PChar; Port: Integer; User: PChar; Password: PChar;
Database: PChar): Integer;
stdcall;
CONNECTION_RELEASE:
function(Connection_ID: Integer): Boolean;
stdcall;
CONNECTION_CONNECT:
function(Connection_ID: Integer): Boolean;
stdcall;
CONNECTION_DISCONNECT:
function(Connection_ID: Integer): Boolean;
stdcall;
CONNECTION_CONNECTED:
function(Connection_ID: Integer): Boolean;
stdcall;
QUERY_ADD:
function(Connection_ID: Integer): Integer;
stdcall;
QUERY_RELEASE:
function(Query_ID: Integer): Boolean;
stdcall;
QUERY_CONNECTED:
function(Query_ID: Integer): Boolean;
stdcall;
QUERY_ACTIVE:
function(Query_ID: Integer): Boolean;
stdcall;
QUERY_EXEC:
function(Query_ID: Integer): Boolean;
stdcall;
SQL_QUERY_CLEAR:
function(Query_ID: Integer): Boolean;
stdcall;
SQL_QUERY_ADD:
function(Query_ID: Integer; S: PChar): Boolean;
stdcall;
SQL_QUERY_TEXT:
function(Query_ID: Integer; S: PChar): Boolean;
stdcall;
SQL_RESULT_COUNT:
function(Query_ID: Integer): Integer;
stdcall;
SQL_RESULT_FIRST:
function(Query_ID: Integer): Boolean;
stdcall;
SQL_RESULT_NEXT:
function(Query_ID: Integer): Boolean;
stdcall;
SQL_RESULT_FIELD:
function(Query_ID: Integer; Fieldname: PChar;
var ResVal: Variant): Boolean;
stdcall;
var
LibSQL_Handle: Cardinal;
DLL_Status: Byte = DLL_UNDEFINED;
function LibSQL_load: Byte;
function LibSQL_Unload: Boolean;
procedure LibSQL_Protocols(List: TStrings);
implementation
function LibSQL_Unload: Boolean;
begin
try
if LibSQL_Handle <> 0
then begin
UNLOAD_SQL;
FreeLibrary(LibSQL_Handle);
end;
LibSQL_Handle := 0;
DLL_Status := DLL_UNDEFINED;
Result := True;
except
DLL_Status := DLL_ERROR;
Result := False;
end;
end;
function LibSQL_load: Byte;
procedure Assign_Proc(
var proc: FARPROC;
Name: pChar);
begin
Proc := GetProcAddress(LibSQL_Handle,
Name);
if Proc =
nil then
DLL_Status := DLL_INCOMPATIBLE;
end;
begin
Result := DLL_ERROR;
if LibSQL_Unload
then begin
LibSQL_Handle := LoadLibrary(DLL_FILE);
if LibSQL_Handle = 0
then
DLL_Status := DLL_MISSING
else begin
DLL_Status := DLL_READY;
Assign_Proc(@SQL_ERROR_TEXT, '
SQL_ERROR_TEXT');
Assign_Proc(@SQL_ERROR_CODE, '
SQL_ERROR_CODE');
Assign_Proc(@LOAD_SQL, '
LOAD_SQL');
Assign_Proc(@UNLOAD_SQL, '
UNLOAD_SQL');
Assign_Proc(@GET_CONNECTION_COUNT, '
GET_CONNECTION_COUNT');
Assign_Proc(@GET_QUERY_COUNT, '
GET_QUERY_COUNT');
Assign_Proc(@GET_CONNECTION_INFO, '
GET_CONNECTION_INFO');
Assign_Proc(@GET_QUERY_INFO, '
GET_QUERY_INFO');
Assign_Proc(@CONNECTION_ADD, '
CONNECTION_ADD');
Assign_Proc(@CONNECTION_RELEASE, '
CONNECTION_RELEASE');
Assign_Proc(@CONNECTION_CONNECT, '
CONNECTION_CONNECT');
Assign_Proc(@CONNECTION_DISCONNECT, '
CONNECTION_DISCONNECT');
Assign_Proc(@CONNECTION_CONNECTED, '
CONNECTION_CONNECTED');
Assign_Proc(@QUERY_ADD, '
QUERY_ADD');
Assign_Proc(@QUERY_RELEASE, '
QUERY_RELEASE');
Assign_Proc(@QUERY_CONNECTED, '
QUERY_CONNECTED');
Assign_Proc(@QUERY_ACTIVE, '
QUERY_ACTIVE');
Assign_Proc(@QUERY_EXEC, '
QUERY_EXEC');
Assign_Proc(@SQL_QUERY_CLEAR, '
SQL_QUERY_CLEAR');
Assign_Proc(@SQL_QUERY_ADD, '
SQL_QUERY_ADD');
Assign_Proc(@SQL_QUERY_TEXT, '
SQL_QUERY_TEXT');
Assign_Proc(@SQL_RESULT_COUNT, '
SQL_RESULT_COUNT');
Assign_Proc(@SQL_RESULT_FIRST, '
SQL_RESULT_FIRST');
Assign_Proc(@SQL_RESULT_NEXT, '
SQL_RESULT_NEXT');
Assign_Proc(@SQL_RESULT_FIELD, '
SQL_RESULT_FIELD');
end;
end
else DLL_Status := DLL_ERROR;
try
if LOAD_SQL
then
Result := DLL_Status;
except
DLL_Status := DLL_ERROR;
Result := DLL_Status;
end;
end;
procedure LibSQL_Protocols(List: TStrings);
type
TGetProtCount =
function(): Integer;
stdcall;
TGetProt =
function(ProtocolNum: Integer): PChar;
stdcall;
var
GetProtCount: TGetProtCount;
GetProt: TGetProt;
I: Integer;
begin
List.Clear;
if LibSQL_Handle <> 0
then begin
@GetProtCount := GetProcAddress(LibSQL_Handle, '
GET_PROTOCOL_COUNT');
@GetProt := GetProcAddress(LibSQL_Handle, '
GET_PROTOCOL');
if (@GetProtCount <>
nil)
and (@GetProt <>
nil)
then begin
for I := 0
to GetProtCount -1
do begin
List.Add( GetProt(I) );
end;
end;
end;
end;
end.