mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-13 14:29:25 +02:00
-some filter fixes
- added ParseSQL property - added DeAllocateCursorHandle - fixed tibconnection string-parameters git-svn-id: trunk@620 -
This commit is contained in:
parent
6ed53e2c70
commit
62871eddeb
@ -67,6 +67,7 @@ type
|
|||||||
function GetHandle : pointer; override;
|
function GetHandle : pointer; override;
|
||||||
|
|
||||||
Function AllocateCursorHandle : TSQLCursor; override;
|
Function AllocateCursorHandle : TSQLCursor; override;
|
||||||
|
Procedure DeAllocateCursorHandle(var cursor : TSQLCursor); override;
|
||||||
Function AllocateTransactionHandle : TSQLHandle; override;
|
Function AllocateTransactionHandle : TSQLHandle; override;
|
||||||
|
|
||||||
procedure CloseStatement(cursor : TSQLCursor); override;
|
procedure CloseStatement(cursor : TSQLCursor); override;
|
||||||
@ -410,6 +411,17 @@ begin
|
|||||||
result := curs;
|
result := curs;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TIBConnection.DeAllocateCursorHandle(var cursor : TSQLCursor);
|
||||||
|
|
||||||
|
begin
|
||||||
|
if assigned(cursor) then with cursor as TIBCursor do
|
||||||
|
begin
|
||||||
|
reAllocMem(SQLDA,0);
|
||||||
|
reAllocMem(in_SQLDA,0);
|
||||||
|
end;
|
||||||
|
FreeAndNil(cursor);
|
||||||
|
end;
|
||||||
|
|
||||||
Function TIBConnection.AllocateTransactionHandle : TSQLHandle;
|
Function TIBConnection.AllocateTransactionHandle : TSQLHandle;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -424,8 +436,6 @@ begin
|
|||||||
CheckError('FreeStatement', Status);
|
CheckError('FreeStatement', Status);
|
||||||
Statement := nil;
|
Statement := nil;
|
||||||
end;
|
end;
|
||||||
// reAllocMem((cursor as tibcursor).SQLDA,0);
|
|
||||||
// ^=bug moet nog ergens anders komen...
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIBConnection.PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams);
|
procedure TIBConnection.PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams);
|
||||||
@ -585,6 +595,7 @@ var ParNr,SQLVarNr : integer;
|
|||||||
s : string;
|
s : string;
|
||||||
i : integer;
|
i : integer;
|
||||||
currbuff : pchar;
|
currbuff : pchar;
|
||||||
|
w : word;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$R-}
|
{$R-}
|
||||||
@ -607,7 +618,17 @@ begin
|
|||||||
begin
|
begin
|
||||||
{$R-}
|
{$R-}
|
||||||
s := AParams[ParNr].AsString;
|
s := AParams[ParNr].AsString;
|
||||||
Move(s[1], in_sqlda^.SQLvar[SQLVarNr].SQLData^, length(s));
|
w := length(s);
|
||||||
|
if ((in_sqlda^.SQLvar[SQLVarNr].SQLType and not 1) = SQL_VARYING) then
|
||||||
|
begin
|
||||||
|
in_sqlda^.SQLvar[SQLVarNr].SQLLen := w;
|
||||||
|
in_sqlda^.SQLvar[SQLVarNr].SQLData := AllocMem(in_SQLDA^.SQLVar[SQLVarNr].SQLLen+2)
|
||||||
|
end;
|
||||||
|
|
||||||
|
CurrBuff := in_sqlda^.SQLvar[SQLVarNr].SQLData;
|
||||||
|
move(w,CurrBuff^,sizeof(w));
|
||||||
|
inc(CurrBuff,2);
|
||||||
|
Move(s[1], CurrBuff^, length(s));
|
||||||
{$R+}
|
{$R+}
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
|
@ -51,6 +51,7 @@ Type
|
|||||||
function GetHandle : pointer; override;
|
function GetHandle : pointer; override;
|
||||||
|
|
||||||
Function AllocateCursorHandle : TSQLCursor; override;
|
Function AllocateCursorHandle : TSQLCursor; override;
|
||||||
|
Procedure DeAllocateCursorHandle(var cursor : TSQLCursor); override;
|
||||||
Function AllocateTransactionHandle : TSQLHandle; override;
|
Function AllocateTransactionHandle : TSQLHandle; override;
|
||||||
|
|
||||||
procedure CloseStatement(cursor : TSQLCursor); override;
|
procedure CloseStatement(cursor : TSQLCursor); override;
|
||||||
@ -206,6 +207,12 @@ begin
|
|||||||
Result:=TMySQLCursor.Create;
|
Result:=TMySQLCursor.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Procedure TMySQLConnection.DeAllocateCursorHandle(var cursor : TSQLCursor);
|
||||||
|
|
||||||
|
begin
|
||||||
|
FreeAndNil(cursor);
|
||||||
|
end;
|
||||||
|
|
||||||
function TMySQLConnection.AllocateTransactionHandle: TSQLHandle;
|
function TMySQLConnection.AllocateTransactionHandle: TSQLHandle;
|
||||||
begin
|
begin
|
||||||
Result:=TMySQLTransaction.Create;
|
Result:=TMySQLTransaction.Create;
|
||||||
|
@ -42,6 +42,7 @@ type
|
|||||||
function GetHandle : pointer; override;
|
function GetHandle : pointer; override;
|
||||||
|
|
||||||
Function AllocateCursorHandle : TSQLCursor; override;
|
Function AllocateCursorHandle : TSQLCursor; override;
|
||||||
|
Procedure DeAllocateCursorHandle(var cursor : TSQLCursor); override;
|
||||||
Function AllocateTransactionHandle : TSQLHandle; override;
|
Function AllocateTransactionHandle : TSQLHandle; override;
|
||||||
|
|
||||||
procedure CloseStatement(cursor : TSQLCursor); override;
|
procedure CloseStatement(cursor : TSQLCursor); override;
|
||||||
@ -319,6 +320,12 @@ begin
|
|||||||
result := TPQCursor.create;
|
result := TPQCursor.create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Procedure TPQConnection.DeAllocateCursorHandle(var cursor : TSQLCursor);
|
||||||
|
|
||||||
|
begin
|
||||||
|
FreeAndNil(cursor);
|
||||||
|
end;
|
||||||
|
|
||||||
Function TPQConnection.AllocateTransactionHandle : TSQLHandle;
|
Function TPQConnection.AllocateTransactionHandle : TSQLHandle;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -76,6 +76,7 @@ type
|
|||||||
function GetHandle : pointer; virtual; abstract;
|
function GetHandle : pointer; virtual; abstract;
|
||||||
|
|
||||||
Function AllocateCursorHandle : TSQLCursor; virtual; abstract;
|
Function AllocateCursorHandle : TSQLCursor; virtual; abstract;
|
||||||
|
Procedure DeAllocateCursorHandle(var cursor : TSQLCursor); virtual; abstract;
|
||||||
Function AllocateTransactionHandle : TSQLHandle; virtual; abstract;
|
Function AllocateTransactionHandle : TSQLHandle; virtual; abstract;
|
||||||
|
|
||||||
procedure PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams); virtual; abstract;
|
procedure PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams); virtual; abstract;
|
||||||
@ -163,6 +164,7 @@ type
|
|||||||
FFromPart : String;
|
FFromPart : String;
|
||||||
FWhereStartPos : integer;
|
FWhereStartPos : integer;
|
||||||
FWhereStopPos : integer;
|
FWhereStopPos : integer;
|
||||||
|
FParseSQL : boolean;
|
||||||
// FSchemaInfo : TSchemaInfo;
|
// FSchemaInfo : TSchemaInfo;
|
||||||
|
|
||||||
procedure CloseStatement;
|
procedure CloseStatement;
|
||||||
@ -172,12 +174,14 @@ type
|
|||||||
function GetStatementType : TStatementType;
|
function GetStatementType : TStatementType;
|
||||||
procedure SetIndexDefs(AValue : TIndexDefs);
|
procedure SetIndexDefs(AValue : TIndexDefs);
|
||||||
procedure SetReadOnly(AValue : Boolean);
|
procedure SetReadOnly(AValue : Boolean);
|
||||||
|
procedure SetParseSQL(AValue : Boolean);
|
||||||
procedure SetUsePrimaryKeyAsKey(AValue : Boolean);
|
procedure SetUsePrimaryKeyAsKey(AValue : Boolean);
|
||||||
procedure SetUpdateMode(AValue : TUpdateMode);
|
procedure SetUpdateMode(AValue : TUpdateMode);
|
||||||
procedure OnChangeSQL(Sender : TObject);
|
procedure OnChangeSQL(Sender : TObject);
|
||||||
|
|
||||||
procedure Execute;
|
procedure Execute;
|
||||||
Procedure ParseSQL(var SQL : string);
|
Procedure SQLParser(var SQL : string);
|
||||||
|
Function AddFilter(SQLstr : string) : string;
|
||||||
protected
|
protected
|
||||||
// abstract & virtual methods of TBufDataset
|
// abstract & virtual methods of TBufDataset
|
||||||
function Fetch : boolean; override;
|
function Fetch : boolean; override;
|
||||||
@ -194,10 +198,8 @@ type
|
|||||||
function GetCanModify: Boolean; override;
|
function GetCanModify: Boolean; override;
|
||||||
function ApplyRecUpdate(UpdateKind : TUpdateKind) : boolean; override;
|
function ApplyRecUpdate(UpdateKind : TUpdateKind) : boolean; override;
|
||||||
Function IsPrepared : Boolean; virtual;
|
Function IsPrepared : Boolean; virtual;
|
||||||
function GetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean): Boolean; overload; override;
|
|
||||||
procedure SetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean); overload; override;
|
procedure SetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean); overload; override;
|
||||||
procedure SetFiltered(Value: Boolean); override;
|
procedure SetFiltered(Value: Boolean); override;
|
||||||
procedure SetFilterText(const Value: string); override;
|
|
||||||
public
|
public
|
||||||
procedure Prepare; virtual;
|
procedure Prepare; virtual;
|
||||||
procedure UnPrepare; virtual;
|
procedure UnPrepare; virtual;
|
||||||
@ -246,6 +248,7 @@ type
|
|||||||
property UpdateMode : TUpdateMode read FUpdateMode write SetUpdateMode;
|
property UpdateMode : TUpdateMode read FUpdateMode write SetUpdateMode;
|
||||||
property UsePrimaryKeyAsKey : boolean read FUsePrimaryKeyAsKey write SetUsePrimaryKeyAsKey;
|
property UsePrimaryKeyAsKey : boolean read FUsePrimaryKeyAsKey write SetUsePrimaryKeyAsKey;
|
||||||
property StatementType : TStatementType read GetStatementType;
|
property StatementType : TStatementType read GetStatementType;
|
||||||
|
property ParseSQL : Boolean read FParseSQL write SetParseSQL;
|
||||||
// property SchemaInfo : TSchemaInfo read FSchemaInfo default stNoSchema;
|
// property SchemaInfo : TSchemaInfo read FSchemaInfo default stNoSchema;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -526,25 +529,22 @@ begin
|
|||||||
Result := Assigned(FCursor) and FCursor.FPrepared;
|
Result := Assigned(FCursor) and FCursor.FPrepared;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TSQLQuery.GetFieldData(Field: TField; Buffer: Pointer;
|
|
||||||
NativeFormat: Boolean): Boolean;
|
|
||||||
begin
|
|
||||||
Result:=GetFieldData(Field, Buffer);
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TSQLQuery.SetFieldData(Field: TField; Buffer: Pointer;
|
procedure TSQLQuery.SetFieldData(Field: TField; Buffer: Pointer;
|
||||||
NativeFormat: Boolean);
|
NativeFormat: Boolean);
|
||||||
begin
|
begin
|
||||||
SetFieldData(Field, Buffer);
|
SetFieldData(Field, Buffer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLQuery.SetFilterText(const Value: string);
|
Function TSQLQuery.AddFilter(SQLstr : string) : string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if Filtered then
|
if FWhereStartPos = 0 then
|
||||||
begin
|
SQLstr := SQLstr + ' where (' + Filter + ')'
|
||||||
end;
|
else if FWhereStopPos > 0 then
|
||||||
Inherited SetFilterText(Value);
|
system.insert(' and ('+Filter+') ',SQLstr,FWhereStopPos+1)
|
||||||
|
else
|
||||||
|
system.insert(' where ('+Filter+') ',SQLstr,FWhereStartPos);
|
||||||
|
Result := SQLstr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLQuery.SetFiltered(Value: Boolean);
|
procedure TSQLQuery.SetFiltered(Value: Boolean);
|
||||||
@ -552,6 +552,7 @@ procedure TSQLQuery.SetFiltered(Value: Boolean);
|
|||||||
var S : String;
|
var S : String;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
if Value and not FParseSQL then DatabaseErrorFmt(SNoParseSQL,['Filtering ']);
|
||||||
if (Filtered <> Value) and Active then
|
if (Filtered <> Value) and Active then
|
||||||
begin
|
begin
|
||||||
CloseStatement;
|
CloseStatement;
|
||||||
@ -560,25 +561,15 @@ begin
|
|||||||
|
|
||||||
s := FSQLBuf;
|
s := FSQLBuf;
|
||||||
|
|
||||||
if Value then
|
if Value then s := AddFilter(s);
|
||||||
begin
|
|
||||||
if FWhereStartPos = 0 then
|
|
||||||
s := s + ' where (' + Filter + ')'
|
|
||||||
else if FWhereStopPos > 0 then
|
|
||||||
system.insert(' and ('+Filter+') ',S,FWhereStopPos+1)
|
|
||||||
else
|
|
||||||
system.insert(' where ('+Filter+') ',S,FWhereStartPos);
|
|
||||||
end;
|
|
||||||
|
|
||||||
(Database as tsqlconnection).PrepareStatement(Fcursor,(transaction as tsqltransaction),S,FParams);
|
(Database as tsqlconnection).PrepareStatement(Fcursor,(transaction as tsqltransaction),S,FParams);
|
||||||
|
|
||||||
|
|
||||||
Execute;
|
Execute;
|
||||||
inherited InternalOpen;
|
inherited InternalOpen;
|
||||||
First;
|
First;
|
||||||
|
|
||||||
inherited SetFiltered(Value);
|
|
||||||
end;
|
end;
|
||||||
|
inherited setfiltered(Value);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLQuery.Prepare;
|
procedure TSQLQuery.Prepare;
|
||||||
@ -604,9 +595,12 @@ begin
|
|||||||
|
|
||||||
FSQLBuf := TrimRight(FSQL.Text);
|
FSQLBuf := TrimRight(FSQL.Text);
|
||||||
|
|
||||||
ParseSQL(FSQLBuf);
|
SQLParser(FSQLBuf);
|
||||||
|
|
||||||
Db.PrepareStatement(Fcursor,sqltr,FSQLBuf,FParams);
|
if filtered then
|
||||||
|
Db.PrepareStatement(Fcursor,sqltr,AddFilter(FSQLBuf),FParams)
|
||||||
|
else
|
||||||
|
Db.PrepareStatement(Fcursor,sqltr,FSQLBuf,FParams);
|
||||||
|
|
||||||
if (FCursor.FStatementType = stSelect) and not ReadOnly then
|
if (FCursor.FStatementType = stSelect) and not ReadOnly then
|
||||||
InitUpdates(FSQLBuf);
|
InitUpdates(FSQLBuf);
|
||||||
@ -617,8 +611,11 @@ procedure TSQLQuery.UnPrepare;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
CheckInactive;
|
CheckInactive;
|
||||||
if IsPrepared then (Database as tsqlconnection).UnPrepareStatement(FCursor);
|
if IsPrepared then with Database as TSQLConnection do
|
||||||
FreeAndNil(FCursor);
|
begin
|
||||||
|
UnPrepareStatement(FCursor);
|
||||||
|
DeAllocateCursorHandle(FCursor);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLQuery.FreeFldBuffers;
|
procedure TSQLQuery.FreeFldBuffers;
|
||||||
@ -682,7 +679,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLQuery.ParseSQL(var SQL : string);
|
procedure TSQLQuery.SQLParser(var SQL : string);
|
||||||
|
|
||||||
type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppBogus);
|
type TParsePart = (ppStart,ppSelect,ppWhere,ppFrom,ppOrder,ppComment,ppBogus);
|
||||||
|
|
||||||
@ -721,6 +718,7 @@ begin
|
|||||||
FCursor.FStatementType := (Database as tsqlconnection).StrToStatementType(s);
|
FCursor.FStatementType := (Database as tsqlconnection).StrToStatementType(s);
|
||||||
if FCursor.FStatementType = stSelect then ParsePart := ppSelect
|
if FCursor.FStatementType = stSelect then ParsePart := ppSelect
|
||||||
else break;
|
else break;
|
||||||
|
if not FParseSQL then break;
|
||||||
PStatementPart := CurrentP;
|
PStatementPart := CurrentP;
|
||||||
end;
|
end;
|
||||||
ppSelect : begin
|
ppSelect : begin
|
||||||
@ -858,6 +856,7 @@ begin
|
|||||||
FSQL.OnChange := @OnChangeSQL;
|
FSQL.OnChange := @OnChangeSQL;
|
||||||
FIndexDefs := TIndexDefs.Create(Self);
|
FIndexDefs := TIndexDefs.Create(Self);
|
||||||
FReadOnly := false;
|
FReadOnly := false;
|
||||||
|
FParseSQL := True;
|
||||||
// Delphi has upWhereAll as default, but since strings and oldvalue's don't work yet
|
// Delphi has upWhereAll as default, but since strings and oldvalue's don't work yet
|
||||||
// (variants) set it to upWhereKeyOnly
|
// (variants) set it to upWhereKeyOnly
|
||||||
FUpdateMode := upWhereKeyOnly;
|
FUpdateMode := upWhereKeyOnly;
|
||||||
@ -877,12 +876,27 @@ end;
|
|||||||
procedure TSQLQuery.SetReadOnly(AValue : Boolean);
|
procedure TSQLQuery.SetReadOnly(AValue : Boolean);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if not Active then FReadOnly := AValue
|
CheckInactive;
|
||||||
else
|
if not AValue then
|
||||||
begin
|
begin
|
||||||
// Just temporary, this should be possible in the future
|
if FParseSQL then FReadOnly := False
|
||||||
DatabaseError(SActiveDataset);
|
else DatabaseErrorFmt(SNoParseSQL,['Updating ']);
|
||||||
end;
|
end
|
||||||
|
else FReadOnly := True;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TSQLQuery.SetParseSQL(AValue : Boolean);
|
||||||
|
|
||||||
|
begin
|
||||||
|
CheckInactive;
|
||||||
|
if not AValue then
|
||||||
|
begin
|
||||||
|
FReadOnly := True;
|
||||||
|
Filtered := False;
|
||||||
|
FParseSQL := False;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
FParseSQL := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLQuery.SetUsePrimaryKeyAsKey(AValue : Boolean);
|
procedure TSQLQuery.SetUsePrimaryKeyAsKey(AValue : Boolean);
|
||||||
|
Loading…
Reference in New Issue
Block a user