mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 19:29:27 +02:00
+ patch from Bram Kuijvenhoven:
- removed unused private field TODBCConnection.FDataSourceName - added local proc ODBCResultToStr - fix in SQLDriverConnect parameter - prevent freeing of handles that should not be freed in some cases git-svn-id: trunk@1635 -
This commit is contained in:
parent
6c0225cef6
commit
a63ed341a7
@ -56,7 +56,6 @@ type
|
|||||||
|
|
||||||
TODBCConnection = class(TSQLConnection)
|
TODBCConnection = class(TSQLConnection)
|
||||||
private
|
private
|
||||||
FDataSourceName: string;
|
|
||||||
FDriver: string;
|
FDriver: string;
|
||||||
FEnvironment:TODBCEnvironment;
|
FEnvironment:TODBCEnvironment;
|
||||||
FDBCHandle:SQLHDBC; // ODBC Connection Handle
|
FDBCHandle:SQLHDBC; // ODBC Connection Handle
|
||||||
@ -140,6 +139,21 @@ begin
|
|||||||
Result:=(Res=SQL_SUCCESS) or (Res=SQL_SUCCESS_WITH_INFO);
|
Result:=(Res=SQL_SUCCESS) or (Res=SQL_SUCCESS_WITH_INFO);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ODBCResultToStr(Res:SQLRETURN):string;
|
||||||
|
begin
|
||||||
|
case Res of
|
||||||
|
SQL_SUCCESS: Result:='SQL_SUCCESS';
|
||||||
|
SQL_SUCCESS_WITH_INFO:Result:='SQL_SUCCESS_WITH_INFO';
|
||||||
|
SQL_ERROR: Result:='SQL_ERROR';
|
||||||
|
SQL_INVALID_HANDLE: Result:='SQL_INVALID_HANDLE';
|
||||||
|
SQL_NO_DATA: Result:='SQL_NO_DATA';
|
||||||
|
SQL_NEED_DATA: Result:='SQL_NEED_DATA';
|
||||||
|
SQL_STILL_EXECUTING: Result:='SQL_STILL_EXECUTING';
|
||||||
|
else
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure ODBCCheckResult(HandleType:SQLSMALLINT; AHandle: SQLHANDLE; ErrorMsg: string);
|
procedure ODBCCheckResult(HandleType:SQLSMALLINT; AHandle: SQLHANDLE; ErrorMsg: string);
|
||||||
|
|
||||||
// check return value from SQLGetDiagField/Rec function itself
|
// check return value from SQLGetDiagField/Rec function itself
|
||||||
@ -163,7 +177,7 @@ var
|
|||||||
RecNumber:SQLSMALLINT;
|
RecNumber:SQLSMALLINT;
|
||||||
begin
|
begin
|
||||||
// check result
|
// check result
|
||||||
Res:=SQLGetDiagField(HandleType,AHandle,0,SQL_DIAG_RETURNCODE,@LastReturnCode,0,TextLength);
|
Res:=SQLGetDiagField(HandleType,AHandle,0,SQL_DIAG_RETURNCODE,@LastReturnCode,SQL_IS_SMALLINT,TextLength);
|
||||||
CheckSQLGetDiagResult(Res);
|
CheckSQLGetDiagResult(Res);
|
||||||
if ODBCSucces(LastReturnCode) then
|
if ODBCSucces(LastReturnCode) then
|
||||||
Exit; // no error; all is ok
|
Exit; // no error; all is ok
|
||||||
@ -352,7 +366,7 @@ begin
|
|||||||
ConnectionString:=CreateConnectionString;
|
ConnectionString:=CreateConnectionString;
|
||||||
SetLength(OutConnectionString,BufferLength-1); // allocate completed connection string buffer (using the ansistring #0 trick)
|
SetLength(OutConnectionString,BufferLength-1); // allocate completed connection string buffer (using the ansistring #0 trick)
|
||||||
SQLDriverConnect(FDBCHandle, // the ODBC connection handle
|
SQLDriverConnect(FDBCHandle, // the ODBC connection handle
|
||||||
0, // no parent window (would be required for prompts)
|
nil, // no parent window (would be required for prompts)
|
||||||
PChar(ConnectionString), // the connection string
|
PChar(ConnectionString), // the connection string
|
||||||
Length(ConnectionString), // connection string length
|
Length(ConnectionString), // connection string length
|
||||||
@(OutConnectionString[1]),// buffer for storing the completed connection string
|
@(OutConnectionString[1]),// buffer for storing the completed connection string
|
||||||
@ -386,6 +400,10 @@ end;
|
|||||||
|
|
||||||
procedure TODBCConnection.DeAllocateCursorHandle(var cursor: TSQLCursor);
|
procedure TODBCConnection.DeAllocateCursorHandle(var cursor: TSQLCursor);
|
||||||
begin
|
begin
|
||||||
|
// make sure we don't deallocate the cursor if the connection was lost already
|
||||||
|
if not Connected then
|
||||||
|
(cursor as TODBCCursor).FSTMTHandle:=SQL_INVALID_HANDLE;
|
||||||
|
|
||||||
FreeAndNil(cursor); // the destructor of TODBCCursor frees the ODBC Statement handle
|
FreeAndNil(cursor); // the destructor of TODBCCursor frees the ODBC Statement handle
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -598,7 +616,6 @@ end;
|
|||||||
procedure TODBCConnection.Execute(cursor: TSQLCursor; ATransaction: TSQLTransaction; AParams: TParams);
|
procedure TODBCConnection.Execute(cursor: TSQLCursor; ATransaction: TSQLTransaction; AParams: TParams);
|
||||||
var
|
var
|
||||||
ODBCCursor:TODBCCursor;
|
ODBCCursor:TODBCCursor;
|
||||||
Res:SQLRETURN;
|
|
||||||
begin
|
begin
|
||||||
ODBCCursor:=cursor as TODBCCursor;
|
ODBCCursor:=cursor as TODBCCursor;
|
||||||
|
|
||||||
@ -606,7 +623,7 @@ begin
|
|||||||
SetParameters(ODBCCursor, AParams);
|
SetParameters(ODBCCursor, AParams);
|
||||||
|
|
||||||
// execute the statement
|
// execute the statement
|
||||||
Res:=SQLExecute(ODBCCursor.FSTMTHandle);
|
SQLExecute(ODBCCursor.FSTMTHandle);
|
||||||
ODBCCheckResult(SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.');
|
ODBCCheckResult(SQL_HANDLE_STMT, ODBCCursor.FSTMTHandle, 'Could not execute statement.');
|
||||||
|
|
||||||
// free parameter buffers
|
// free parameter buffers
|
||||||
@ -858,9 +875,12 @@ destructor TODBCCursor.Destroy;
|
|||||||
begin
|
begin
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
|
|
||||||
// deallocate statement handle
|
if FSTMTHandle<>SQL_INVALID_HANDLE then
|
||||||
if SQLFreeHandle(SQL_HANDLE_STMT, FSTMTHandle)=SQL_ERROR then
|
begin
|
||||||
ODBCCheckResult(SQL_HANDLE_STMT, FSTMTHandle, 'Could not free ODBC Statement handle.');
|
// deallocate statement handle
|
||||||
|
if SQLFreeHandle(SQL_HANDLE_STMT, FSTMTHandle)=SQL_ERROR then
|
||||||
|
ODBCCheckResult(SQL_HANDLE_STMT, FSTMTHandle, 'Could not free ODBC Statement handle.');
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ finalization }
|
{ finalization }
|
||||||
|
@ -44,6 +44,7 @@ type
|
|||||||
SQLREAL = real;
|
SQLREAL = real;
|
||||||
SQLDOUBLE = Double;
|
SQLDOUBLE = Double;
|
||||||
SQLFLOAT = Double;
|
SQLFLOAT = Double;
|
||||||
|
SQLHWND = pointer;
|
||||||
PSQLCHAR = PChar;
|
PSQLCHAR = PChar;
|
||||||
PSQLINTEGER = ^SQLINTEGER;
|
PSQLINTEGER = ^SQLINTEGER;
|
||||||
PSQLUINTEGER = ^SQLUINTEGER;
|
PSQLUINTEGER = ^SQLUINTEGER;
|
||||||
@ -999,10 +1000,10 @@ type TSQLConnect=function (ConnectionHandle:SQLHDBC;
|
|||||||
type TSQLDisconnect=function(ConnectionHandle:SQLHDBC):SQLRETURN;stdcall;
|
type TSQLDisconnect=function(ConnectionHandle:SQLHDBC):SQLRETURN;stdcall;
|
||||||
|
|
||||||
type TSQLDriverConnect=function (hdbc: SQLHDBC;
|
type TSQLDriverConnect=function (hdbc: SQLHDBC;
|
||||||
hwnd: Integer;szCsin: PChar;
|
hwnd: SQLHWND;szCsin: PChar;
|
||||||
szCLen: SQLSMALLINT;szCsout: PChar;
|
szCLen: SQLSMALLINT;szCsout: PChar;
|
||||||
cbCSMax: SQLSMALLINT;Var cbCsOut: SQLSMALLINT;
|
cbCSMax: SQLSMALLINT;Var cbCsOut: SQLSMALLINT;
|
||||||
f: Integer):SQLRETURN;stdcall;
|
f: SQLUSMALLINT):SQLRETURN;stdcall;
|
||||||
|
|
||||||
type TSQLExecDirect=function (StatementHandle:SQLHSTMT;
|
type TSQLExecDirect=function (StatementHandle:SQLHSTMT;
|
||||||
StatementText:PSQLCHAR;TextLength:SQLINTEGER):SQLRETURN;stdcall;
|
StatementText:PSQLCHAR;TextLength:SQLINTEGER):SQLRETURN;stdcall;
|
||||||
@ -1239,13 +1240,13 @@ Const
|
|||||||
ConnectionHandle:SQLHDBC):SQLRETURN;{$ifdef win32}stdcall{$else}cdecl{$endif};external LibName;
|
ConnectionHandle:SQLHDBC):SQLRETURN;{$ifdef win32}stdcall{$else}cdecl{$endif};external LibName;
|
||||||
function SQLDriverConnect(
|
function SQLDriverConnect(
|
||||||
hdbc: SQLHDBC;
|
hdbc: SQLHDBC;
|
||||||
hwnd: Integer;
|
hwnd: SQLHWND;
|
||||||
szCsin: PChar;
|
szCsin: PChar;
|
||||||
szCLen: SQLSMALLINT;
|
szCLen: SQLSMALLINT;
|
||||||
szCsout: PChar;
|
szCsout: PChar;
|
||||||
cbCSMax: SQLSMALLINT;
|
cbCSMax: SQLSMALLINT;
|
||||||
Var cbCsOut: SQLSMALLINT;
|
Var cbCsOut: SQLSMALLINT;
|
||||||
f: Integer):SQLRETURN;{$ifdef win32}stdcall{$else}cdecl{$endif};external LibName;
|
f: SQLUSMALLINT):SQLRETURN;{$ifdef win32}stdcall{$else}cdecl{$endif};external LibName;
|
||||||
function SQLBrowseConnect(
|
function SQLBrowseConnect(
|
||||||
hdbc : SQLHDBC;
|
hdbc : SQLHDBC;
|
||||||
szConnStrIn :PSQLCHAR;
|
szConnStrIn :PSQLCHAR;
|
||||||
|
Loading…
Reference in New Issue
Block a user