Ignore:
Timestamp:
Sep 13, 2010, 11:20:24 AM (14 years ago)
Author:
george
Message:
  • Přidáno: Druhá varianta projektu pro sestavení TCP serveru.
  • Přidáno: Vlastní obsluha vyjímek a zobrazení ve HTTP tvaru.
  • Opraveno: Zpracování session třídy THTTPSessionStorageMySQL.
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        22UConfig.pas
        33bin
         4lib
  • trunk/Common/USqlDatabase.pas

    r25 r33  
    5252    function GetLastErrorMessage: string;
    5353    function GetLastErrorNumber: Integer;
    54     function CheckError: Boolean;
    5554    function GetCharset: string;
    5655    procedure SetDatabase(const Value: string);
     
    9190implementation
    9291
    93 uses DateUtils, Math;
     92uses
     93  DateUtils, Math;
     94
     95resourcestring
     96  SDatabaseQueryError = 'Database query error: "%s"';
    9497
    9598const
     
    172175    FSession := NewSession;
    173176  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;
    177186end;
    178187
     
    197206  System.Delete(DbNames, 1, 1);
    198207  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;
    201213end;
    202214
     
    210222  RepeatLastAction := False;
    211223  LastQuery := Data;
    212   //if not Connected then NastaveniPripojeni.ShowModal;
    213224  Result := TDbRows.Create;
    214   //repeat
    215225  mysql_query(FSession, PChar(Data));
    216   //until not
    217   CheckError;
    218   //if not CheckError then
    219   begin
    220     DbResult := mysql_store_result(FSession);
    221     if Assigned(DbResult) then begin
    222       Result.Count := mysql_num_rows(DbResult);
    223       for I := 0 to Result.Count - 1 do begin
    224         DbRow := mysql_fetch_row(DbResult);
    225         Result[I] := TAssociativeArray.Create;
    226         with Result[I] do begin
    227           for II := 0 to mysql_num_fields(DbResult) - 1 do begin
    228             Add(mysql_fetch_field_direct(DbResult, II)^.Name +
    229               NameValueSeparator + PChar((DbRow + II)^));
     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)^));
    230240          end;
    231241        end;
    232242      end;
    233     end;
    234243  end;
    235244  mysql_free_result(DbResult);
    236   (*
    237   if Assigned(DatabaseIntegrity) then
    238   with DatabaseIntegrity do if not Checking then begin
    239     Check;
    240     DebugLog('Database integrity: Unreferenced='+IntToStr(Unreferenced)+' BadReferences='+IntToStr(BadReferences));
    241   end;
    242   *)
    243245end;
    244246
     
    263265  System.Delete(DbNames, 1, 1);
    264266  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;
    267272end;
    268273
     
    270275begin
    271276  Table := ATable;
    272   Result := Query('SELECT ' + Filter + ' FROM `' + Table + '` WHERE '+Condition);
     277  Result := Query('SELECT ' + Filter + ' FROM `' + Table + '` WHERE ' + Condition);
    273278end;
    274279
     
    289294  end;
    290295  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;
    293301end;
    294302
     
    303311begin
    304312  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;
    307318end;
    308319
     
    338349begin
    339350  Result := mysql_errno(FSession);
    340 end;
    341 
    342 function TSqlDatabase.CheckError: Boolean;
    343 begin
    344   Result := LastErrorNumber <> 0;
    345   if Result then
    346     raise EQueryError.Create('Database query error: "' + LastErrorMessage + '"');
    347351end;
    348352
Note: See TracChangeset for help on using the changeset viewer.