Changeset 6 for trunk/UDatabase.pas


Ignore:
Timestamp:
Jan 20, 2015, 12:31:24 AM (10 years ago)
Author:
chronos
Message:
  • Added: Allow to create multiple database connections and set their parmaters.
  • Added: Defined database engines to support various database backends. Each supports different set of field data types.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UDatabase.pas

    r4 r6  
    1010type
    1111  TTable = class;
     12  TDatabaseEngine = class;
    1213
    1314  TFieldType = (ftString, ftInteger, ftDateTime, ftBoolean, ftFloat, ftImage,
     
    109110    Tables: TTables;
    110111    ConnectionString: string;
     112    Engine: TDatabaseEngine;
    111113    constructor Create;
    112114    destructor Destroy; override;
     
    115117  end;
    116118
     119  TDatabases = class(TObjectList)
     120
     121  end;
     122
     123  TDatabaseClass = class of TDatabase;
     124
     125  { TDataType }
     126
     127  TDataType = class
     128    Name: string;
     129    FieldType: TFieldType;
     130  end;
     131
     132  TDataTypes = class(TObjectList)
     133    function RegisterType(Name: string; FieldType: TFieldType): TDataType;
     134  end;
     135
     136  { TDatabaseEngine }
     137
     138  TDatabaseEngine = class
     139    Name: string;
     140    DataTypes: TDataTypes;
     141    DatabaseClass: TDatabaseClass;
     142    constructor Create;
     143    destructor Destroy; override;
     144  end;
     145
     146  { TDatabaseEngines }
     147
     148  TDatabaseEngines = class(TObjectList)
     149    function RegisterEngine(Name: string; DatabaseClass: TDatabaseClass): TDatabaseEngine;
     150    function FindByName(Name: string): TDatabaseEngine;
     151  end;
     152
    117153
    118154implementation
     
    120156uses
    121157  UDataTypes;
     158
     159{ TDatabaseEngines }
     160
     161function TDatabaseEngines.RegisterEngine(Name: string;
     162  DatabaseClass: TDatabaseClass): TDatabaseEngine;
     163begin
     164  Result := TDatabaseEngine.Create;
     165  Result.Name := Name;
     166  Result.DatabaseClass := DatabaseClass;
     167  Add(Result);
     168end;
     169
     170function TDatabaseEngines.FindByName(Name: string): TDatabaseEngine;
     171var
     172  I: Integer;
     173begin
     174  I := 0;
     175  while (I < Count) and (TDatabaseEngine(Items[I]).Name <> Name) do Inc(I);
     176  if I < Count then Result := TDatabaseEngine(Items[I])
     177    else Result := nil;
     178end;
     179
     180{ TDataTypes }
     181
     182function TDataTypes.RegisterType(Name: string; FieldType: TFieldType): TDataType;
     183begin
     184  Result := TDataType.Create;
     185  Result.Name := Name;
     186  Result.FieldType := FieldType;
     187  Add(Result);
     188end;
     189
     190{ TDatabaseEngine }
     191
     192constructor TDatabaseEngine.Create;
     193begin
     194  DataTypes := TDataTypes.Create;
     195end;
     196
     197destructor TDatabaseEngine.Destroy;
     198begin
     199  DataTypes.Free;
     200  inherited Destroy;
     201end;
    122202
    123203{ TValues }
Note: See TracChangeset for help on using the changeset viewer.