Changeset 35 for Network/MysqlClient/USqlDatabase.pas
- Timestamp:
- Jul 1, 2010, 2:11:01 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Network/MysqlClient/USqlDatabase.pas
r33 r35 1 1 unit USqlDatabase; 2 2 3 // Upraveno: 24.2.2008 3 {$mode Delphi}{$H+} 4 // Upraveno: 16.12.2009 4 5 5 6 interface 6 7 7 8 uses 8 SysUtils, Classes, Dialogs, mysql , TypInfo;9 SysUtils, Classes, Dialogs, mysql50, TypInfo; 9 10 10 11 type 12 EQueryError = Exception; 13 11 14 TClientCapabilities = (_CLIENT_LONG_PASSWORD, _CLIENT_FOUND_ROWS, 12 15 _CLIENT_LONG_FLAG, _CLIENT_CONNECT_WITH_DB, _CLIENT_NO_SCHEMA, … … 44 47 FSession: PMYSQL; 45 48 FConnected: Boolean; 46 FOnError: TNotifyEvent;47 49 FDatabase: string; 48 50 function GetConnected: Boolean; … … 57 59 UserName: string; 58 60 Password: string; 61 Encoding: string; 59 62 Table: string; 60 63 RepeatLastAction: Boolean; … … 75 78 property LastErrorNumber: Integer read GetLastErrorNumber; 76 79 property Connected: Boolean read GetConnected; 77 property OnError: TNotifyEvent read FOnError write FOnError;78 80 constructor Create; 79 81 destructor Destroy; override; … … 111 113 begin 112 114 S := FloatToStr(F); 113 if Pos(',', S) > 0 then S[Pos(',',S)] := '.';115 if Pos(',', S) > 0 then S[Pos(',',S)] := '.'; 114 116 Result := S; 115 117 end; … … 117 119 function MySQLStrToFloat(S: string): Real; 118 120 begin 119 if Pos('.', S) > 0 thenS[Pos('.',S)] := ',';121 if Pos('.', S) > 0 then S[Pos('.',S)] := ','; 120 122 Result := StrToFloat(S); 121 123 end; … … 137 139 end else FConnected := False; 138 140 CheckError; 139 Rows := Query('SET NAMES cp1250');141 Rows := Query('SET NAMES ' + Encoding); 140 142 Rows.Free; 141 143 end; … … 152 154 DbNames := ''; 153 155 DbValues := ''; 154 for I := 0 to Data.Count -1 do begin156 for I := 0 to Data.Count - 1 do begin 155 157 Value := Data.ValuesAtIndex[I]; 156 158 StringReplace(Value, '"', '\"', [rfReplaceAll]); … … 169 171 I, II: Integer; 170 172 DbResult: PMYSQL_RES; 171 DbRow: PMYSQL_ROW;173 DbRow: MYSQL_ROW; 172 174 begin 173 175 //DebugLog('SqlDatabase query: '+Data); … … 185 187 if Assigned(DbResult) then begin 186 188 Result.Count := mysql_num_rows(DbResult); 187 for I := 0 to Result.Count -1 do begin189 for I := 0 to Result.Count - 1 do begin 188 190 DbRow := mysql_fetch_row(DbResult); 189 191 Result[I] := TAssociativeArray.Create; 190 192 with Result[I] do begin 191 for II := 0 to mysql_num_fields(DbResult)-1 do begin 192 Add(mysql_fetch_field_direct(DbResult, II)^.name + NameValueSeparator + DbRow^[II]); 193 for II := 0 to mysql_num_fields(DbResult) - 1 do begin 194 Add(mysql_fetch_field_direct(DbResult, II)^.Name + 195 NameValueSeparator + PChar((DbRow + II)^)); 193 196 end; 194 197 end; … … 217 220 DbNames := ''; 218 221 DbValues := ''; 219 for I := 0 to Data.Count -1 do begin222 for I := 0 to Data.Count - 1 do begin 220 223 Value := Data.ValuesAtIndex[I]; 221 224 StringReplace(Value, '"', '\"', [rfReplaceAll]); … … 245 248 Table := ATable; 246 249 DbValues := ''; 247 for I := 0 to Data.Count -1 do begin250 for I := 0 to Data.Count - 1 do begin 248 251 Value := Data.ValuesAtIndex[I]; 249 252 StringReplace(Value, '"', '\"', [rfReplaceAll]); … … 283 286 begin 284 287 Result := ''; 285 for I := 0 to Count -1 do begin288 for I := 0 to Count - 1 do begin 286 289 Result := Result + Names[I] + '=' + ValuesAtIndex[I] + ','; 287 290 end; … … 319 322 inherited; 320 323 FSession := nil; 324 Encoding := 'utf8'; 321 325 end; 322 326 … … 332 336 I: Integer; 333 337 begin 334 for I := 0 to Count - 1 do Data[I].Free; 338 for I := 0 to Count - 1 do 339 Data[I].Free; 335 340 inherited; 336 341 end; … … 364 369 begin 365 370 Result := LastErrorNumber <> 0; 366 if Result and Assigned(OnError) then OnError(Self); 371 if Result then 372 raise EQueryError.Create('Database query error: "' + LastErrorMessage + '"'); 367 373 end; 368 374 … … 380 386 381 387 procedure TSqlDatabase.CreateTable(Name: string); 382 begin 383 Query('CREATE TABLE `' + Name + '`' + 384 ' (`id` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`));'); 388 var 389 DbRows: TDbRows; 390 begin 391 DbRows := Query('CREATE TABLE `' + Name + '`' + 392 ' (`Id` INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (`Id`));'); 393 DbRows.Destroy; 385 394 end; 386 395
Note:
See TracChangeset
for help on using the changeset viewer.