Skip to content

Commit cad1b10

Browse files
author
Arnaud Bouchez
committed
introducing ISQLDBStatement.ForceDateWithMS property
1 parent 3834817 commit cad1b10

7 files changed

+41
-12
lines changed

SynDB.pas

+34-6
Original file line numberDiff line numberDiff line change
@@ -951,12 +951,20 @@ TSQLDBRowVariantType = class(TSynInvokeableVariantType)
951951
// - BLOB field value is saved as Base64, in the '"\uFFF0base64encodedbinary"'
952952
// format and contains true BLOB data
953953
procedure ExecutePreparedAndFetchAllAsJSON(Expanded: boolean; out JSON: RawUTF8);
954+
954955
function GetForceBlobAsNull: boolean;
955956
procedure SetForceBlobAsNull(value: boolean);
956957
/// if set, any BLOB field won't be retrieved, and forced to be null
957958
// - this may be used to speed up fetching the results for SQL requests
958959
// with * statements
959960
property ForceBlobAsNull: boolean read GetForceBlobAsNull write SetForceBlobAsNull;
961+
function GetForceDateWithMS: boolean;
962+
procedure SetForceDateWithMS(value: boolean);
963+
/// if set, any ftDate field will contain the milliseconds information
964+
// when serialized into ISO-8601 text
965+
// - this setting is private to each statement, since may vary depending
966+
// on data definition (e.g. ORM TDateTime/TDateTimeMS)
967+
property ForceDateWithMS: boolean read GetForceDateWithMS write SetForceDateWithMS;
960968
/// gets a number of updates made by latest executed statement
961969
function UpdateCount: Integer;
962970
end;
@@ -1863,10 +1871,13 @@ TSQLDBStatement = class(TInterfacedObject, ISQLDBRows, ISQLDBStatement)
18631871
fCurrentRow: Integer;
18641872
fSQLWithInlinedParams: RawUTF8;
18651873
fForceBlobAsNull: boolean;
1874+
fForceDateWithMS: boolean;
18661875
fDBMS: TSQLDBDefinition;
18671876
function GetSQLWithInlinedParams: RawUTF8;
18681877
function GetForceBlobAsNull: boolean;
18691878
procedure SetForceBlobAsNull(value: boolean);
1879+
function GetForceDateWithMS: boolean;
1880+
procedure SetForceDateWithMS(value: boolean);
18701881
/// raise an exception if Col is out of range according to fColumnCount
18711882
procedure CheckCol(Col: integer); {$ifdef HASINLINE}inline;{$endif}
18721883
/// will set a Int64/Double/Currency/TDateTime/RawUTF8/TBlobData Dest variable
@@ -2671,8 +2682,8 @@ ESQLDBRemote = class(ESQLDBException);
26712682
Params: TSQLDBParamDynArray;
26722683
/// if input parameters expected BindArray() process
26732684
ArrayCount: integer;
2674-
/// if set, any BLOB field won't be retrieved, and forced to be null
2675-
ForceBlobAsNull: boolean;
2685+
/// match ForceBlobAsNull and ForceDateWithMS properties
2686+
Force: set of (fBlobAsNull, fDateWithMS);
26762687
end;
26772688

26782689
/// implements a proxy-like virtual connection statement to a DB engine
@@ -4543,8 +4554,10 @@ procedure AppendOutput(value: Int64);
45434554
RecordLoad(InputExecute,O,TypeInfo(TSQLDBProxyConnectionCommandExecute));
45444555
ExecuteWithResults := header.Command<>cExecute;
45454556
Stmt := NewStatementPrepared(InputExecute.SQL,ExecuteWithResults,true);
4546-
if InputExecute.ForceBlobAsNull then
4557+
if fBlobAsNull in InputExecute.Force then
45474558
Stmt.ForceBlobAsNull := true;
4559+
if fDateWithMS in InputExecute.Force then
4560+
Stmt.ForceDateWithMS := true;
45484561
for i := 1 to Length(InputExecute.Params) do
45494562
with InputExecute.Params[i-1] do
45504563
if InputExecute.ArrayCount=0 then
@@ -6730,6 +6743,16 @@ procedure TSQLDBStatement.SetForceBlobAsNull(value: boolean);
67306743
fForceBlobAsNull := value;
67316744
end;
67326745

6746+
function TSQLDBStatement.GetForceDateWithMS: boolean;
6747+
begin
6748+
result := fForceDateWithMS;
6749+
end;
6750+
6751+
procedure TSQLDBStatement.SetForceDateWithMS(value: boolean);
6752+
begin
6753+
fForceDateWithMS := value;
6754+
end;
6755+
67336756
constructor TSQLDBStatement.Create(aConnection: TSQLDBConnection);
67346757
begin
67356758
// SynDBLog.Enter(self);
@@ -6836,7 +6859,7 @@ procedure TSQLDBStatement.ColumnsToJSON(WR: TJSONWriter);
68366859
ftCurrency: WR.AddCurr64(ColumnCurrency(col));
68376860
ftDate: begin
68386861
WR.Add('"');
6839-
WR.AddDateTime(ColumnDateTime(col));
6862+
WR.AddDateTime(ColumnDateTime(col),fForceDateWithMS);
68406863
WR.Add('"');
68416864
end;
68426865
ftUTF8: begin
@@ -6863,6 +6886,7 @@ procedure TSQLDBStatement.ColumnsToJSON(WR: TJSONWriter);
68636886
procedure TSQLDBStatement.ColumnToSQLVar(Col: Integer; var Value: TSQLVar;
68646887
var Temp: RawByteString);
68656888
begin
6889+
Value.Options := [];
68666890
if ColumnNull(Col) then // will call GetCol() to check Col
68676891
Value.VType := ftNull else
68686892
Value.VType := ColumnType(Col);
@@ -7021,7 +7045,7 @@ function TSQLDBStatement.FetchAllToCSVValues(Dest: TStream; Tab: boolean;
70217045
ftDate: begin
70227046
if not Tab then
70237047
W.Add('"');
7024-
W.AddDateTime(V.VDateTime);
7048+
W.AddDateTime(V.VDateTime,svoDateWithMS in V.Options);
70257049
if not Tab then
70267050
W.Add('"');
70277051
end;
@@ -8481,7 +8505,11 @@ procedure TSQLDBProxyStatement.ParamsToCommand(var Input: TSQLDBProxyConnectionC
84818505
SetLength(fParams,fParamCount);
84828506
Input.Params := fParams;
84838507
Input.ArrayCount := fParamsArrayCount;
8484-
Input.ForceBlobAsNull := fForceBlobAsNull;
8508+
if fForceBlobAsNull then
8509+
Input.Force := [fBlobAsNull] else
8510+
Input.Force := [];
8511+
if fForceDateWithMS then
8512+
include(Input.Force,fDateWithMS);
84858513
end;
84868514

84878515
procedure TSQLDBProxyStatement.ExecutePrepared;

SynDBDataset.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ procedure TSQLDBDatasetStatementAbstract.ColumnsToJSON(WR: TJSONWriter);
533533
WR.AddCurr64(TField(ColumnAttr).AsCurrency);
534534
SynCommons.ftDate: begin
535535
WR.Add('"');
536-
WR.AddDateTime(TField(ColumnAttr).AsDateTime);
536+
WR.AddDateTime(TField(ColumnAttr).AsDateTime,fForceDateWithMS);
537537
WR.Add('"');
538538
end;
539539
SynCommons.ftUTF8: begin

SynDBODBC.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,8 @@ procedure TODBCStatement.ColumnsToJSON(WR: TJSONWriter);
15621562
ftDouble, ftCurrency:
15631563
WR.AddFloatStr(Pointer(fColData[Col])); // already as SQL_C_CHAR
15641564
ftDate:
1565-
WR.AddNoJSONEscape(@tmp,
1566-
PSQL_TIMESTAMP_STRUCT(Pointer(fColData[Col]))^.ToIso8601(tmp,ColumnValueDBType));
1565+
WR.AddNoJSONEscape(@tmp,PSQL_TIMESTAMP_STRUCT(Pointer(fColData[Col]))^.
1566+
ToIso8601(tmp,ColumnValueDBType,fForceDateWithMS));
15671567
ftUTF8: begin
15681568
WR.Add('"');
15691569
if ColumnDataSize>1 then

SynDBOracle.pas

+1
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,7 @@ procedure TSQLDBOracleStatement.ColumnToSQLVar(Col: Integer; var Value: TSQLVar;
23642364
V: pointer;
23652365
NoDecimal: boolean;
23662366
begin // dedicated version to avoid as much memory allocation than possible
2367+
Value.Options := [];
23672368
V := GetCol(Col,C);
23682369
if V=nil then
23692370
Value.VType := ftNull else

SynDBZeos.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ procedure WriteIZBlob;
12751275
WR.AddCurr64(fResultSet.GetCurrency(col+FirstDbcIndex));
12761276
ftDate: begin
12771277
WR.Add('"');
1278-
WR.AddDateTime(fResultSet.GetTimeStamp(col+FirstDbcIndex));
1278+
WR.AddDateTime(fResultSet.GetTimeStamp(col+FirstDbcIndex),fForceDateWithMS);
12791279
WR.Add('"');
12801280
end;
12811281
ftUTF8: begin

SynOleDB.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ procedure TOleDBStatement.ColumnsToJSON(WR: TJSONWriter);
17121712
ftCurrency: WR.AddCurr64(V^.Int64);
17131713
ftDate: begin
17141714
WR.Add('"');
1715-
WR.AddDateTime(@V^.Double);
1715+
WR.AddDateTime(@V^.Double,'T',#0,fForceDateWithMS);
17161716
WR.Add('"');
17171717
end;
17181718
ftUTF8: begin

SynopseCommit.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'1.18.3363'
1+
'1.18.3364'

0 commit comments

Comments
 (0)