mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-03 05:18:29 +02:00
* fixed mysql date problems using sscanf :]
* better integer parsing in sscanf git-svn-id: trunk@609 -
This commit is contained in:
parent
86da715b86
commit
cfcaff7dc9
@ -688,12 +688,15 @@ end;
|
||||
function TMySQLDataset.InternalStrToDate(S: string): TDateTime;
|
||||
|
||||
var
|
||||
EY, EM, ED: Word;
|
||||
EY, EM, ED: Longint;
|
||||
|
||||
begin
|
||||
SScanf(S,'%d-%d-%d',[@EY,@EM,@ED]);
|
||||
{
|
||||
EY := StrToInt(Copy(S,1,4));
|
||||
EM := StrToInt(Copy(S,6,2));
|
||||
ED := StrToInt(Copy(S,9,2));
|
||||
}
|
||||
if (EY = 0) or (EM = 0) or (ED = 0) then
|
||||
Result:=0
|
||||
else
|
||||
@ -703,16 +706,19 @@ end;
|
||||
function TMySQLDataset.InternalStrToDateTime(S: string): TDateTime;
|
||||
|
||||
var
|
||||
EY, EM, ED: Word;
|
||||
EH, EN, ES: Word;
|
||||
EY, EM, ED: Longint;
|
||||
EH, EN, ES: Longint;
|
||||
|
||||
begin
|
||||
SScanf(S,'%d-%d-%d %d:%d:%d',[@EY,@EM,@ED,@EH,@EN,@ES]);
|
||||
{
|
||||
EY := StrToInt(Copy(S, 1, 4));
|
||||
EM := StrToInt(Copy(S, 6, 2));
|
||||
ED := StrToInt(Copy(S, 9, 2));
|
||||
EH := StrToInt(Copy(S, 12, 2));
|
||||
EN := StrToInt(Copy(S, 15, 2));
|
||||
ES := StrToInt(Copy(S, 18, 2));
|
||||
}
|
||||
if (EY = 0) or (EM = 0) or (ED = 0) then
|
||||
Result := 0
|
||||
else
|
||||
@ -723,28 +729,34 @@ end;
|
||||
function TMySQLDataset.InternalStrToTime(S: string): TDateTime;
|
||||
|
||||
var
|
||||
EH, EM, ES: Word;
|
||||
EH, EM, ES: Longint;
|
||||
|
||||
begin
|
||||
SScanf(S,'%d:%d:%d',[@EH,@EM,@ES]);
|
||||
{
|
||||
EH := StrToInt(Copy(S, 1, 2));
|
||||
EM := StrToInt(Copy(S, 4, 2));
|
||||
ES := StrToInt(Copy(S, 7, 2));
|
||||
}
|
||||
Result := EncodeTime(EH, EM, ES, 0);
|
||||
end;
|
||||
|
||||
function TMySQLDataset.InternalStrToTimeStamp(S: string): TDateTime;
|
||||
|
||||
var
|
||||
EY, EM, ED: Word;
|
||||
EH, EN, ES: Word;
|
||||
EY, EM, ED: longint;
|
||||
EH, EN, ES: longint;
|
||||
|
||||
begin
|
||||
SScanf(S,'%d-%d-%d %d:%d:%d',[@EY,@EM,@ED,@EH,@EN,@ES]);
|
||||
{
|
||||
EY := StrToInt(Copy(S, 1, 4));
|
||||
EM := StrToInt(Copy(S, 5, 2));
|
||||
ED := StrToInt(Copy(S, 7, 2));
|
||||
EH := StrToInt(Copy(S, 9, 2));
|
||||
EN := StrToInt(Copy(S, 11, 2));
|
||||
ES := StrToInt(Copy(S, 13, 2));
|
||||
}
|
||||
if (EY = 0) or (EM = 0) or (ED = 0) then
|
||||
Result := 0
|
||||
else
|
||||
|
@ -2074,12 +2074,28 @@ function sscanf(const s: string; const fmt : string;const Pointers : array of Po
|
||||
i,j,n,m : SizeInt;
|
||||
s1 : string;
|
||||
|
||||
function GetInt : Integer;
|
||||
function GetInt(unsigned : boolean=false) : Integer;
|
||||
begin
|
||||
s1 := '';
|
||||
while (s[n] = ' ') and (Length(s) > n) do
|
||||
inc(n);
|
||||
while (s[n] in ['0'..'9', '+', '-'])
|
||||
{ read sign }
|
||||
if (Length(s)>= n) and (s[n] in ['+', '-']) then
|
||||
begin
|
||||
{ don't accept - when reading unsigned }
|
||||
if unsigned and (s[n]='-') then
|
||||
begin
|
||||
result:=length(s1);
|
||||
exit;
|
||||
end
|
||||
else
|
||||
begin
|
||||
s1:=s1+s[n];
|
||||
inc(n);
|
||||
end;
|
||||
end;
|
||||
{ read numbers }
|
||||
while (s[n] in ['0'..'9'])
|
||||
and (Length(s) >= n) do
|
||||
begin
|
||||
s1 := s1+s[n];
|
||||
|
Loading…
Reference in New Issue
Block a user