Changeset 25 for branches/lazarus/Common/USqlDatabase.pas
- Timestamp:
- Sep 8, 2010, 8:34:15 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/lazarus/Common/USqlDatabase.pas
r23 r25 2 2 3 3 {$mode Delphi}{$H+} 4 // Upraveno: 16.12.2009 4 5 // Upraveno: 8.9.2010 5 6 6 7 interface 7 8 8 9 uses 9 SysUtils, Classes, Dialogs, mysql50, TypInfo ;10 SysUtils, Classes, Dialogs, mysql50, TypInfo, Contnrs, UStringListEx; 10 11 11 12 type 12 EQueryError = Exception;13 EQueryError = class(Exception); 13 14 14 15 TClientCapabilities = (_CLIENT_LONG_PASSWORD, _CLIENT_FOUND_ROWS, … … 33 34 end; 34 35 35 TDbRows = class(T List)36 TDbRows = class(TObjectList) 36 37 private 37 38 function GetData(Index: Integer): TAssociativeArray; … … 85 86 function MySQLFloatToStr(F: Real): string; 86 87 function MySQLStrToFloat(S: string): Real; 88 function SQLToDateTime(Value: string): TDateTime; 89 function DateTimeToSQL(Value: TDateTime): string; 87 90 88 91 implementation … … 110 113 begin 111 114 S := FloatToStr(F); 112 if Pos(',', S) > 0 then S[Pos(',', S)] := '.';115 if Pos(',', S) > 0 then S[Pos(',', S)] := '.'; 113 116 Result := S; 114 117 end; … … 116 119 function MySQLStrToFloat(S: string): Real; 117 120 begin 118 if Pos('.', S) > 0 then S[Pos('.',S)] := ',';121 if Pos('.', S) > 0 then S[Pos('.', S)] := ','; 119 122 Result := StrToFloat(S); 123 end; 124 125 function SQLToDateTime(Value: string): TDateTime; 126 var 127 Parts: TStringListEx; 128 DateParts: TStringListEx; 129 TimeParts: TStringListEx; 130 begin 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; 150 end; 151 152 function DateTimeToSQL(Value: TDateTime): string; 153 begin 154 Result := FormatDateTime('yyyy-mm-dd hh.nn.ss', Value); 120 155 end; 121 156 … … 401 436 402 437 destructor TDbRows.Destroy; 403 var 404 I: Integer; 405 begin 406 for I := 0 to Count - 1 do 407 Data[I].Free; 438 begin 408 439 inherited; 409 440 end; … … 411 442 function TDbRows.GetData(Index: Integer): TAssociativeArray; 412 443 begin 413 Result := Items[Index];444 Result := TAssociativeArray(Items[Index]); 414 445 end; 415 446
Note:
See TracChangeset
for help on using the changeset viewer.