Using more than one SQLite database file with Aure

Hello Support Team,

following scenario:

Database is SQLite, MDI application: One database file for common application data, several database files for projects (one per MDI child). Both files have different tables and structures (maybe same table names).

It's mandatory to create both application data base file and MDI database file during runtime.
What I found out is that if AutoSearchMappedClasses is true database creation fails because all entities will be uses for both database file types, particularly if I use identical table names. Furthermore all tables will be created in all database file types.

To avoid this I set AutoSearchMappedClasses to false, added table prefixes 'ct' for common table and 'pt' for project tables.

Then I have added modified the Un-/Register procedures like this:

procedure TDM.RegisterCommonClasses;
var
  EntityClassList: TList<TClass>;
  EntityClass: TClass;
begin
  EntityClassList := TList<TClass>.Create;
  try
    GetEntityClasses(EntityClassList);
    for EntityClass in EntityClassList do
      if Copy(EntityClass.ClassName, 1, 3) = cPrefixCommonTable
        then TMappedClasses.GetInstance.RegisterClass(EntityClass);
  finally
    EntityClassList.Free;
  end;
end;

procedure TDM.UnregisterCommonClasses;
var
  EntityClassList: TList<TClass>;
  EntityClass: TClass;
begin
  EntityClassList := TList<TClass>.Create;
  try
    GetEntityClasses(EntityClassList);
    for EntityClass in EntityClassList do
      if Copy(EntityClass.ClassName, 1, 3) = cPrefixCommonTable
        then TMappedClasses.GetInstance.UnregisterClass(EntityClass);
  finally
    EntityClassList.Free;
  end;
end;

procedure TDM.RegisterProjectClasses;
var
  EntityClassList: TList<TClass>;
  EntityClass: TClass;
begin
  EntityClassList := TList<TClass>.Create;
  try
    GetEntityClasses(EntityClassList);
    for EntityClass in EntityClassList do
      if Copy(EntityClass.ClassName, 1, 3) = cPrefixProjectTable
        then TMappedClasses.GetInstance.RegisterClass(EntityClass);
  finally
    EntityClassList.Free;
  end;
end;

procedure TDM.UnregisterProjectClasses;
var
  EntityClassList: TList<TClass>;
  EntityClass: TClass;
begin
  EntityClassList := TList<TClass>.Create;
  try
    GetEntityClasses(EntityClassList);
    for EntityClass in EntityClassList do
      if Copy(EntityClass.ClassName, 1, 3) = cPrefixProjectTable
        then TMappedClasses.GetInstance.UnregisterClass(EntityClass);
  finally
    EntityClassList.Free;
  end;
end;

As a last step I have added manual registering for my common database file

  RegisterCommonClasses;
  ...
  DatabaseManager := TDatabaseManager.Create(FConnection);
  ...
  DatabaseManager.BuildDatabase;
  ...

and finally for the project database file:

  UnregisterCommonClasses;
  RegisterProjectClasses;
  ...
  DatabaseManager := TDatabaseManager.Create(FConnection);
  ...
  DatabaseManager.BuildDatabase;
  ...

As far as I can see it woks fine but maybe something can be added in future versions to simplify it.
Thanks in advance.

Regards,
Matthias

Hello,

I have exactly the same problem. Two databases with different tables in each of them.

Could we get some built-in solution for this in some future Aurelius version?

Thanks


Any news on this?

We have since this created the TMappingSetup (see mapping setup in manual) that holds mapping information. We are slowly adding features to this mapping setup - currently only dynamic properties are provided, but soon we will allow different classes to be added to each setup.