#1 2023-11-14 08:00:03

sgavrilov
Member
Registered: 2019-05-24
Posts: 20

'stored AS_UNIQUE' and OrmMapExternal

Hello,

Environment: Delphi XE2, TRestServerDB, SQLite3 database, 4 tables in a model, a table has a field defined as 'stored AS_UNIQUE'.

If the database is created in the constructor of the server

  server := TRestServerDB.Create(aModel, 'c:\temp\test.db', False);
  server.Server.CreateMissingTables;

then everything works as expected: the uniqueness index is created in the test.db.

But if connection properties and the OrmMapExternal are used

  aConnProps := TSQLDBSQLite3ConnectionProperties.Create('c:\temp\test.db', '', '', '');
  ...
  OrmMapExternal(aModel, [ list of tables ], aConnProps);

  server := TRestServerDB.Create(aModel, SQLITE_MEMORY_DATABASE_NAME, False);
  server.Server.CreateMissingTables;

then no index for 'AS_UNIQUE' field is created. It does not matter if the target database is SQLIte3 or MS SQL.

Best regards,
Sergey

Offline

#2 2023-11-29 08:26:15

sgavrilov
Member
Registered: 2019-05-24
Posts: 20

Re: 'stored AS_UNIQUE' and OrmMapExternal

Well, it appears that I was inattentive and looked in a wrong place...

I did not pay attention to the 'sqlite_autoindex_*' indexes. The SQLite automatically creates them during the table creation. So, the 'stored AS_UNIQUE' indexes are indeed created.

Actually, often duplicate indexes are created as well: 'sqlite_autoindex_*' (unique) and 'NDX{Table}{Field}' (non-unique). I suppose that the former are created by the SQLIte and the latter - by the mORMot.
And the same happens if a table is mapped to a MS SQL server: 'UO_{Table}_*' (unique) and 'NDX{Table}{Field}' (non-unique).

I apologize for the confusion.

Sergey

Offline

Board footer

Powered by FluxBB