mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-02 19:30:17 +02:00
+ Caching of blob-fields which can only be fetched for the current record is now handled by TSQLConnection
+ postgresql text-fields are now considered to be blob-fields git-svn-id: trunk@4584 -
This commit is contained in:
parent
24ae32c855
commit
d0a367ef1e
@ -51,10 +51,6 @@ Type
|
|||||||
ParamBinding : TParamBinding;
|
ParamBinding : TParamBinding;
|
||||||
ParamReplaceString : String;
|
ParamReplaceString : String;
|
||||||
MapDSRowToMSQLRow : array of integer;
|
MapDSRowToMSQLRow : array of integer;
|
||||||
FBlobStrings:TStringList; // list of strings in which the blob-fields are stored
|
|
||||||
public
|
|
||||||
constructor Create;
|
|
||||||
destructor Destroy; override;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
TConnectionName = class (TSQLConnection)
|
TConnectionName = class (TSQLConnection)
|
||||||
@ -99,7 +95,6 @@ Type
|
|||||||
procedure CommitRetaining(trans : TSQLHandle); override;
|
procedure CommitRetaining(trans : TSQLHandle); override;
|
||||||
procedure RollBackRetaining(trans : TSQLHandle); override;
|
procedure RollBackRetaining(trans : TSQLHandle); override;
|
||||||
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); override;
|
procedure UpdateIndexDefs(var IndexDefs : TIndexDefs;TableName : string); override;
|
||||||
procedure LoadBlobIntoStream(Field: TField;AStream: TMemoryStream;cursor: TSQLCursor;ATransaction : TSQLTransaction); override;
|
|
||||||
Public
|
Public
|
||||||
Property ServerInfo : String Read FServerInfo;
|
Property ServerInfo : String Read FServerInfo;
|
||||||
Property HostInfo : String Read FHostInfo;
|
Property HostInfo : String Read FHostInfo;
|
||||||
@ -216,7 +211,7 @@ var esc_str : pchar;
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
if (not assigned(param)) or param.IsNull then Result := 'Null'
|
if (not assigned(param)) or param.IsNull then Result := 'Null'
|
||||||
else if param.DataType = ftString then
|
else if param.DataType in [ftString,ftBlob] then
|
||||||
begin
|
begin
|
||||||
Getmem(esc_str,length(param.asstring)*2+1);
|
Getmem(esc_str,length(param.asstring)*2+1);
|
||||||
mysql_real_escape_string(FMySQL,esc_str,pchar(param.asstring),length(param.asstring));
|
mysql_real_escape_string(FMySQL,esc_str,pchar(param.asstring),length(param.asstring));
|
||||||
@ -347,7 +342,7 @@ begin
|
|||||||
C.FRes:=Nil;
|
C.FRes:=Nil;
|
||||||
end;
|
end;
|
||||||
SetLength(c.MapDSRowToMSQLRow,0);
|
SetLength(c.MapDSRowToMSQLRow,0);
|
||||||
c.FBlobStrings.Clear;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TConnectionName.Execute(cursor: TSQLCursor;
|
procedure TConnectionName.Execute(cursor: TSQLCursor;
|
||||||
@ -764,25 +759,6 @@ begin
|
|||||||
qry.free;
|
qry.free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TConnectionName.LoadBlobIntoStream(Field: TField;AStream: TMemoryStream;cursor: TSQLCursor;ATransaction : TSQLTransaction);
|
|
||||||
|
|
||||||
var blobId : pinteger;
|
|
||||||
BlobBuf : TBufBlobField;
|
|
||||||
s : string;
|
|
||||||
|
|
||||||
begin
|
|
||||||
if not field.getData(@BlobBuf) then
|
|
||||||
exit;
|
|
||||||
blobId := @BlobBuf;
|
|
||||||
|
|
||||||
s := (cursor as TCursorName).FBlobStrings.Strings[blobid^];
|
|
||||||
|
|
||||||
AStream.WriteBuffer(s[1],length(s));
|
|
||||||
|
|
||||||
AStream.seek(0,soFromBeginning);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function TConnectionName.GetTransactionHandle(trans: TSQLHandle): pointer;
|
function TConnectionName.GetTransactionHandle(trans: TSQLHandle): pointer;
|
||||||
begin
|
begin
|
||||||
Result:=Nil;
|
Result:=Nil;
|
||||||
@ -813,18 +789,4 @@ begin
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TCursorName }
|
|
||||||
|
|
||||||
constructor TCursorName.Create;
|
|
||||||
begin
|
|
||||||
FBlobStrings := TStringList.Create;
|
|
||||||
inherited;
|
|
||||||
end;
|
|
||||||
|
|
||||||
destructor TCursorName.Destroy;
|
|
||||||
begin
|
|
||||||
FBlobStrings.Free;
|
|
||||||
inherited Destroy;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -49,7 +49,6 @@ type
|
|||||||
Function AllocateTransactionHandle : TSQLHandle; override;
|
Function AllocateTransactionHandle : TSQLHandle; override;
|
||||||
|
|
||||||
procedure PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams); override;
|
procedure PrepareStatement(cursor: TSQLCursor;ATransaction : TSQLTransaction;buf : string; AParams : TParams); override;
|
||||||
procedure FreeFldBuffers(cursor : TSQLCursor); override;
|
|
||||||
procedure Execute(cursor: TSQLCursor;atransaction:tSQLtransaction; AParams : TParams); override;
|
procedure Execute(cursor: TSQLCursor;atransaction:tSQLtransaction; AParams : TParams); override;
|
||||||
procedure AddFieldDefs(cursor: TSQLCursor; FieldDefs : TfieldDefs); override;
|
procedure AddFieldDefs(cursor: TSQLCursor; FieldDefs : TfieldDefs); override;
|
||||||
function Fetch(cursor : TSQLCursor) : boolean; override;
|
function Fetch(cursor : TSQLCursor) : boolean; override;
|
||||||
@ -307,7 +306,8 @@ begin
|
|||||||
case Type_Oid of
|
case Type_Oid of
|
||||||
Oid_varchar,Oid_bpchar,
|
Oid_varchar,Oid_bpchar,
|
||||||
Oid_name : Result := ftstring;
|
Oid_name : Result := ftstring;
|
||||||
Oid_text : Result := ftstring;
|
// Oid_text : Result := ftstring;
|
||||||
|
Oid_text : Result := ftBlob;
|
||||||
Oid_oid : Result := ftInteger;
|
Oid_oid : Result := ftInteger;
|
||||||
Oid_int8 : Result := ftLargeInt;
|
Oid_int8 : Result := ftLargeInt;
|
||||||
Oid_int4 : Result := ftInteger;
|
Oid_int4 : Result := ftInteger;
|
||||||
@ -451,12 +451,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPQConnection.FreeFldBuffers(cursor : TSQLCursor);
|
|
||||||
|
|
||||||
begin
|
|
||||||
// Do nothing
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TPQConnection.Execute(cursor: TSQLCursor;atransaction:tSQLtransaction;AParams : TParams);
|
procedure TPQConnection.Execute(cursor: TSQLCursor;atransaction:tSQLtransaction;AParams : TParams);
|
||||||
|
|
||||||
var ar : array of pointer;
|
var ar : array of pointer;
|
||||||
@ -537,9 +531,11 @@ begin
|
|||||||
begin
|
begin
|
||||||
size := pqfmod(res,i)-4;
|
size := pqfmod(res,i)-4;
|
||||||
if size = -5 then size := dsMaxStringSize;
|
if size = -5 then size := dsMaxStringSize;
|
||||||
end;
|
end
|
||||||
if fieldtype = ftdate then
|
else if fieldtype = ftdate then
|
||||||
size := sizeof(double);
|
size := sizeof(double)
|
||||||
|
else if fieldtype = ftblob then
|
||||||
|
size := 0;
|
||||||
|
|
||||||
TFieldDef.Create(FieldDefs, PQfname(Res, i), fieldtype,size, False, (i + 1));
|
TFieldDef.Create(FieldDefs, PQfname(Res, i), fieldtype,size, False, (i + 1));
|
||||||
end;
|
end;
|
||||||
@ -581,6 +577,7 @@ var
|
|||||||
dbl : pdouble;
|
dbl : pdouble;
|
||||||
cur : currency;
|
cur : currency;
|
||||||
NumericRecord : ^TNumericRecord;
|
NumericRecord : ^TNumericRecord;
|
||||||
|
s : string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
with cursor as TPQCursor do
|
with cursor as TPQCursor do
|
||||||
@ -619,6 +616,14 @@ begin
|
|||||||
pchar(Buffer + li)^ := #0;
|
pchar(Buffer + li)^ := #0;
|
||||||
i := pqfmod(res,x)-3;
|
i := pqfmod(res,x)-3;
|
||||||
end;
|
end;
|
||||||
|
ftBlob :
|
||||||
|
begin
|
||||||
|
li := pqgetlength(res,curtuple,x);
|
||||||
|
setlength(s,li);
|
||||||
|
Move(CurrBuff^, s[1], li);
|
||||||
|
i := fBlobStrings.Add(S);
|
||||||
|
Move(I, Buffer^, SizeOf(Integer));
|
||||||
|
end;
|
||||||
ftdate :
|
ftdate :
|
||||||
begin
|
begin
|
||||||
dbl := pointer(buffer);
|
dbl := pointer(buffer);
|
||||||
|
@ -38,11 +38,17 @@ type
|
|||||||
TSQLHandle = Class(TObject)
|
TSQLHandle = Class(TObject)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TSQLCursor }
|
||||||
|
|
||||||
TSQLCursor = Class(TSQLHandle)
|
TSQLCursor = Class(TSQLHandle)
|
||||||
public
|
public
|
||||||
FPrepared : Boolean;
|
FPrepared : Boolean;
|
||||||
FInitFieldDef : Boolean;
|
FInitFieldDef : Boolean;
|
||||||
FStatementType : TStatementType;
|
FStatementType : TStatementType;
|
||||||
|
FBlobStrings : TStringList; // list of strings in which the blob-fields are stored
|
||||||
|
public
|
||||||
|
constructor Create;
|
||||||
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -90,7 +96,7 @@ type
|
|||||||
procedure AddFieldDefs(cursor: TSQLCursor; FieldDefs : TfieldDefs); virtual; abstract;
|
procedure AddFieldDefs(cursor: TSQLCursor; FieldDefs : TfieldDefs); virtual; abstract;
|
||||||
procedure UnPrepareStatement(cursor : TSQLCursor); virtual; abstract;
|
procedure UnPrepareStatement(cursor : TSQLCursor); virtual; abstract;
|
||||||
|
|
||||||
procedure FreeFldBuffers(cursor : TSQLCursor); virtual; abstract;
|
procedure FreeFldBuffers(cursor : TSQLCursor); virtual;
|
||||||
function LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer) : boolean; virtual; abstract;
|
function LoadField(cursor : TSQLCursor;FieldDef : TfieldDef;buffer : pointer) : boolean; virtual; abstract;
|
||||||
function GetTransactionHandle(trans : TSQLHandle): pointer; virtual; abstract;
|
function GetTransactionHandle(trans : TSQLHandle): pointer; virtual; abstract;
|
||||||
function Commit(trans : TSQLHandle) : boolean; virtual; abstract;
|
function Commit(trans : TSQLHandle) : boolean; virtual; abstract;
|
||||||
@ -455,6 +461,11 @@ begin
|
|||||||
Result := nil;
|
Result := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TSQLConnection.FreeFldBuffers(cursor: TSQLCursor);
|
||||||
|
begin
|
||||||
|
cursor.FBlobStrings.Clear;
|
||||||
|
end;
|
||||||
|
|
||||||
function TSQLConnection.GetSchemaInfoSQL( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string;
|
function TSQLConnection.GetSchemaInfoSQL( SchemaType : TSchemaType; SchemaObjectName, SchemaPattern : string) : string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -463,8 +474,20 @@ end;
|
|||||||
|
|
||||||
procedure TSQLConnection.LoadBlobIntoStream(Field: TField;AStream: TMemoryStream; cursor: TSQLCursor;ATransaction : TSQLTransaction);
|
procedure TSQLConnection.LoadBlobIntoStream(Field: TField;AStream: TMemoryStream; cursor: TSQLCursor;ATransaction : TSQLTransaction);
|
||||||
|
|
||||||
|
var blobId : pinteger;
|
||||||
|
BlobBuf : TBufBlobField;
|
||||||
|
s : string;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
DatabaseErrorFmt(SUnsupportedFieldType,['Blob']);
|
if not field.getData(@BlobBuf) then
|
||||||
|
exit;
|
||||||
|
blobId := @BlobBuf;
|
||||||
|
|
||||||
|
s := cursor.FBlobStrings.Strings[blobid^];
|
||||||
|
|
||||||
|
AStream.WriteBuffer(s[1],length(s));
|
||||||
|
|
||||||
|
AStream.seek(0,soFromBeginning);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSQLTransaction }
|
{ TSQLTransaction }
|
||||||
@ -1260,4 +1283,18 @@ begin
|
|||||||
DataSource:=Nil;
|
DataSource:=Nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TSQLCursor }
|
||||||
|
|
||||||
|
constructor TSQLCursor.Create;
|
||||||
|
begin
|
||||||
|
FBlobStrings := TStringList.Create;
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TSQLCursor.Destroy;
|
||||||
|
begin
|
||||||
|
FBlobStrings.Free;
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user