#1 2012-10-23 13:29:40

sytis
Member
From: Milano
Registered: 2012-10-16
Posts: 11

How to test VirtualTableExternalRegisterAll

I'm using the current source code for new VirtualTableExternalRegisterAll.

Right now I'm able to connect to MSSQL db server with a registered
VirtualTableExternal.
What I can't understand is how to register more than one external table
in the same Model to be able to use VirtualTableExternalRegisterAll.

Thanks!
Mauro

Offline

#2 2012-10-23 15:29:21

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

Re: How to test VirtualTableExternalRegisterAll

Just register your tables in the model as usual, then call VirtualTableExternalRegisterAll to mark that all your tables are externel.

Offline

#3 2012-10-24 14:51:52

sytis
Member
From: Milano
Registered: 2012-10-16
Posts: 11

Re: How to test VirtualTableExternalRegisterAll

I can't understand how use VirtualTableExternal (with just one table, internal or external, everything works as expected).

This sample code doesn't work rising "exception class C0000005 with message: 'access violation at 0x0403dba...":

Var
aModel : TSQLModel;
aServer : TSQLRestServerDB;
aProps : TOleDBConnectionProperties;
//vRecord1 : TSQLA;
//vRecord2 : TSQLB;

begin
aModel : CreateTestData;
aModel.VirtualTableRegister(TSQLA, TSQLVirtualTableJSON);
aModel.VirtualTableRegister(TSQLB, TSQLVirtualTableJSON);
aServer : TSQLRestServerDB.Create(aModel,'db.db3',false);
aServer.CreateMissingTables();
TSQLite3HttpServer.Create('8080',[aServer]);
WriteLn('Press ENTER to Exit');
ReadLn;
end.

//---------------------------- interface file

type
TSQLA = class(TSQLRecordVirtualTableAutoID)
private
   ffield1: Integer;
   ffield2: RawUTF8;
published
   property field1: Integer read ffield1 write ffield1;
   property field2: RawUTF8 read ffield2 write ffield2;
end;

type
TSQLB = class(TSQLRecordVirtualTableAutoID)
private
   ffield3: Integer;
   ffield4: RawUTF8;
published
   property field3: Integer read ffield3 write ffield3;
   property field4: RawUTF8 read ffield4 write ffield4;
end;
function CreateTestData: TSQLModel;
implementation
function CreateTestData: TSQLModel;
begin
result : TSQLModel.Create([TSQLA, TSQLB], 'root');
end;

Thanks for your help!

Offline

#4 2012-10-24 16:42:09

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

Re: How to test VirtualTableExternalRegisterAll

What is the exact source code line of the error, and the corresponding stack trace?

Offline

#5 2012-10-25 09:06:33

sytis
Member
From: Milano
Registered: 2012-10-16
Posts: 11

Re: How to test VirtualTableExternalRegisterAll

It's a CONSOLE application so when you compile it with the second VirtualTableRegister activated the program crash and close the window.
The exact error message is:

Project Project1.exe raised exception class C0000005 with message 'access violation at 0x00403dba: read of address 0xbaadf00d'.
Process stopped. Use Step or Run to continue.

Here the test source I'm using:

------------------------Project1.dpr----------------------

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  SynCommons,
  SynOleDB,
  SynDB,
  SQLite3Commons,
  SQLite3,
  SQLite3DB,
  SQLite3HttpServer,
  Unit1 in 'Unit1.pas';

Var
  aModel : TSQLModel;
  aServer : TSQLRestServerDB;
  Server: TSQLite3HttpServer;
begin
  aModel := CreateMyModel;

  // The program compile and run correctly if you
  // comment out one of these lines
  aModel.VirtualTableRegister(TSQLA, TSQLVirtualTableJSON);
  aModel.VirtualTableRegister(TSQLB, TSQLVirtualTableJSON);

  aServer := TSQLRestServerDB.Create(aModel,'database.db3',false);

  aServer.CreateMissingTables();

  Server := TSQLite3HttpServer.Create('8080',[aServer]);
  WriteLn('Press ENTER to Exit');
  ReadLn;
end.

-----------------Unit1.pas-----------------------
unit Unit1;

interface

uses
  SynCommons,
  SQLite3Commons;

type
  TSQLA = class(TSQLRecord)
  private
    fFirstField : Integer;
    fSecondField: RawUTF8;
  published
    property FirstField: Integer  read fFirstField  write fFirstField;
    property SecondField: RawUTF8 read fSecondField write fSecondField;
  end;

type
  TSQLB = class(TSQLRecord)
  private
    fThirdField : Integer;
    fFourthField: RawUTF8;
  published
    property ThirdField: Integer  read fThirdField  write fThirdField;
    property FourthField: RawUTF8 read fFourthField write fFourthField;
  end;

function CreateMyModel: TSQLModel;

implementation

function CreateMyModel: TSQLModel;
begin
  result := TSQLModel.Create([TSQLA, TSQLB]);
end;

end.

Offline

Board footer

Powered by FluxBB