#1 2015-05-17 22:00:39

GetCoffee
Member
Registered: 2014-09-20
Posts: 9

CreateSQLIndex and external db.

Ok, the code.

	FModel := TSQLModel.Create([TModelUser]);
	VirtualTableExternalRegister(FModel, TModelUser, FOwner.ConnectionProperties);
	FServer := TSQLRestServerDB.Create(FModel, SQLITE_MEMORY_DATABASE_NAME);
	GetRestServerDb.CreateSQLIndex(TModelUser, ['UserName'], True);
	GetRestServerDb.CreateMissingTables;

Where FOwner.ConnectionProperties is a connection property to postgresql server.

When i try to create the index i get:

Project Shell.exe raised exception class ESQLite3Exception with message 'Error SQLITE_ERROR (1) using 3.8.9 - 'no such table: main.ModelUser' extended_errcode=1'.

Is this a known issue?

Thanks in advance.

------

Solved:

Just reverse the last two lines. ;)

Offline

#2 2015-05-17 22:18:28

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: CreateSQLIndex and external db.

Yes, it does make sense to create the indexes once the tables are created, right?

You should better create the index in TSqlRecord.InitializeTable itself.
This class virtual method will be executed in the proper place, during initialization.

See e.g.

class procedure TSQLArticle.InitializeTable(Server: TSQLRestServer;
  const FieldName: RawUTF8; Options: TSQLInitializeTableOptions);
begin
  inherited;
  if (FieldName='') or (FieldName='PublishedMonth') then
    Server.CreateSQLIndex(TSQLArticle,'PublishedMonth',false);
end;

http://synopse.info/files/html/Synopse% … #TITLE_468

Offline

#3 2015-05-18 16:04:59

GetCoffee
Member
Registered: 2014-09-20
Posts: 9

Re: CreateSQLIndex and external db.

Sure. I`m just new to mORMot.

Thanks.

Offline

#4 2015-05-18 16:37:58

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: CreateSQLIndex and external db.

You are welcome!

There is so much to discover and find out.
wink

Offline

Board footer

Powered by FluxBB