mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-28 22:50:18 +02:00
* Locate by default starts from 0th record. Add option to allow search from current. Fix date handling
This commit is contained in:
parent
c149455dce
commit
0a0fd7dfe0
@ -1002,7 +1002,7 @@ type
|
|||||||
TUpdateAction = (uaFail, uaAbort, uaSkip, uaRetry, uaApplied);
|
TUpdateAction = (uaFail, uaAbort, uaSkip, uaRetry, uaApplied);
|
||||||
TUpdateKind = (ukModify, ukInsert, ukDelete);
|
TUpdateKind = (ukModify, ukInsert, ukDelete);
|
||||||
|
|
||||||
TLocateOption = (loCaseInsensitive, loPartialKey);
|
TLocateOption = (loCaseInsensitive, loPartialKey, loFromCurrent);
|
||||||
TLocateOptions = set of TLocateOption;
|
TLocateOptions = set of TLocateOption;
|
||||||
TDataOperation = procedure of object;
|
TDataOperation = procedure of object;
|
||||||
|
|
||||||
@ -1293,10 +1293,10 @@ type
|
|||||||
procedure Append;
|
procedure Append;
|
||||||
procedure AppendRecord(const Values: array of jsValue);
|
procedure AppendRecord(const Values: array of jsValue);
|
||||||
function BookmarkValid(ABookmark{%H-}: TBookmark): Boolean; virtual;
|
function BookmarkValid(ABookmark{%H-}: TBookmark): Boolean; virtual;
|
||||||
function ConvertToDateTime(aValue : JSValue; ARaiseException : Boolean) : TDateTime; virtual;
|
function ConvertToDateTime(aField : TField; aValue : JSValue; ARaiseException : Boolean) : TDateTime; virtual;
|
||||||
function ConvertDateTimeToNative(aValue : TDateTime) : JSValue; virtual;
|
function ConvertDateTimeToNative(aField : TField; aValue : TDateTime) : JSValue; virtual;
|
||||||
Class function DefaultConvertToDateTime(aValue : JSValue; ARaiseException{%H-} : Boolean) : TDateTime; virtual;
|
Class function DefaultConvertToDateTime(aField : TField; aValue : JSValue; ARaiseException{%H-} : Boolean) : TDateTime; virtual;
|
||||||
Class function DefaultConvertDateTimeToNative(aValue : TDateTime) : JSValue; virtual;
|
Class function DefaultConvertDateTimeToNative(aField : TField; aValue : TDateTime) : JSValue; virtual;
|
||||||
Function BlobDataToBytes(aValue : JSValue) : TBytes; virtual;
|
Function BlobDataToBytes(aValue : JSValue) : TBytes; virtual;
|
||||||
Class Function DefaultBlobDataToBytes(aValue : JSValue) : TBytes; virtual;
|
Class Function DefaultBlobDataToBytes(aValue : JSValue) : TBytes; virtual;
|
||||||
Function BytesToBlobData(aValue : TBytes) : JSValue ; virtual;
|
Function BytesToBlobData(aValue : TBytes) : JSValue ; virtual;
|
||||||
@ -3867,12 +3867,12 @@ end;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function TDataSet.ConvertToDateTime(aValue: JSValue; ARaiseException: Boolean): TDateTime;
|
function TDataSet.ConvertToDateTime(aField: TField; aValue: JSValue; ARaiseException: Boolean): TDateTime;
|
||||||
begin
|
begin
|
||||||
Result:=DefaultConvertToDateTime(aValue,ARaiseException);
|
Result:=DefaultConvertToDateTime(aField,aValue,ARaiseException);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TDataSet.DefaultConvertToDateTime(aValue: JSValue; ARaiseException: Boolean): TDateTime;
|
class function TDataSet.DefaultConvertToDateTime(aField: TField; aValue: JSValue; ARaiseException: Boolean): TDateTime;
|
||||||
begin
|
begin
|
||||||
Result:=0;
|
Result:=0;
|
||||||
if IsString(aValue) then
|
if IsString(aValue) then
|
||||||
@ -3884,13 +3884,13 @@ begin
|
|||||||
Result:=TDateTime(AValue)
|
Result:=TDateTime(AValue)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDataSet.ConvertDateTimeToNative(aValue : TDateTime) : JSValue;
|
function TDataSet.ConvertDateTimeToNative(aField: TField; aValue : TDateTime) : JSValue;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=DefaultConvertDateTimeToNative(aValue);
|
Result:=DefaultConvertDateTimeToNative(aField, aValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Class function TDataSet.DefaultConvertDateTimeToNative(aValue : TDateTime) : JSValue;
|
Class function TDataSet.DefaultConvertDateTimeToNative(aField : TField;aValue : TDateTime) : JSValue;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=DateTimeToRFC3339(aValue);
|
Result:=DateTimeToRFC3339(aValue);
|
||||||
@ -6735,18 +6735,20 @@ end;
|
|||||||
|
|
||||||
function TDateTimeField.ConvertToDateTime(aValue: JSValue; aRaiseError: Boolean): TDateTime;
|
function TDateTimeField.ConvertToDateTime(aValue: JSValue; aRaiseError: Boolean): TDateTime;
|
||||||
begin
|
begin
|
||||||
if Assigned(Dataset) then
|
if JS.isNull(aValue) then
|
||||||
Result:=Dataset.ConvertToDateTime(aValue,aRaiseError)
|
Result:=0
|
||||||
|
else if Assigned(Dataset) then
|
||||||
|
Result:=Dataset.ConvertToDateTime(Self,aValue,aRaiseError)
|
||||||
else
|
else
|
||||||
Result:=TDataset.DefaultConvertToDateTime(aValue,aRaiseError);
|
Result:=TDataset.DefaultConvertToDateTime(Self,aValue,aRaiseError);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDateTimeField.DateTimeToNativeDateTime(aValue: TDateTime): JSValue;
|
function TDateTimeField.DateTimeToNativeDateTime(aValue: TDateTime): JSValue;
|
||||||
begin
|
begin
|
||||||
if Assigned(Dataset) then
|
if Assigned(Dataset) then
|
||||||
Result:=Dataset.ConvertDateTimeToNative(aValue)
|
Result:=Dataset.ConvertDateTimeToNative(Self,aValue)
|
||||||
else
|
else
|
||||||
Result:=TDataset.DefaultConvertDateTimeToNative(aValue);
|
Result:=TDataset.DefaultConvertDateTimeToNative(Self,aValue);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TDateTimeField.GetAsDateTime: TDateTime;
|
function TDateTimeField.GetAsDateTime: TDateTime;
|
||||||
@ -7107,9 +7109,9 @@ Var
|
|||||||
begin
|
begin
|
||||||
V:=GetData;
|
V:=GetData;
|
||||||
if Assigned(Dataset) then
|
if Assigned(Dataset) then
|
||||||
Result:=Dataset.ConvertToDateTime(V,True)
|
Result:=Dataset.ConvertToDateTime(Self,V,True)
|
||||||
else
|
else
|
||||||
Result:=TDataset.DefaultConvertToDateTime(V,True)
|
Result:=TDataset.DefaultConvertToDateTime(Self,V,True)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TVariantField.GetAsFloat: Double;
|
function TVariantField.GetAsFloat: Double;
|
||||||
|
@ -282,6 +282,7 @@ type
|
|||||||
procedure SetRows(AValue: TJSArray);
|
procedure SetRows(AValue: TJSArray);
|
||||||
procedure SetRowType(AValue: TJSONRowType);
|
procedure SetRowType(AValue: TJSONRowType);
|
||||||
protected
|
protected
|
||||||
|
function ConvertDateTimeToNative(aField : TField; aValue : TDateTime) : JSValue; override;
|
||||||
// Determine filter value type based on field type
|
// Determine filter value type based on field type
|
||||||
function FieldTypeToExpressionType(aDataType: TFieldType): TResultType; virtual;
|
function FieldTypeToExpressionType(aDataType: TFieldType): TResultType; virtual;
|
||||||
// Callback for IsNull filter function.
|
// Callback for IsNull filter function.
|
||||||
@ -643,7 +644,7 @@ var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
D1:=Dataset.ConvertDateTimeField(String(GetFieldValue(Rowindex)),Self.Field);
|
D1:=Dataset.ConvertDateTimeField(String(GetFieldValue(Rowindex)),Self.Field);
|
||||||
D2:=TDateTime(aValue);
|
D2:=Dataset.ConvertDateTimeField(String(aValue),Self.Field);
|
||||||
Result:=Round(D1-D2);
|
Result:=Round(D1-D2);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1085,6 +1086,15 @@ begin
|
|||||||
FRowType:=AValue;
|
FRowType:=AValue;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TBaseJSONDataSet.ConvertDateTimeToNative(aField : TField; aValue: TDateTime): JSValue;
|
||||||
|
begin
|
||||||
|
if jsISNan(aValue) then
|
||||||
|
Result:=Null
|
||||||
|
else
|
||||||
|
Result:=FormatDateTimeField(aValue,aField)
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TBaseJSONDataSet.AllocRecordBuffer: TDataRecord;
|
function TBaseJSONDataSet.AllocRecordBuffer: TDataRecord;
|
||||||
begin
|
begin
|
||||||
@ -1174,7 +1184,7 @@ begin
|
|||||||
Result:=TFPExpressionParser;
|
Result:=TFPExpressionParser;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBaseJSONDataSet.GetFilterIsNull(Const Args : TExprParameterArray) : TFPExpressionResult;
|
function TBaseJSONDataSet.GetFilterIsNull(const Args: TExprParameterArray): TFPExpressionResult;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result.ResultType:=rtBoolean;
|
Result.ResultType:=rtBoolean;
|
||||||
@ -1201,7 +1211,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBaseJSONDataSet.GetFilterField(Const AName : String) : TFPExpressionResult;
|
function TBaseJSONDataSet.GetFilterField(const AName: String): TFPExpressionResult;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
F : TField;
|
F : TField;
|
||||||
@ -1265,7 +1275,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBaseJSONDataSet.GetRecord(Var Buffer: TDataRecord; GetMode: TGetMode; DoCheck: Boolean): TGetResult;
|
function TBaseJSONDataSet.GetRecord(var Buffer: TDataRecord; GetMode: TGetMode; DoCheck: Boolean): TGetResult;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
BkmIdx : Integer;
|
BkmIdx : Integer;
|
||||||
@ -1689,7 +1699,7 @@ begin
|
|||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TBaseJSONDataSet.CreateIndexDefs : TJSONIndexDefs;
|
function TBaseJSONDataSet.CreateIndexDefs: TJSONIndexDefs;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:=TJSONIndexDefs.Create(Self,Self,TJSONIndexDef);
|
Result:=TJSONIndexDefs.Create(Self,Self,TJSONIndexDef);
|
||||||
@ -1722,7 +1732,10 @@ begin
|
|||||||
Result:=-1;
|
Result:=-1;
|
||||||
Comp:=RecordComparerClass.Create(Self,KeyFields,KeyValues,Options);
|
Comp:=RecordComparerClass.Create(Self,KeyFields,KeyValues,Options);
|
||||||
try
|
try
|
||||||
I:=FCurrent;
|
if loFromCurrent in Options then
|
||||||
|
I:=FCurrent
|
||||||
|
else
|
||||||
|
I:=0;
|
||||||
RI:=FCurrentIndex.GetRecordIndex(I);
|
RI:=FCurrentIndex.GetRecordIndex(I);
|
||||||
While (Result=-1) and (RI<>-1) do
|
While (Result=-1) and (RI<>-1) do
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user