mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-07 06: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;
|
function TMySQLDataset.InternalStrToDate(S: string): TDateTime;
|
||||||
|
|
||||||
var
|
var
|
||||||
EY, EM, ED: Word;
|
EY, EM, ED: Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
SScanf(S,'%d-%d-%d',[@EY,@EM,@ED]);
|
||||||
|
{
|
||||||
EY := StrToInt(Copy(S,1,4));
|
EY := StrToInt(Copy(S,1,4));
|
||||||
EM := StrToInt(Copy(S,6,2));
|
EM := StrToInt(Copy(S,6,2));
|
||||||
ED := StrToInt(Copy(S,9,2));
|
ED := StrToInt(Copy(S,9,2));
|
||||||
|
}
|
||||||
if (EY = 0) or (EM = 0) or (ED = 0) then
|
if (EY = 0) or (EM = 0) or (ED = 0) then
|
||||||
Result:=0
|
Result:=0
|
||||||
else
|
else
|
||||||
@ -703,16 +706,19 @@ end;
|
|||||||
function TMySQLDataset.InternalStrToDateTime(S: string): TDateTime;
|
function TMySQLDataset.InternalStrToDateTime(S: string): TDateTime;
|
||||||
|
|
||||||
var
|
var
|
||||||
EY, EM, ED: Word;
|
EY, EM, ED: Longint;
|
||||||
EH, EN, ES: Word;
|
EH, EN, ES: Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
SScanf(S,'%d-%d-%d %d:%d:%d',[@EY,@EM,@ED,@EH,@EN,@ES]);
|
||||||
|
{
|
||||||
EY := StrToInt(Copy(S, 1, 4));
|
EY := StrToInt(Copy(S, 1, 4));
|
||||||
EM := StrToInt(Copy(S, 6, 2));
|
EM := StrToInt(Copy(S, 6, 2));
|
||||||
ED := StrToInt(Copy(S, 9, 2));
|
ED := StrToInt(Copy(S, 9, 2));
|
||||||
EH := StrToInt(Copy(S, 12, 2));
|
EH := StrToInt(Copy(S, 12, 2));
|
||||||
EN := StrToInt(Copy(S, 15, 2));
|
EN := StrToInt(Copy(S, 15, 2));
|
||||||
ES := StrToInt(Copy(S, 18, 2));
|
ES := StrToInt(Copy(S, 18, 2));
|
||||||
|
}
|
||||||
if (EY = 0) or (EM = 0) or (ED = 0) then
|
if (EY = 0) or (EM = 0) or (ED = 0) then
|
||||||
Result := 0
|
Result := 0
|
||||||
else
|
else
|
||||||
@ -723,28 +729,34 @@ end;
|
|||||||
function TMySQLDataset.InternalStrToTime(S: string): TDateTime;
|
function TMySQLDataset.InternalStrToTime(S: string): TDateTime;
|
||||||
|
|
||||||
var
|
var
|
||||||
EH, EM, ES: Word;
|
EH, EM, ES: Longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
SScanf(S,'%d:%d:%d',[@EH,@EM,@ES]);
|
||||||
|
{
|
||||||
EH := StrToInt(Copy(S, 1, 2));
|
EH := StrToInt(Copy(S, 1, 2));
|
||||||
EM := StrToInt(Copy(S, 4, 2));
|
EM := StrToInt(Copy(S, 4, 2));
|
||||||
ES := StrToInt(Copy(S, 7, 2));
|
ES := StrToInt(Copy(S, 7, 2));
|
||||||
|
}
|
||||||
Result := EncodeTime(EH, EM, ES, 0);
|
Result := EncodeTime(EH, EM, ES, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TMySQLDataset.InternalStrToTimeStamp(S: string): TDateTime;
|
function TMySQLDataset.InternalStrToTimeStamp(S: string): TDateTime;
|
||||||
|
|
||||||
var
|
var
|
||||||
EY, EM, ED: Word;
|
EY, EM, ED: longint;
|
||||||
EH, EN, ES: Word;
|
EH, EN, ES: longint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
SScanf(S,'%d-%d-%d %d:%d:%d',[@EY,@EM,@ED,@EH,@EN,@ES]);
|
||||||
|
{
|
||||||
EY := StrToInt(Copy(S, 1, 4));
|
EY := StrToInt(Copy(S, 1, 4));
|
||||||
EM := StrToInt(Copy(S, 5, 2));
|
EM := StrToInt(Copy(S, 5, 2));
|
||||||
ED := StrToInt(Copy(S, 7, 2));
|
ED := StrToInt(Copy(S, 7, 2));
|
||||||
EH := StrToInt(Copy(S, 9, 2));
|
EH := StrToInt(Copy(S, 9, 2));
|
||||||
EN := StrToInt(Copy(S, 11, 2));
|
EN := StrToInt(Copy(S, 11, 2));
|
||||||
ES := StrToInt(Copy(S, 13, 2));
|
ES := StrToInt(Copy(S, 13, 2));
|
||||||
|
}
|
||||||
if (EY = 0) or (EM = 0) or (ED = 0) then
|
if (EY = 0) or (EM = 0) or (ED = 0) then
|
||||||
Result := 0
|
Result := 0
|
||||||
else
|
else
|
||||||
|
@ -2074,12 +2074,28 @@ function sscanf(const s: string; const fmt : string;const Pointers : array of Po
|
|||||||
i,j,n,m : SizeInt;
|
i,j,n,m : SizeInt;
|
||||||
s1 : string;
|
s1 : string;
|
||||||
|
|
||||||
function GetInt : Integer;
|
function GetInt(unsigned : boolean=false) : Integer;
|
||||||
begin
|
begin
|
||||||
s1 := '';
|
s1 := '';
|
||||||
while (s[n] = ' ') and (Length(s) > n) do
|
while (s[n] = ' ') and (Length(s) > n) do
|
||||||
inc(n);
|
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
|
and (Length(s) >= n) do
|
||||||
begin
|
begin
|
||||||
s1 := s1+s[n];
|
s1 := s1+s[n];
|
||||||
|
Loading…
Reference in New Issue
Block a user