Changeset 33 for trunk/Common/USqlDatabase.pas
- Timestamp:
- Sep 13, 2010, 11:20:24 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 2 2 UConfig.pas 3 3 bin 4 lib
-
- Property svn:ignore
-
trunk/Common/USqlDatabase.pas
r25 r33 52 52 function GetLastErrorMessage: string; 53 53 function GetLastErrorNumber: Integer; 54 function CheckError: Boolean;55 54 function GetCharset: string; 56 55 procedure SetDatabase(const Value: string); … … 91 90 implementation 92 91 93 uses DateUtils, Math; 92 uses 93 DateUtils, Math; 94 95 resourcestring 96 SDatabaseQueryError = 'Database query error: "%s"'; 94 97 95 98 const … … 172 175 FSession := NewSession; 173 176 end else FConnected := False; 174 CheckError; 175 Rows := Query('SET NAMES ' + Encoding); 176 Rows.Free; 177 178 if LastErrorNumber <> 0 then 179 raise EQueryError.Create(Format(SDatabaseQueryError, [LastErrorMessage])); 180 181 try 182 Rows := Query('SET NAMES ' + Encoding); 183 finally 184 Rows.Free; 185 end; 177 186 end; 178 187 … … 197 206 System.Delete(DbNames, 1, 1); 198 207 System.Delete(DbValues, 1, 1); 199 DbResult := Query('INSERT INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 200 DbResult.Free; 208 try 209 DbResult := Query('INSERT INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 210 finally 211 DbResult.Free; 212 end; 201 213 end; 202 214 … … 210 222 RepeatLastAction := False; 211 223 LastQuery := Data; 212 //if not Connected then NastaveniPripojeni.ShowModal;213 224 Result := TDbRows.Create; 214 //repeat215 225 mysql_query(FSession, PChar(Data)); 216 //until not217 CheckError;218 //if not CheckError then219 begin 220 221 222 223 224 225 226 227 228 229 226 if LastErrorNumber <> 0 then begin 227 raise EQueryError.Create(Format(SDatabaseQueryError, [Data])); 228 end; 229 230 DbResult := mysql_store_result(FSession); 231 if Assigned(DbResult) then begin 232 Result.Count := mysql_num_rows(DbResult); 233 for I := 0 to Result.Count - 1 do begin 234 DbRow := mysql_fetch_row(DbResult); 235 Result[I] := TAssociativeArray.Create; 236 with Result[I] do begin 237 for II := 0 to mysql_num_fields(DbResult) - 1 do begin 238 Add(mysql_fetch_field_direct(DbResult, II)^.Name + 239 NameValueSeparator + PChar((DbRow + II)^)); 230 240 end; 231 241 end; 232 242 end; 233 end;234 243 end; 235 244 mysql_free_result(DbResult); 236 (*237 if Assigned(DatabaseIntegrity) then238 with DatabaseIntegrity do if not Checking then begin239 Check;240 DebugLog('Database integrity: Unreferenced='+IntToStr(Unreferenced)+' BadReferences='+IntToStr(BadReferences));241 end;242 *)243 245 end; 244 246 … … 263 265 System.Delete(DbNames, 1, 1); 264 266 System.Delete(DbValues, 1, 1); 265 DbResult := Query('REPLACE INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 266 DbResult.Free; 267 try 268 DbResult := Query('REPLACE INTO `' + Table + '` (' + DbNames + ') VALUES (' + DbValues + ')'); 269 finally 270 DbResult.Free; 271 end; 267 272 end; 268 273 … … 270 275 begin 271 276 Table := ATable; 272 Result := Query('SELECT ' + Filter + ' FROM `' + Table + '` WHERE ' +Condition);277 Result := Query('SELECT ' + Filter + ' FROM `' + Table + '` WHERE ' + Condition); 273 278 end; 274 279 … … 289 294 end; 290 295 System.Delete(DbValues, 1, 1); 291 DbResult := Query('UPDATE `' + Table + '` SET (' + DbValues + ') WHERE ' + Condition); 292 DbResult.Free; 296 try 297 DbResult := Query('UPDATE `' + Table + '` SET (' + DbValues + ') WHERE ' + Condition); 298 finally 299 DbResult.Free; 300 end; 293 301 end; 294 302 … … 303 311 begin 304 312 Table := ATable; 305 DbResult := Query('DELETE FROM `' + Table + '` WHERE ' + Condition); 306 DbResult.Free; 313 try 314 DbResult := Query('DELETE FROM `' + Table + '` WHERE ' + Condition); 315 finally 316 DbResult.Free; 317 end; 307 318 end; 308 319 … … 338 349 begin 339 350 Result := mysql_errno(FSession); 340 end;341 342 function TSqlDatabase.CheckError: Boolean;343 begin344 Result := LastErrorNumber <> 0;345 if Result then346 raise EQueryError.Create('Database query error: "' + LastErrorMessage + '"');347 351 end; 348 352
Note:
See TracChangeset
for help on using the changeset viewer.