mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-13 08:19:27 +02:00
+ fcl-db: SQlite3: accept more date/time formats:
YYYY-MM-DDTHH:MM YYYY-MM-DDTHH:MM:SS YYYY-MM-DDTHH:MM:SS.SSS as defined in http://www.sqlite.org/lang_datefunc.html Fixes mantis issue #26551 git-svn-id: trunk@28337 -
This commit is contained in:
parent
6f6dd75e77
commit
24b406aed7
@ -97,7 +97,7 @@ type
|
|||||||
function GetInsertID: int64;
|
function GetInsertID: int64;
|
||||||
// See http://www.sqlite.org/c3ref/create_collation.html for detailed information
|
// See http://www.sqlite.org/c3ref/create_collation.html for detailed information
|
||||||
// If eTextRep=0 a default UTF-8 compare function is used (UTF8CompareCallback)
|
// If eTextRep=0 a default UTF-8 compare function is used (UTF8CompareCallback)
|
||||||
// Warning: UTF8CompareCallback needs a wide string manager on linux such as cwstring
|
// Warning: UTF8CompareCallback needs a wide string manager on Linux such as cwstring
|
||||||
// Warning: CollationName has to be a UTF-8 string
|
// Warning: CollationName has to be a UTF-8 string
|
||||||
procedure CreateCollation(const CollationName: string; eTextRep: integer; Arg: Pointer=nil; Compare: xCompare=nil);
|
procedure CreateCollation(const CollationName: string; eTextRep: integer; Arg: Pointer=nil; Compare: xCompare=nil);
|
||||||
procedure LoadExtension(LibraryFile: string);
|
procedure LoadExtension(LibraryFile: string);
|
||||||
@ -540,7 +540,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Parses string-formatted time into TDateTime value
|
// Parses string-formatted time into TDateTime value
|
||||||
// Expected format '23:59:59.999' (without ')
|
// Expected formats
|
||||||
|
// 23:59
|
||||||
|
// 23:59:59
|
||||||
|
// 23:59:59.999
|
||||||
Function ParseSQLiteTime(S : ShortString; Interval: boolean) : TDateTime;
|
Function ParseSQLiteTime(S : ShortString; Interval: boolean) : TDateTime;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -550,14 +553,25 @@ begin
|
|||||||
Result:=0;
|
Result:=0;
|
||||||
If TryStrToInt(NextWord(S,':'),Hour) then
|
If TryStrToInt(NextWord(S,':'),Hour) then
|
||||||
if TryStrToInt(NextWord(S,':'),Min) then
|
if TryStrToInt(NextWord(S,':'),Min) then
|
||||||
|
begin
|
||||||
if TryStrToInt(NextWord(S,'.'),Sec) then
|
if TryStrToInt(NextWord(S,'.'),Sec) then
|
||||||
begin
|
begin // 23:59:59 or 23:59:59.999
|
||||||
MSec:=StrToIntDef(S,0);
|
MSec:=StrToIntDef(S,0);
|
||||||
if Interval then
|
if Interval then
|
||||||
Result:=EncodeTimeInterval(Hour,Min,Sec,MSec)
|
Result:=EncodeTimeInterval(Hour,Min,Sec,MSec)
|
||||||
else
|
else
|
||||||
Result:=EncodeTime(Hour,Min,Sec,MSec);
|
Result:=EncodeTime(Hour,Min,Sec,MSec);
|
||||||
end;
|
end;
|
||||||
|
end
|
||||||
|
else //23:59
|
||||||
|
begin
|
||||||
|
Sec:=0;
|
||||||
|
MSec:=0;
|
||||||
|
if Interval then
|
||||||
|
Result:=EncodeTimeInterval(Hour,Min,Sec,MSec)
|
||||||
|
else
|
||||||
|
Result:=EncodeTime(Hour,Min,Sec,MSec);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Parses string-formatted date/time into TDateTime value
|
// Parses string-formatted date/time into TDateTime value
|
||||||
@ -570,7 +584,9 @@ var
|
|||||||
begin
|
begin
|
||||||
DS:='';
|
DS:='';
|
||||||
TS:='';
|
TS:='';
|
||||||
P:=Pos(' ',S);
|
P:=Pos('T',S); //allow e.g. YYYY-MM-DDTHH:MM
|
||||||
|
if P=0 then
|
||||||
|
P:=Pos(' ',S); //allow e.g. YYYY-MM-DD HH:MM
|
||||||
If (P<>0) then
|
If (P<>0) then
|
||||||
begin
|
begin
|
||||||
DS:=Copy(S,1,P-1);
|
DS:=Copy(S,1,P-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user