diff options
author | jonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2015-01-21 23:28:34 +0000 |
---|---|---|
committer | jonas <jonas@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2015-01-21 23:28:34 +0000 |
commit | 1903b037de2fb3e75826406b46f055acb70963fa (patch) | |
tree | 604cd8b790fe14e5fbe441d4cd647c80d2a36a9a /packages/fcl-db/src/sqldb/postgres | |
parent | ad1141d52f8353457053b925cd674fe1d5c4eafc (diff) | |
parent | 953d907e4d6c3a5c2f8aaee6e5e4f73c55ce5985 (diff) | |
download | fpc-blocks.tar.gz |
* synchronised with trunk till r29513blocks
git-svn-id: http://svn.freepascal.org/svn/fpc/branches/blocks@29516 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-db/src/sqldb/postgres')
-rw-r--r-- | packages/fcl-db/src/sqldb/postgres/Makefile | 94 | ||||
-rw-r--r-- | packages/fcl-db/src/sqldb/postgres/fpmake.inc | 2 | ||||
-rw-r--r-- | packages/fcl-db/src/sqldb/postgres/pqconnection.pp | 205 |
3 files changed, 208 insertions, 93 deletions
diff --git a/packages/fcl-db/src/sqldb/postgres/Makefile b/packages/fcl-db/src/sqldb/postgres/Makefile index c83b09797d..91dfe0fe73 100644 --- a/packages/fcl-db/src/sqldb/postgres/Makefile +++ b/packages/fcl-db/src/sqldb/postgres/Makefile @@ -1,9 +1,9 @@ # -# Don't edit, this file is generated by FPCMake Version 2.0.0 [2014-02-06 rev 26692] +# Don't edit, this file is generated by FPCMake Version 2.0.0 [2014-12-07 rev 29213] # default: all -MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-android jvm-java jvm-android i8086-msdos -BSDs = freebsd netbsd openbsd darwin +MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-haiku i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince i386-embedded i386-symbian i386-nativent i386-iphonesim i386-android i386-aros m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos m68k-embedded powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos powerpc-embedded powerpc-wii powerpc-aix sparc-linux sparc-netbsd sparc-solaris sparc-embedded x86_64-linux x86_64-freebsd x86_64-netbsd x86_64-solaris x86_64-openbsd x86_64-darwin x86_64-win64 x86_64-embedded x86_64-dragonfly arm-linux arm-palmos arm-darwin arm-wince arm-gba arm-nds arm-embedded arm-symbian arm-android powerpc64-linux powerpc64-darwin powerpc64-embedded powerpc64-aix avr-embedded armeb-linux armeb-embedded mips-linux mipsel-linux mipsel-embedded mipsel-android jvm-java jvm-android i8086-msdos +BSDs = freebsd netbsd openbsd darwin dragonfly UNIXs = linux $(BSDs) solaris qnx haiku aix LIMIT83fs = go32v2 os2 emx watcom msdos OSNeedsComspecToRunBatch = go32v2 watcom @@ -184,6 +184,12 @@ $(error When compiling for arm-embedded, a sub-architecture (e.g. SUBARCH=armv4t endif override FPCOPT+=-Cp$(SUBARCH) endif +ifeq ($(FULL_TARGET),mipsel-embedded) +ifeq ($(SUBARCH),) +$(error When compiling for mipsel-embedded, a sub-architecture (e.g. SUBARCH=pic32mx) must be defined) +endif +override FPCOPT+=-Cp$(SUBARCH) +endif ifneq ($(findstring $(OS_SOURCE),$(LIMIT83fs)),) TARGETSUFFIX=$(OS_TARGET) SOURCESUFFIX=$(OS_SOURCE) @@ -390,6 +396,9 @@ endif ifeq ($(FULL_TARGET),i386-android) override TARGET_UNITS+=pqconnection pqeventmonitor endif +ifeq ($(FULL_TARGET),i386-aros) +override TARGET_UNITS+=pqconnection pqeventmonitor +endif ifeq ($(FULL_TARGET),m68k-linux) override TARGET_UNITS+=pqconnection pqeventmonitor endif @@ -477,6 +486,9 @@ endif ifeq ($(FULL_TARGET),x86_64-embedded) override TARGET_UNITS+=pqconnection pqeventmonitor endif +ifeq ($(FULL_TARGET),x86_64-dragonfly) +override TARGET_UNITS+=pqconnection pqeventmonitor +endif ifeq ($(FULL_TARGET),arm-linux) override TARGET_UNITS+=pqconnection pqeventmonitor endif @@ -531,6 +543,9 @@ endif ifeq ($(FULL_TARGET),mipsel-linux) override TARGET_UNITS+=pqconnection pqeventmonitor endif +ifeq ($(FULL_TARGET),mipsel-embedded) +override TARGET_UNITS+=pqconnection pqeventmonitor +endif ifeq ($(FULL_TARGET),mipsel-android) override TARGET_UNITS+=pqconnection pqeventmonitor endif @@ -612,6 +627,9 @@ endif ifeq ($(FULL_TARGET),i386-android) override TARGET_RSTS+=pqconnection endif +ifeq ($(FULL_TARGET),i386-aros) +override TARGET_RSTS+=pqconnection +endif ifeq ($(FULL_TARGET),m68k-linux) override TARGET_RSTS+=pqconnection endif @@ -699,6 +717,9 @@ endif ifeq ($(FULL_TARGET),x86_64-embedded) override TARGET_RSTS+=pqconnection endif +ifeq ($(FULL_TARGET),x86_64-dragonfly) +override TARGET_RSTS+=pqconnection +endif ifeq ($(FULL_TARGET),arm-linux) override TARGET_RSTS+=pqconnection endif @@ -753,6 +774,9 @@ endif ifeq ($(FULL_TARGET),mipsel-linux) override TARGET_RSTS+=pqconnection endif +ifeq ($(FULL_TARGET),mipsel-embedded) +override TARGET_RSTS+=pqconnection +endif ifeq ($(FULL_TARGET),mipsel-android) override TARGET_RSTS+=pqconnection endif @@ -835,6 +859,9 @@ endif ifeq ($(FULL_TARGET),i386-android) override COMPILER_OPTIONS+=-S2 endif +ifeq ($(FULL_TARGET),i386-aros) +override COMPILER_OPTIONS+=-S2 +endif ifeq ($(FULL_TARGET),m68k-linux) override COMPILER_OPTIONS+=-S2 endif @@ -922,6 +949,9 @@ endif ifeq ($(FULL_TARGET),x86_64-embedded) override COMPILER_OPTIONS+=-S2 endif +ifeq ($(FULL_TARGET),x86_64-dragonfly) +override COMPILER_OPTIONS+=-S2 +endif ifeq ($(FULL_TARGET),arm-linux) override COMPILER_OPTIONS+=-S2 endif @@ -976,6 +1006,9 @@ endif ifeq ($(FULL_TARGET),mipsel-linux) override COMPILER_OPTIONS+=-S2 endif +ifeq ($(FULL_TARGET),mipsel-embedded) +override COMPILER_OPTIONS+=-S2 +endif ifeq ($(FULL_TARGET),mipsel-android) override COMPILER_OPTIONS+=-S2 endif @@ -1230,6 +1263,12 @@ EXEEXT= HASSHAREDLIB=1 SHORTSUFFIX=lnx endif +ifeq ($(OS_TARGET),dragonfly) +BATCHEXT=.sh +EXEEXT= +HASSHAREDLIB=1 +SHORTSUFFIX=df +endif ifeq ($(OS_TARGET),freebsd) BATCHEXT=.sh EXEEXT= @@ -1275,6 +1314,11 @@ EXEEXT= SHAREDLIBEXT=.library SHORTSUFFIX=amg endif +ifeq ($(OS_TARGET),aros) +EXEEXT= +SHAREDLIBEXT=.library +SHORTSUFFIX=aros +endif ifeq ($(OS_TARGET),morphos) EXEEXT= SHAREDLIBEXT=.library @@ -1857,6 +1901,16 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif +ifeq ($(FULL_TARGET),i386-aros) +REQUIRE_PACKAGES_RTL=1 +REQUIRE_PACKAGES_PASZLIB=1 +REQUIRE_PACKAGES_FCL-PROCESS=1 +REQUIRE_PACKAGES_HASH=1 +REQUIRE_PACKAGES_LIBTAR=1 +REQUIRE_PACKAGES_FPMKUNIT=1 +REQUIRE_PACKAGES_FCL-XML=1 +REQUIRE_PACKAGES_POSTGRES=1 +endif ifeq ($(FULL_TARGET),m68k-linux) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -2147,6 +2201,16 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif +ifeq ($(FULL_TARGET),x86_64-dragonfly) +REQUIRE_PACKAGES_RTL=1 +REQUIRE_PACKAGES_PASZLIB=1 +REQUIRE_PACKAGES_FCL-PROCESS=1 +REQUIRE_PACKAGES_HASH=1 +REQUIRE_PACKAGES_LIBTAR=1 +REQUIRE_PACKAGES_FPMKUNIT=1 +REQUIRE_PACKAGES_FCL-XML=1 +REQUIRE_PACKAGES_POSTGRES=1 +endif ifeq ($(FULL_TARGET),arm-linux) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -2327,6 +2391,16 @@ REQUIRE_PACKAGES_FPMKUNIT=1 REQUIRE_PACKAGES_FCL-XML=1 REQUIRE_PACKAGES_POSTGRES=1 endif +ifeq ($(FULL_TARGET),mipsel-embedded) +REQUIRE_PACKAGES_RTL=1 +REQUIRE_PACKAGES_PASZLIB=1 +REQUIRE_PACKAGES_FCL-PROCESS=1 +REQUIRE_PACKAGES_HASH=1 +REQUIRE_PACKAGES_LIBTAR=1 +REQUIRE_PACKAGES_FPMKUNIT=1 +REQUIRE_PACKAGES_FCL-XML=1 +REQUIRE_PACKAGES_POSTGRES=1 +endif ifeq ($(FULL_TARGET),mipsel-android) REQUIRE_PACKAGES_RTL=1 REQUIRE_PACKAGES_PASZLIB=1 @@ -2784,7 +2858,7 @@ endif ifdef CREATESHARED override FPCOPT+=-Cg endif -ifneq ($(findstring $(OS_TARGET),freebsd openbsd netbsd linux solaris),) +ifneq ($(findstring $(OS_TARGET),dragonfly freebsd openbsd netbsd linux solaris),) ifeq ($(CPU_TARGET),x86_64) override FPCOPT+=-Cg endif @@ -2814,17 +2888,23 @@ ifdef ACROSSCOMPILE override FPCOPT+=$(CROSSOPT) endif override COMPILER:=$(strip $(FPC) $(FPCOPT)) -ifeq (,$(findstring -s ,$(COMPILER))) +ifneq (,$(findstring -sh ,$(COMPILER))) +UseEXECPPAS=1 +endif +ifneq (,$(findstring -s ,$(COMPILER))) +ifeq ($(FULL_SOURCE),$(FULL_TARGET)) +UseEXECPPAS=1 +endif +endif +ifneq ($(UseEXECPPAS),1) EXECPPAS= else -ifeq ($(FULL_SOURCE),$(FULL_TARGET)) ifdef RUNBATCH EXECPPAS:=@$(RUNBATCH) $(PPAS) else EXECPPAS:=@$(PPAS) endif endif -endif .PHONY: fpc_units ifneq ($(TARGET_UNITS)$(TARGET_IMPLICITUNITS),) override ALLTARGET+=fpc_units diff --git a/packages/fcl-db/src/sqldb/postgres/fpmake.inc b/packages/fcl-db/src/sqldb/postgres/fpmake.inc index d9c7a0a135..92f4d2e876 100644 --- a/packages/fcl-db/src/sqldb/postgres/fpmake.inc +++ b/packages/fcl-db/src/sqldb/postgres/fpmake.inc @@ -6,7 +6,7 @@ Targets.ResetDefaults; Targets.DefaultDir:='db/sqldb/postgres'; { Drivers only for the following OSes } -Targets.DefaultOS:=[win32,openbsd,netbsd,freebsd,darwin,linux,haiku]; +Targets.DefaultOS:=[win32,openbsd,netbsd,freebsd,darwin,linux,haiku,dragonfly]; T:=Targets.AddUnit('pqconnection'); T.ResourceStrings:=True; T:=Targets.AddUnit('pqeventmonitor'); diff --git a/packages/fcl-db/src/sqldb/postgres/pqconnection.pp b/packages/fcl-db/src/sqldb/postgres/pqconnection.pp index 48c24e8b58..bcf43828a1 100644 --- a/packages/fcl-db/src/sqldb/postgres/pqconnection.pp +++ b/packages/fcl-db/src/sqldb/postgres/pqconnection.pp @@ -21,10 +21,10 @@ type TPQTrans = Class(TSQLHandle) protected - PGConn : PPGConn; - FList : TThreadList; - Procedure RegisterCursor(S : TPQCursor); - Procedure UnRegisterCursor(S : TPQCursor); + PGConn : PPGConn; + FList : TThreadList; + Procedure RegisterCursor(Cursor : TPQCursor); + Procedure UnRegisterCursor(Cursor : TPQCursor); Public Constructor Create; Destructor Destroy; override; @@ -60,6 +60,8 @@ type Destructor Destroy; override; end; + { EPQDatabaseError } + EPQDatabaseError = class(EDatabaseError) public SEVERITY:string; @@ -70,6 +72,8 @@ type STATEMENT_POSITION:string; end; + { TPQTranConnection } + TPQTranConnection = class protected FPGConn : PPGConn; @@ -116,6 +120,7 @@ type function RollBack(trans : TSQLHandle) : boolean; override; function Commit(trans : TSQLHandle) : boolean; override; procedure CommitRetaining(trans : TSQLHandle); override; + function StartImplicitTransaction(trans : TSQLHandle; AParams : string) : boolean; override; function StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; override; procedure RollBackRetaining(trans : TSQLHandle); override; procedure UpdateIndexDefs(IndexDefs : TIndexDefs;TableName : string); override; @@ -124,7 +129,7 @@ type function RowsAffected(cursor: TSQLCursor): TRowsCount; override; public constructor Create(AOwner : TComponent); override; - destructor destroy; override; + destructor Destroy; override; function GetConnectionInfo(InfoType:TConnInfoType): string; override; procedure CreateDB; override; procedure DropDB; override; @@ -188,23 +193,12 @@ const Oid_Bool = 16; oid_numeric = 1700; Oid_uuid = 2950; -{ TPQTrans } -procedure TPQTrans.RegisterCursor(S: TPQCursor); -begin - FList.Add(S); - S.tr:=Self; -end; - -procedure TPQTrans.UnRegisterCursor(S: TPQCursor); -begin - S.tr:=Nil; - FList.Remove(S); -end; +{ TPQTrans } constructor TPQTrans.Create; begin - Flist:=TThreadList.Create; + FList:=TThreadList.Create; FList.Duplicates:=dupIgnore; end; @@ -215,19 +209,39 @@ Var I : integer; begin - L:=Flist.LockList; + L:=FList.LockList; try For I:=0 to L.Count-1 do TPQCursor(L[i]).tr:=Nil; finally - Flist.UnlockList; + FList.UnlockList; end; FreeAndNil(FList); inherited Destroy; end; +procedure TPQTrans.RegisterCursor(Cursor: TPQCursor); +begin + FList.Add(Cursor); + Cursor.tr:=Self; +end; + +procedure TPQTrans.UnRegisterCursor(Cursor: TPQCursor); +begin + Cursor.tr:=Nil; + FList.Remove(Cursor); +end; + + { TPQCursor } +destructor TPQCursor.Destroy; +begin + if Assigned(tr) then + tr.UnRegisterCursor(Self); + inherited Destroy; +end; + function TPQCursor.GetFieldBinding(F: TFieldDef): PFieldBinding; Var @@ -251,25 +265,20 @@ begin end; end; -destructor TPQCursor.Destroy; -begin - if Assigned(tr) then - Tr.UnRegisterCursor(Self); - inherited Destroy; -end; +{ TPQConnection } constructor TPQConnection.Create(AOwner : TComponent); begin inherited; - FConnOptions := FConnOptions + [sqSupportParams, sqSupportEmptyDatabaseName, sqEscapeRepeat, sqEscapeSlash]; + FConnOptions := FConnOptions + [sqSupportParams, sqSupportEmptyDatabaseName, sqEscapeRepeat, sqEscapeSlash, sqImplicitTransaction]; FieldNameQuoteChars:=DoubleQuotes; VerboseErrors:=True; FConnectionPool:=TThreadlist.Create; end; -destructor TPQConnection.destroy; +destructor TPQConnection.Destroy; begin // We must disconnect here. If it is done in inherited, then connection pool is gone. Connected:=False; @@ -322,7 +331,8 @@ begin {$EndIf} end; -procedure TPQConnection.GetExtendedFieldInfo(cursor: TPQCursor; Bindings: TFieldBindings); +Procedure TPQConnection.GetExtendedFieldInfo(cursor: TPQCursor; + Bindings: TFieldBindings); Var tt,tc,Tn,S : String; @@ -376,7 +386,7 @@ begin P.SQLDBData:=TPQCursor(C).GetFieldBinding(F.FieldDef); end; -function TPQConnection.ErrorOnUnknownType: Boolean; +Function TPQConnection.ErrorOnUnknownType: Boolean; begin Result:=False; end; @@ -430,6 +440,7 @@ var begin result := false; tr := trans as TPQTrans; + // unprepare statements associated with given transaction L:=tr.FList.LockList; try For I:=0 to L.Count-1 do @@ -439,8 +450,9 @@ begin end; L.Clear; finally - tr.flist.UnlockList; + tr.FList.UnlockList; end; + res := PQexec(tr.PGConn, 'ROLLBACK'); CheckResultError(res,tr.PGConn,SErrRollbackFailed); PQclear(res); @@ -463,23 +475,50 @@ begin result := true; end; -function TPQConnection.StartdbTransaction(trans : TSQLHandle; AParams : string) : boolean; +procedure TPQConnection.RollBackRetaining(trans : TSQLHandle); +var + res : PPGresult; + tr : TPQTrans; +begin + tr := trans as TPQTrans; + res := PQexec(tr.PGConn, 'ROLLBACK'); + CheckResultError(res,tr.PGConn,SErrRollbackFailed); + + PQclear(res); + res := PQexec(tr.PGConn, 'BEGIN'); + CheckResultError(res,tr.PGConn,sErrTransactionFailed); + + PQclear(res); +end; + +procedure TPQConnection.CommitRetaining(trans : TSQLHandle); var res : PPGresult; tr : TPQTrans; - i : Integer; - t : TPQTranConnection; - L : TList; begin - result:=false; tr := trans as TPQTrans; + res := PQexec(tr.PGConn, 'COMMIT'); + CheckResultError(res,tr.PGConn,SErrCommitFailed); + + PQclear(res); + res := PQexec(tr.PGConn, 'BEGIN'); + CheckResultError(res,tr.PGConn,sErrTransactionFailed); + PQclear(res); +end; + +function TPQConnection.StartImplicitTransaction(trans : TSQLHandle; AParams : string) : boolean; +var + i : Integer; + T : TPQTranConnection; + L : TList; +begin //find an unused connection in the pool i:=0; - t:=Nil; + T:=Nil; L:=FConnectionPool.LockList; try - while (I<L.Count) do + while (i<L.Count) do begin T:=TPQTranConnection(L[i]); if (T.FPGConn=nil) or not T.FTranActive then @@ -495,60 +534,42 @@ begin finally FConnectionPool.UnLockList; end; + if (T=Nil) then begin T:=TPQTranConnection.Create; T.FTranActive:=True; AddConnection(T); end; - if (T.FPGConn<>nil) then - tr.PGConn:=T.FPGConn - else + + if (T.FPGConn=nil) then begin - tr.PGConn := PQconnectdb(pchar(FConnectString)); - T.FPGConn:=tr.PGConn; - CheckConnectionStatus(tr.PGConn); + T.FPGConn := PQconnectdb(pchar(FConnectString)); + CheckConnectionStatus(T.FPGConn); if CharSet <> '' then - PQsetClientEncoding(tr.PGConn, pchar(CharSet)); + PQsetClientEncoding(T.FPGConn, pchar(CharSet)); end; - res := PQexec(tr.PGConn, 'BEGIN'); - CheckResultError(res,tr.PGConn,sErrTransactionFailed); - - PQclear(res); - result := true; + TPQTrans(trans).PGConn := T.FPGConn; + Result := true; end; -procedure TPQConnection.RollBackRetaining(trans : TSQLHandle); -var - res : PPGresult; - tr : TPQTrans; -begin - tr := trans as TPQTrans; - res := PQexec(tr.PGConn, 'ROLLBACK'); - CheckResultError(res,tr.PGConn,SErrRollbackFailed); - - PQclear(res); - res := PQexec(tr.PGConn, 'BEGIN'); - CheckResultError(res,tr.PGConn,sErrTransactionFailed); - - PQclear(res); -end; +function TPQConnection.StartDBTransaction(trans: TSQLHandle; + AParams: string): boolean; -procedure TPQConnection.CommitRetaining(trans : TSQLHandle); -var +Var res : PPGresult; tr : TPQTrans; -begin - tr := trans as TPQTrans; - res := PQexec(tr.PGConn, 'COMMIT'); - CheckResultError(res,tr.PGConn,SErrCommitFailed); - - PQclear(res); - res := PQexec(tr.PGConn, 'BEGIN'); - CheckResultError(res,tr.PGConn,sErrTransactionFailed); - PQclear(res); +begin + Result:=StartImplicitTransaction(trans, AParams); + if Result then + begin + tr := trans as TPQTrans; + res := PQexec(tr.PGConn, 'BEGIN'); + CheckResultError(res,tr.PGConn,sErrTransactionFailed); + PQclear(res); + end; end; @@ -648,9 +669,21 @@ var MESSAGE_DETAIL: string; MESSAGE_HINT: string; STATEMENT_POSITION: string; + P : Pchar; + haveError : Boolean; + begin - if (PQresultStatus(res) <> PGRES_COMMAND_OK) then + HaveError:=False; + if (Res=Nil) then + begin + HaveError:=True; + P:=PQerrorMessage(conn); + If Assigned(p) then + ErrMsg:=StrPas(P); + end + else if (PQresultStatus(res) <> PGRES_COMMAND_OK) then begin + HaveError:=True; SEVERITY:=PQresultErrorField(res,ord('S')); SQLSTATE:=PQresultErrorField(res,ord('C')); MESSAGE_PRIMARY:=PQresultErrorField(res,ord('M')); @@ -667,6 +700,9 @@ begin MaybeAdd(sErr,'Hint',MESSAGE_HINT); MaybeAdd(sErr,'Character',STATEMENT_POSITION); end; + end; + if HaveError then + begin if (Self.Name='') then CompName := Self.ClassName else CompName := Self.Name; E:=EPQDatabaseError.CreateFmt('%s : %s (PostgreSQL: %s)', [CompName, ErrMsg, sErr]); E.SEVERITY:=SEVERITY; @@ -675,7 +711,6 @@ begin E.MESSAGE_DETAIL:=MESSAGE_DETAIL; E.MESSAGE_HINT:=MESSAGE_HINT; E.STATEMENT_POSITION:=STATEMENT_POSITION; - PQclear(res); res:=nil; if assigned(conn) then @@ -688,7 +723,7 @@ begin end; function TPQConnection.TranslateFldType(res: PPGresult; Tuple: integer; out - Size: integer; out ATypeOID: oid): TFieldType; + Size: integer; Out ATypeOID: oid): TFieldType; const VARHDRSZ=sizeof(longint); @@ -769,18 +804,18 @@ begin end; end; -function TPQConnection.AllocateCursorHandle: TSQLCursor; +Function TPQConnection.AllocateCursorHandle: TSQLCursor; begin result := TPQCursor.create; end; -procedure TPQConnection.DeAllocateCursorHandle(var cursor: TSQLCursor); +Procedure TPQConnection.DeAllocateCursorHandle(var cursor: TSQLCursor); begin FreeAndNil(cursor); end; -function TPQConnection.AllocateTransactionHandle: TSQLHandle; +Function TPQConnection.AllocateTransactionHandle: TSQLHandle; begin result := TPQTrans.create; @@ -918,7 +953,7 @@ begin res:=nil; if FPrepared then begin - if PQtransactionStatus(tr.PGConn) <> PQTRANS_INERROR then + if assigned(tr) and (PQtransactionStatus(tr.PGConn) <> PQTRANS_INERROR) then begin res := PQexec(tr.PGConn,pchar('deallocate '+StmtName)); CheckResultError(res,nil,SErrUnPrepareFailed); @@ -1000,7 +1035,7 @@ begin end else begin - // Registercursor sets tr + // RegisterCursor sets tr TPQTrans(aTransaction.Handle).RegisterCursor(Cursor as TPQCursor); if Assigned(AParams) and (AParams.Count > 0) then @@ -1090,7 +1125,7 @@ begin end else if ErrorOnUnknownType then - DatabaseError('unhandled field type :'+FB^.TypeName,Self); + DatabaseError('Unhandled field type :'+FB^.TypeName,Self); end; end; end; |