fcl-db: ODBC: add NativeError and SQLState fields to EODBCException. Bug #23798

git-svn-id: trunk@26685 -
This commit is contained in:
lacak 2014-02-06 13:20:29 +00:00
parent c184669206
commit 56f37cd0e0

View File

@ -134,7 +134,8 @@ type
end; end;
EODBCException = class(EDatabaseError) EODBCException = class(EDatabaseError)
// currently empty; perhaps we can add fields here later that describe the error instead of one simple message string NativeError: integer;
SQLState: string;
end; end;
{$IF (FPC_VERSION>=2) AND (FPC_RELEASE>=1)} {$IF (FPC_VERSION>=2) AND (FPC_RELEASE>=1)}
@ -199,6 +200,7 @@ var
Res:SQLRETURN; Res:SQLRETURN;
SqlState,MessageText,TotalMessage:string; SqlState,MessageText,TotalMessage:string;
RecNumber:SQLSMALLINT; RecNumber:SQLSMALLINT;
Error: EODBCException;
begin begin
// check result // check result
if ODBCSucces(LastReturnCode) then if ODBCSucces(LastReturnCode) then
@ -209,6 +211,7 @@ begin
// build TotalMessage for exception to throw // build TotalMessage for exception to throw
TotalMessage:=Format(ErrorMsg,FmtArgs)+Format(' ODBC error details: LastReturnCode: %s;',[ODBCResultToStr(LastReturnCode)]); TotalMessage:=Format(ErrorMsg,FmtArgs)+Format(' ODBC error details: LastReturnCode: %s;',[ODBCResultToStr(LastReturnCode)]);
// retrieve status records // retrieve status records
NativeError:=0;
SetLength(SqlState,5); // SqlState buffer SetLength(SqlState,5); // SqlState buffer
SetLength(MessageText,1); SetLength(MessageText,1);
RecNumber:=1; RecNumber:=1;
@ -238,7 +241,10 @@ begin
end end
end; end;
// raise error // raise error
raise EODBCException.Create(TotalMessage); Error := EODBCException.Create(TotalMessage);
Error.NativeError := NativeError;
Error.SQLState := SqlState;
raise Error;
end; end;
procedure ODBCCheckResult(LastReturnCode:SQLRETURN; HandleType:SQLSMALLINT; AHandle: SQLHANDLE; ErrorMsg: string); procedure ODBCCheckResult(LastReturnCode:SQLRETURN; HandleType:SQLSMALLINT; AHandle: SQLHANDLE; ErrorMsg: string);