Ignore:
Timestamp:
Sep 8, 2010, 8:34:15 PM (14 years ago)
Author:
george
Message:
  • Opraveno: Zobrazování jednotlivých stránek.
  • Opraveno: Zobrazení výpisu historie sítě.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/lazarus/Common/USqlDatabase.pas

    r23 r25  
    22
    33{$mode Delphi}{$H+}
    4 // Upraveno: 16.12.2009
     4
     5// Upraveno: 8.9.2010
    56
    67interface
    78
    89uses
    9   SysUtils, Classes, Dialogs, mysql50, TypInfo;
     10  SysUtils, Classes, Dialogs, mysql50, TypInfo, Contnrs, UStringListEx;
    1011
    1112type
    12   EQueryError = Exception;
     13  EQueryError = class(Exception);
    1314
    1415  TClientCapabilities = (_CLIENT_LONG_PASSWORD, _CLIENT_FOUND_ROWS,
     
    3334  end;
    3435
    35   TDbRows = class(TList)
     36  TDbRows = class(TObjectList)
    3637  private
    3738    function GetData(Index: Integer): TAssociativeArray;
     
    8586  function MySQLFloatToStr(F: Real): string;
    8687  function MySQLStrToFloat(S: string): Real;
     88  function SQLToDateTime(Value: string): TDateTime;
     89  function DateTimeToSQL(Value: TDateTime): string;
    8790
    8891implementation
     
    110113begin
    111114  S := FloatToStr(F);
    112   if Pos(',', S) > 0 then S[Pos(',',S)] := '.';
     115  if Pos(',', S) > 0 then S[Pos(',', S)] := '.';
    113116  Result := S;
    114117end;
     
    116119function MySQLStrToFloat(S: string): Real;
    117120begin
    118   if Pos('.', S) > 0 then  S[Pos('.',S)] := ',';
     121  if Pos('.', S) > 0 then S[Pos('.', S)] := ',';
    119122  Result := StrToFloat(S);
     123end;
     124
     125function SQLToDateTime(Value: string): TDateTime;
     126var
     127  Parts: TStringListEx;
     128  DateParts: TStringListEx;
     129  TimeParts: TStringListEx;
     130begin
     131  try
     132    Parts := TStringListEx.Create;
     133    DateParts := TStringListEx.Create;
     134    TimeParts := TStringListEx.Create;
     135
     136    Parts.Explode(' ', Value);
     137    DateParts.Explode('-', Parts[0]);
     138    Result := EncodeDate(StrToInt(DateParts[0]), StrToInt(DateParts[1]),
     139      StrToInt(DateParts[2]));
     140    if Parts.Count > 1 then begin
     141      TimeParts.Explode(':', Parts[1]);
     142      Result := Result + EncodeTime(StrToInt(TimeParts[0]), StrToInt(TimeParts[1]),
     143        StrToInt(TimeParts[2]), 0);
     144    end;
     145  finally
     146    DateParts.Free;
     147    TimeParts.Free;
     148    Parts.Free;
     149  end;
     150end;
     151
     152function DateTimeToSQL(Value: TDateTime): string;
     153begin
     154  Result := FormatDateTime('yyyy-mm-dd hh.nn.ss', Value);
    120155end;
    121156
     
    401436
    402437destructor TDbRows.Destroy;
    403 var
    404   I: Integer;
    405 begin
    406   for I := 0 to Count - 1 do
    407     Data[I].Free;
     438begin
    408439  inherited;
    409440end;
     
    411442function TDbRows.GetData(Index: Integer): TAssociativeArray;
    412443begin
    413   Result := Items[Index];
     444  Result := TAssociativeArray(Items[Index]);
    414445end;
    415446
Note: See TracChangeset for help on using the changeset viewer.