Skip to content

Commit

Permalink
several fixes and enhancements to TSQLDBConnectionProperties.Multiple…
Browse files Browse the repository at this point in the history
…ValuesInsertFirebird
  • Loading branch information
Arnaud Bouchez committed Nov 6, 2019
1 parent a95a9c7 commit f6c4a01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions SynDB.pas
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6171,7 +6171,7 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
const FieldNames: TRawUTF8DynArray; const FieldTypes: TSQLDBFieldTypeArray; const FieldNames: TRawUTF8DynArray; const FieldTypes: TSQLDBFieldTypeArray;
RowCount: integer; const FieldValues: TRawUTF8DynArrayDynArray); RowCount: integer; const FieldValues: TRawUTF8DynArrayDynArray);
var W: TTextWriter; var W: TTextWriter;
maxf,sqllenwitoutvalues,sqllen,r,f,i: Integer; maxf,sqllenwitoutvalues,sqllen,r,f,i: PtrInt;
v: RawUTF8; v: RawUTF8;
begin begin
maxf := length(FieldNames); // e.g. 2 fields maxf := length(FieldNames); // e.g. 2 fields
Expand All @@ -6187,7 +6187,7 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
MultipleValuesInsert(Props,TableName,FieldNames,FieldTypes,RowCount,FieldValues); MultipleValuesInsert(Props,TableName,FieldNames,FieldTypes,RowCount,FieldValues);
exit; exit;
end; end;
ftDate: inc(sqllenwitoutvalues,Length(FieldNames[f])+20); // 'cast(..)' ftDate: inc(sqllenwitoutvalues,Length(FieldNames[f])+20); // 'timestamp '
else else
inc(sqllenwitoutvalues,Length(FieldNames[f])); inc(sqllenwitoutvalues,Length(FieldNames[f]));
end; end;
Expand All @@ -6196,11 +6196,11 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
r := 0; r := 0;
repeat repeat
W.AddShort('execute block as begin'#10); W.AddShort('execute block as begin'#10);
sqllen := sqllenwitoutvalues;
repeat repeat
sqllen := sqllenwitoutvalues;
for f := 0 to maxf do for f := 0 to maxf do
inc(sqllen,length(FieldValues[f,r])); inc(sqllen,length(FieldValues[f,r]));
if sqllen+integer(W.TextLength)>30000 then if sqllen+PtrInt(W.TextLength)>30000 then
break; break;
W.AddShort('INSERT INTO '); W.AddShort('INSERT INTO ');
W.AddString(TableName); W.AddString(TableName);
Expand All @@ -6212,21 +6212,24 @@ procedure TSQLDBConnectionProperties.MultipleValuesInsertFirebird(
W.CancelLastComma; W.CancelLastComma;
W.AddShort(') VALUES ('); W.AddShort(') VALUES (');
for f := 0 to maxf do begin 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 W.AddShort('null') else
if FieldTypes[f]=ftDate then if FieldTypes[f]=ftDate then
if FieldValues[f,r]=#39#39 then if v=#39#39 then
W.AddShort('null') else begin W.AddShort('null') else begin
W.AddShort('timestamp '); W.AddShort('timestamp ');
v := FieldValues[f,r]; if length(v)>12 then begin // not 'CCYY-MM-DD' -> fix needed?
if length(v)<>10 then begin // not 'CCYY-MM-DD' -> fix needed? if v[12]='T' then // handle 'CCYY-MM-DDTHH:MM:SS' common case
i := PosExChar('T',v); v[12] := ' ' else begin
if i>0 then // see https://firebirdsql.org/en/firebird-date-literals i := PosExChar('T',v);
v[i] := ' '; if i>0 then
v[i] := ' ';
end; // see https://firebirdsql.org/en/firebird-date-literals
end; end;
W.AddString(v) W.AddString(v)
end else end else
W.AddString(FieldValues[f,r]); W.AddString(v);
W.Add(','); W.Add(',');
end; end;
W.CancelLastComma; W.CancelLastComma;
Expand Down
2 changes: 1 addition & 1 deletion SynopseCommit.inc
Original file line number Original file line Diff line number Diff line change
@@ -1 +1 @@
'1.18.5445' '1.18.5446'

0 comments on commit f6c4a01

Please sign in to comment.