Skip to content
Permalink
Browse files

several fixes and enhancements to TSQLDBConnectionProperties.Multiple…

…ValuesInsertFirebird
  • Loading branch information...
Arnaud Bouchez
Arnaud Bouchez committed Nov 6, 2019
1 parent a95a9c7 commit f6c4a0195b33a9920c24d427310609039cd02504
Showing with 16 additions and 13 deletions.
  1. +15 −12 SynDB.pas
  2. +1 −1 SynopseCommit.inc
@@ -6171,7 +6171,7 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
const FieldNames: TRawUTF8DynArray; const FieldTypes: TSQLDBFieldTypeArray;
RowCount: integer; const FieldValues: TRawUTF8DynArrayDynArray);
var W: TTextWriter;
maxf,sqllenwitoutvalues,sqllen,r,f,i: Integer;
maxf,sqllenwitoutvalues,sqllen,r,f,i: PtrInt;
v: RawUTF8;
begin
maxf := length(FieldNames); // e.g. 2 fields
@@ -6187,7 +6187,7 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
MultipleValuesInsert(Props,TableName,FieldNames,FieldTypes,RowCount,FieldValues);
exit;
end;
ftDate: inc(sqllenwitoutvalues,Length(FieldNames[f])+20); // 'cast(..)'
ftDate: inc(sqllenwitoutvalues,Length(FieldNames[f])+20); // 'timestamp '
else
inc(sqllenwitoutvalues,Length(FieldNames[f]));
end;
@@ -6196,11 +6196,11 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
r := 0;
repeat
W.AddShort('execute block as begin'#10);
sqllen := sqllenwitoutvalues;
repeat
sqllen := sqllenwitoutvalues;
for f := 0 to maxf do
inc(sqllen,length(FieldValues[f,r]));
if sqllen+integer(W.TextLength)>30000 then
if sqllen+PtrInt(W.TextLength)>30000 then
break;
W.AddShort('INSERT INTO ');
W.AddString(TableName);
@@ -6212,21 +6212,24 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
W.CancelLastComma;
W.AddShort(') VALUES (');
for f := 0 to maxf do begin
if (FieldValues[f,r]='') or (FieldValues[f,r]='null') then
v := FieldValues[f,r]; // includes single quotes (#39)
if (v='') or (v='null') then
W.AddShort('null') else
if FieldTypes[f]=ftDate then
if FieldValues[f,r]=#39#39 then
if v=#39#39 then
W.AddShort('null') else begin
W.AddShort('timestamp ');
v := FieldValues[f,r];
if length(v)<>10 then begin // not 'CCYY-MM-DD' -> fix needed?
i := PosExChar('T',v);
if i>0 then // see https://firebirdsql.org/en/firebird-date-literals
v[i] := ' ';
if length(v)>12 then begin // not 'CCYY-MM-DD' -> fix needed?
if v[12]='T' then // handle 'CCYY-MM-DDTHH:MM:SS' common case
v[12] := ' ' else begin
i := PosExChar('T',v);
if i>0 then
v[i] := ' ';
end; // see https://firebirdsql.org/en/firebird-date-literals
end;
W.AddString(v)
end else
W.AddString(FieldValues[f,r]);
W.AddString(v);
W.Add(',');
end;
W.CancelLastComma;
@@ -1 +1 @@
'1.18.5445'
'1.18.5446'

0 comments on commit f6c4a01

Please sign in to comment.
You can’t perform that action at this time.