You are not logged in.
Pages: 1
While checking out the TSQLVirtualTable i got some strange behavior with them
At first i have a virtual table:
MyModel.VirtualTableRegister( TSQLMyData1Temp, TSQLVirtualTableJSON );
Sending and retrieving data works fine ... but there is some data missing.
The Record contains a collection and the collection data is missing in the file ... where has it gone?
Switching the table into a normal TSQLRecord everything is fine - also the collection data exists in the sqlite file.
Last edited by Sir Rufo (2011-10-31 20:21:45)
Offline
The record MUST be a TSQLRecord descendant.
it is ... not really TSQLRecord, but TSQLRecordVirtual, cause otherwise I can't register this as a virtual table
TMyData1Temp = class( TSQLRecordVirtual )
published
property MyCollection : TCollection read GetMyCollection;
end;
...
MyModel.VirtualTableRegister( TMyData1Temp, TSQLVirtualTableJSON );
so if i had to use a TSQLRecord descendant, how do I register as a virtual table?
Offline
As stated by the documentation (see e.g. the definition of TSQLVirtualTableJSON), you shall inherit your class from TSQLRecordVirtualTableAutoID instead of TSQLRecordVirtual, which is an abstract class common to all virtual tables:
{{ A TSQLRestServerStaticInMemory-based virtual table using JSON storage
- for ORM access, you should use TSQLModel.VirtualTableRegister method to
associated this virtual table module to a TSQLRecordVirtualTableAutoID class
- transactions are not handled by this module
- by default, no data is written on disk: you will need to call explicitly
aServer.StaticVirtualTable[aClass].UpdateToFile for file creation or refresh
- file extension is set to '.json' }
TSQLVirtualTableJSON = class(TSQLVirtualTable)
....
Offline
upps ... you are totally right
after building a test case, everything works fine ...
Offline
But there is still a difference, when using VirtualTables
here my record
type
TSQLSomeDataReal = class( TSQLRecord )
private
fStrData : SynUnicode;
FStrDataColl : TSomeDataCollection;
public
constructor Create; override;
destructor Destroy; override;
published
property StrData : SynUnicode read fStrData write fStrData;
property StrDataColl : TSomeDataCollection read FStrDataColl;
end;
TSQLSomeDataVirtual = class( TSQLRecordVirtualTableAutoID )
private
fStrData : SynUnicode;
FStrDataColl : TSomeDataCollection;
public
constructor Create; override;
destructor Destroy; override;
published
property StrData : SynUnicode read fStrData write fStrData;
property StrDataColl : TSomeDataCollection read FStrDataColl;
end;
and the creation of the client (and the database)
begin
Model := TSQLModel.Create( [TSQLSomeDataReal, TSQLSomeDataVirtual] );
Model.VirtualTableRegister( TSQLSomeDataVirtual, TSQLVirtualTableJSON );
fClient := TSQLRestClientDB.Create( Model, nil, TSQLDatabase.Create( ChangeFileExt( ParamStr( 0 ), '.db' ) ),
TSQLRestServerDB );
( fClient as TSQLRestClientDB ).Server.CreateMissingTables( 0 );
( fClient as TSQLRestClientDB ).Server.CreateSQLIndex( TSQLSomeDataReal, 'StrData', True );
end;
but there will be no UNIQUE INDEX in the database
without the VirtualTable
begin
Model := TSQLModel.Create( [TSQLSomeDataReal] );
fClient := TSQLRestClientDB.Create( Model, nil, TSQLDatabase.Create( ChangeFileExt( ParamStr( 0 ), '.db' ) ),
TSQLRestServerDB );
( fClient as TSQLRestClientDB ).Server.CreateMissingTables( 0 );
( fClient as TSQLRestClientDB ).Server.CreateSQLIndex( TSQLSomeDataReal, 'StrData', True );
end;
the UNIQUE INDEX works as expected
Last edited by Sir Rufo (2011-11-02 15:27:17)
Offline
Pages: 1