You are not logged in.
Pages: 1
Thanks a lot!
Hello!
I'm working with mormot 1.18, Delphi Seattle, MSSQL 2014
I Change the Sample 28 (simple RESTful ORM Server) to TOleDBMSSQLConnectionProperties for to work with MSSQL 2014 database
I'm creating the MSSQL tables from TSQLModel.
When the application execute CreateMissingTables, then the following error occurs "Class not registered"
This is the code TSQLModel:
unit uClassDef;
{$I Synopse.inc} // define HASINLINE WITHLOG USETHREADPOOL ONLYUSEHTTPSOCKET
interface
uses
{$I SynDprUses.inc}
SysUtils,
SynCommons,
SynCrypto,
mORMot;
Type
TSQLUserGroups = Class(TSQLRecord)
private
fHeader: Integer;
fDescrip: RawUTF8;
fSettings: TNullableUTF8Text;
public
published
property Header: Integer read fHeader write fHeader;
property Descrip: RawUTF8 Index 60 read fDescrip write fDescrip;
property Settings: TNullableUTF8Text read fSettings write fSettings;
End;
TSQLUsers = Class(TSQLRecord)
private
fmGroup: TSQLUserGroups;
fHeader: Integer;
fSettings: TNullableUTF8Text;
fDescrip: RawUTF8;
public
published
property mGroup: TSQLUserGroups read fmGroup write fmGroup;
property Header: Integer read fHeader write fHeader;
property Descrip: RawUTF8 Index 60 read fDescrip write fDescrip;
property Settings: TNullableUTF8Text read fSettings write fSettings;
End;
TSQLAddress = Class(TSQLRecord)
private
fDescrip: RawUTF8;
fCountry: RawUTF8;
fState: RawUTF8;
fLocality: RawUTF8;
fAddress1: RawUTF8;
fAddress2: RawUTF8;
fzipCode: RawUTF8;
fPhones: RawUTF8;
public
published
property Descrip: RawUTF8 Index 60 read fDescrip write fDescrip;
property Country: RawUTF8 Index 40 read fCountry write fCountry;
property State: RawUTF8 Index 20 read fState write fState;
property Locality: RawUTF8 Index 40 read fLocality write fLocality;
property Address1: RawUTF8 Index 60 read fAddress1 write fAddress1;
property Address2: RawUTF8 Index 60 read fAddress2 write fAddress2;
property zipcode: RawUTF8 Index 15 read fzipCode write fzipCode;
property Phones: RawUTF8 Index 60 read fPhones write fPhones;
End;
TPersonTypes = (ptDefault,ptCustomer,ptVendor,ptSalesman,ptServers);
TSQLPerson = Class(TSQLRecord)
private
fPersonId: RawUTF8;
fpType: Int8;
fBirthDate: TCreateTime;
fpClass: RawUTF8;
fEmail: RawUTF8;
fLastName: RawUTF8;
fIdType: Int8;
fTaxId: RawUTF8;
fDescrip: RawUTF8;
fNametype: Int8;
fFirstName: RawUTF8;
fActive: Int8;
fNotes: TNullableUTF8Text;
fAddress: TSQLAddress;
public
function Name: RawUTF8;
published
property personId: RawUTF8 Index 15 read fPersonId write fPersonId stored AS_UNIQUE;
property pType: Int8 read fpType write fpType;
property Active: Int8 read fActive write fActive;
property TaxId: RawUTF8 Index 25 read fTaxId write fTaxId;
property IdType: Int8 read fIdType write fIdType;
property NameType: Int8 read fNametype write fnametype;
property FirstName: RawUTF8 index 20 read fFirstName write fFirstName;
property LastName: RawUTF8 index 20 read fLastName write fLastName;
property Descrip: RawUTF8 Index 60 read fDescrip write fDescrip;
property Address: TSQLAddress read fAddress write fAddress;
property pClass: RawUTF8 Index 15 read fpClass write fpClass;
property BirthDate: TCreateTime read fBirthDate write fBirthDate;
property Email: RawUTF8 index 60 read fEmail write fEmail;
property Notes: TNullableUTF8Text read fNotes write fNotes;
End;
TSQLConfigSys = Class(TSQLRecord)
private
fSettings: TNullableUTF8Text;
fdPrivate: TSQLRawBlob;
fAddress: TSQLAddress;
fIdVersion: Int64;
public
published
property Settings: TNullableUTF8Text read fSettings write fSettings;
property dPrivate: TSQLRawBlob read fdPrivate write fdPrivate;
property address: TSQLAddress read fAddress write fAddress;
property Idversion: Int64 read fIdVersion write fIdVersion;
End;
TSQLCorrelative = Class(TSQLRecord)
private
fConfig: TSQLConfigSys;
fFieldName: RawUTF8;
fValue: RawUTF8;
fStation: RawUTF8;
public
published
property Config: TSQLConfigSys read fConfig write fConfig;
property fieldname: RawUTF8 Index 15 read fFieldName write ffieldName;
property Station: RawUTF8 Index 15 read fStation write fStation;
property Value: RawUTF8 Index 10 read fValue write fValue;
End;
TSQLCustomers = Class(TSQLRecord)
private
fPerson: TSQLPerson;
fzoneCode: RawUTF8;
fTolerance: Int16;
fAgreeCode: RawUTF8;
fDiscount: Double;
fCustType: Int8;
fSalesCode: RawUTF8;
fCredit: Double;
fCreditdays: Int16;
fPricetype: Int8;
public
published
property person: TSQLPerson read fPerson write fPerson;
property CustType: Int8 read fCustType write fCustType; // Contribuyente,C.Final,Gobierno
property PriceType: Int8 read fPricetype write fPriceType;
property ZoneCode: RawUTF8 index 10 read fzoneCode write fzoneCode;
property SalesCode: RawUTF8 index 10 read fSalesCode write fSalesCode;
property AgreeCode: RawUTF8 index 10 read fAgreeCode write fAgreeCode;
property Credit: Double read fCredit write fCredit;
property CreditDays: Int16 read fCreditdays write fCreditdays;
property Tolerance: Int16 read fTolerance write fTolerance;
property Discount: Double read fDiscount write fDiscount;
End;
TSQLSalesMen = Class(TSQLRecord)
private
fPerson: TSQLPerson;
public
published
property person: TSQLPerson read fPerson write fPerson;
End;
TSQLServers = Class(TSQLRecord)
private
fPerson: TSQLPerson;
public
published
property person: TSQLPerson read fPerson write fPerson;
End;
TSQLVendors = Class(TSQLRecord)
private
fPerson: TSQLPerson;
public
published
property person: TSQLPerson read fPerson write fPerson;
End;
TSQLInstance =Class(TSQLRecord)
private
public
published
End;
TSQLInventory =Class(TSQLRecord)
private
public
published
End;
TSQLLocation =Class(TSQLRecord)
private
published
End;
TSQLUser = class(TSQLAuthUser)
private
published
end;
const
SERVER_ROOT = 'root';
SERVER_PORT = '8092';
SERVER_HOST = 'localhost';
function DataModel: TSQLModel;
implementation
uses
SynCrtSock;
function DataModel: TSQLModel;
begin
Result:= TSQLModel.Create([TSQLUSerGroups,TSQLUsers,TSQLAddress,
TSQLPerson,TSQLConfigSys,TSQLCorrelative, TSQLCustomers],SERVER_ROOT);
//TPerson.AddFilterOrValidate('Name',TSynValidateText.Create); // ensure exists
end;
function TSQLPerson.Name: RawUTF8;
begin
if IdType=1 then
Result:=Descrip
else
Result:=FirstName+' '+LastName;
end;
end.
This is the server:
uses
{$I SynDprUses.inc}
SynCrtSock,
SynCommons,
SynSQLite3,
SynDBRemote,
SynSQLite3Static,
SynDB,
SynLog,
SynOleDB,
mORMot,
mORMotDB,
mORMotSQLite3,
mORMotHttpServer,
uClassDef in 'uClassDef.pas';
procedure setVirtualTables( aModel: TSQLModel;
aProps: TOleDBMSSQLConnectionProperties);
Begin
VirtualTableExternalRegister(aModel,TSQLUSerGroups, aProps,'dbo.UserGroups');
VirtualTableExternalRegister(aModel,TSQLUsers, aProps,'dbo.Users');
VirtualTableExternalRegister(aModel,TSQLAddress, aProps,'dbo.Address');
VirtualTableExternalRegister(aModel,TSQLPerson, aProps,'dbo.Person');
VirtualTableExternalRegister(aModel,TSQLConfigSys, aProps,'dbo.ConfigSys');
VirtualTableExternalRegister(aModel,TSQLCorrelative,aProps,'dbo.Correlative');
VirtualTableExternalRegister(aModel,TSQLCustomers, aProps,'dbo.Customers');
VirtualTableExternalRegisterAll(aModel,aProps);
End;
var
aModel: TSQLModel;
aProps: TOleDBMSSQLConnectionProperties;
aRestServer: TSQLRestServerDB;
aHttpServer: TSQLHttpServer;
begin
SQLite3Log.Family.Level := LOG_VERBOSE;
SQLite3Log.Family.PerThreadLog := ptIdentifiedInOnFile;
aProps := TOleDBMSSQLConnectionProperties.Create('localhost','Elevated','sa','12345');
try
aModel := DataModel;
setVirtualTables(aModel,aProps);
try
aRestServer := TSQLRestServerDB.Create(aModel,':memory:',false); // authentication=false
try
aRestServer.AcquireExecutionMode[execORMGet ]:= amBackgroundORMSharedThread;
aRestServer.AcquireExecutionMode[execORMWrite]:= amBackgroundORMSharedThread;
aRestServer.DB.Synchronous:=smNormal;
aRestServer.DB.LockingMode:=lmExclusive;
// create tables or fields if missing
aRestServer.CreateMissingTables;
// serve aRestServer data over HTTP
aHttpServer := TSQLHttpServer.Create(SERVER_PORT,[aRestServer],'+',useHttpApiRegisteringURI);
try
aHttpServer.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries
writeln('Background server is running.'#10);
write('Press [Enter] to close the server.');
readln;
This is the log file
20160128 17192111 ! DB SynSQLite3.TSQLDatabase(02D3A820) ":memory:" database file opened with PageSize=1024 and CacheSize=2000
20160128 17192111 ! - 00.000.185
20160128 17192111 ! SQL SynSQLite3.TSQLDatabase(02D3A820) 5us PRAGMA synchronous=1
20160128 17192111 ! SQL SynSQLite3.TSQLDatabase(02D3A820) 2us PRAGMA locking_mode=EXCLUSIVE;
20160128 17192111 ! SQL SynSQLite3.TSQLDatabase(02D3A820) 20us returned 0 rows SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';
20160128 17192111 ! DB mORMotSQLite3.TSQLRestServerDB(02C10030) CreateMissingTables on {"TSQLDatabase(02D3A820)":{"FileName":":memory:","IsMemory":true,"UseCache":true,"TransactionActive":false,"BusyTimeout":0,"CacheSize":2000,"PageSize":1024,"PageCount":0,"FileSize":0,"WALMode":false,"Synchronous":"smNormal","LockingMode":"lmExclusive","MemoryMappedMB":0,"user_version":0,"OpenV2Flags":6,"BackupBackgroundInProcess":false,"BackupBackgroundLastTime":"","BackupBackgroundLastFileName":"","SQLite3Library":{"TSQLite3LibraryStatic(02C975F0)":{"Version":"3.10.2 with internal MM"}}}}
20160128 17192111 ! DB mORMotSQLite3.TSQLRestServerDB(02C10030) "GetTables":[]
20160128 17192111 ! SQL SynSQLite3.TSQLDatabase(02D3A820) 2us BEGIN TRANSACTION;
20160128 17192111 ! + mORMotDB.TSQLRestStorageExternal(02C9F4E0).Create TSQLUserGroups
20160128 17192111 ! info mORMotDB.TSQLRestStorageExternal(02C9F4E0) TSQLUserGroups {"TOleDBMSSQLConnectionProperties(02C79C30)":{"ProviderName":"SQLNCLI10","Engine":"MSSQL","ServerName":"localhost","DatabaseNameSafe":"Elevated","UserID":"sa","DBMS":"dMSSQL","DBMSEngineName":"MSSQL","BatchSendingAbilities":["cCreate"],"BatchMaxSentAtOnce":4096,"LoggedSQLMaxSize":0,"LogSQLStatementOnException":false,"ForcedSchemaName":"dbo","UseCache":true,"RollbackOnDisconnect":true,"StoreVoidStringAsNull":true}} Server={"TSQLRestServerDB(02C10030)":{"DB":{"TSQLDatabase(02D3A820)":{"FileName":":memory:","IsMemory":true,"UseCache":true,"TransactionActive":true,"BusyTimeout":0,"CacheSize":2000,"PageSize":1024,"PageCount":1,"FileSize":1024,"WALMode":false,"Synchronous":"smNormal","LockingMode":"lmExclusive","MemoryMappedMB":0,"user_version":0,"OpenV2Flags":6,"BackupBackgroundInProcess":false,"BackupBackgroundLastTime":"","BackupBackgroundLastFileName":"","SQLite3Library":{"TSQLite3LibraryStatic(02C975F0)":{"Version":"3.10.2 with internal MM"}}}},"StatementLastException":"","NoAJAXJSON":false,"Options":[],"HandleAuthentication":false,"BypassORMAuthentication":[],"Stats":{"StartDate":"2016-01-28 17:19:21","Success":0,"ServiceMethod":0,"ServiceInterface":0,"OutcomingFiles":0,"CurrentThreadCount":0,"Created":0,"Read":0,"Updated":0,"Deleted":0,"ClientsCurrent":0,"ClientsMax":0,"CurrentRequestCount":0,"Input":{"Bytes":0,"Text":"0 B"},"Output":{"Bytes":0,"Text":"0 B"},"InputThroughput":{"BytesPerSec":0,"Text":"0 B/s"},"OutputThroughput":{"BytesPerSec":0,"Text":"0 B/s"},"Processing":false,"TaskCount":0,"TotalTime":{"MicroSec":0,"Text":"0us"},"LastTime":{"MicroSec":0,"Text":"0us"},"MinimalTime":{"MicroSec":0,"Text":"0us"},"AverageTime":{"MicroSec":0,"Text":"0us"},"MaximalTime":{"MicroSec":0,"Text":"0us"},"PerSec":0,"Errors":0,"LastError":null},"StatLevels":["mlTables","mlMethods","mlInterfaces","mlSQLite3"],"StaticVirtualTableDirect":true,"ServerTimeStamp":135295079637}}
20160128 17192111 ! + SynOleDB.TOleDBConnection(02C46BB0).005EEA1D
20160128 17192111 ! - 00.002.587
20160128 17192111 ! + SynOleDB.TOleDBConnection(02C46BB0).005EE7A2
20160128 17192127 ! EXC EOleSysError 80040154 ("Class not registered") at 005E6239 stack trace API 00540EF4 00540F1C 0040A808
20160128 17192127 ! ERROR "EOleSysError(02D09188)":"Class not registered" stack trace API 00542FE0 005EE921 0056A149 005EC844 005592CF 0055B337 0055ABF6 0055EC8F 005EFB9A 006AA75D 006AABAA 0068F7FA 006B7B56 005BD814 005BDBD7 00597CC8 00590E47 00590F44 0054EDE5 0054DAFA 0054DBA7 0054ADBF 006B3743 006CA53D 77BA38F4 77CD56C3 77CD568E
20160128 17192127 ! EXC EOleSysError 80040154 ("Class not registered") at 005E6239 stack trace API 00540EF4 00540F1C 0040A808
20160128 17192127 ! - 00.246.829
20160128 17192127 ! DB SynOleDB.TOleDBStatement(02E59B10) Rows = {"TOleDBStatement(02E59B10)":{"SQL":"select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, 0 INDEX_COUNT from INFORMATION_SCHEMA.COLUMNS where UPPER(TABLE_SCHEMA) = 'DBO' and UPPER(TABLE_NAME) = 'USERGROUPS'","SQLWithInlinedParams":"select COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE, 0 INDEX_COUNT from INFORMATION_SCHEMA.COLUMNS where UPPER(TABLE_SCHEMA) = 'DBO' and UPPER(TABLE_NAME) = 'USERGROUPS'","CurrentRow":0,"TotalRowsRetrieved":0,"Connection":{"TOleDBConnection(02C46BB0)":{"Connected":false,"ServerTimeStampAtConnection":"","TotalConnectionCount":0,"TransactionCount":0,"InTransaction":false,"RollbackOnDisconnect":true,"LastErrorMessage":"","LastErrorWasAboutConnection":false,"Properties":{"TOleDBMSSQLConnectionProperties(02C79C30)":
Hello!
I new in mORMot.
My tables were defined by code first in TSQLrecord especifications. Not by sql script
I have a simple Firedac MSSQL server like this:
procedure setVirtualTables( aModel: TSQLModel;
aExternalDB: TSQLDBConnectionPropertiesThreadSafe);
Begin
VirtualTableExternalRegister(aModel,TSQLUSerGroups, aExternalDB,'dbo.UserGroups');
VirtualTableExternalRegister(aModel,TSQLUsers, aExternalDB,'dbo.Users');
VirtualTableExternalRegister(aModel,TSQLAddress, aExternalDB,'dbo.Address');
VirtualTableExternalRegister(aModel,TSQLPerson, aExternalDB,'dbo.Person');
VirtualTableExternalRegister(aModel,TSQLConfigSys, aExternalDB,'dbo.ConfigSys');
VirtualTableExternalRegister(aModel,TSQLCorrelative,aExternalDB,'dbo.Correlative');
VirtualTableExternalRegister(aModel,TSQLCustomers, aExternalDB,'dbo.Customers');
VirtualTableExternalRegisterAll(aModel,aExternalDB,[regDoNotRegisterUserGroupTables,
regMapAutoKeywordFields]);
End;
var aModel: TSQLModel;
aExternalDB: TSQLDBConnectionPropertiesThreadSafe;
aServer: TSQLRestServerDB;
aHTTPServer: TSQLHttpServer;
FDPhysMSSQLDriverLink: TFDPhysMSSQLDriverLink;
begin
SynDBLog.Family.Level := LOG_VERBOSE;
SynDBLog.Family.PerThreadLog:= ptIdentifiedInOnFile;
FDPhysMSSQLDriverLink:= TFDPhysMSSQLDriverLink.Create(Nil);
aModel := DataModel;
// ! Create('MSSQL?Server=127.0.0.1\SQLEXPRESS','Northwind','User','Password');
// ! Create('MSSQL?Server=.\SQLEXPRESS;OSAuthent=Yes','','','');
aExternalDB := TSQLDBFireDACConnectionProperties.Create(
'MSSQL?Server=127.0.0.1','Elevated','sa','12345');
try
aExternalDB.ThreadingMode := tmMainConnection; // force SINGLE connection
setVirtualTables(aModel,aExternalDB);
aServer:=TSQLRestServerDB.Create(aModel,SQLITE_MEMORY_DATABASE_NAME);
try
aServer.AcquireExecutionMode[execORMGet ]:=amBackgroundThread;
aServer.AcquireExecutionMode[execORMWrite]:=amBackgroundThread;
aServer.DB.Synchronous:=smNormal;
aServer.DB.LockingMode:=lmExclusive;
aServer.CreateMissingTables;
aHTTPServer:=TSQLHttpServer.Create(SERVER_PORT,aServer,'+',useHttpApiRegisteringURI);
aHttpServer.AccessControlAllowOrigin:='*'; // allow cross-site AJAX queries
try
writeln('Server launched on port '+SERVER_PORT+' using ',aHttpServer.HttpServer.ClassName);
writeln(#10'Press [Enter] to close the server.'#10);
readln;
---------------
---------------
The server is ok!
But in Client applicattion I can't add any record
The log file in the server is:
(038381E0).URI(GET root/TimeStamp inlen=0)
20160125 17002144 A call mORMotSQLite3.TSQLRestServerDB(038381E0) TimeStamp
20160125 17002144 A srvr mORMotSQLite3.TSQLRestServerDB(038381E0) GET root/TimeStamp SOA-Method -> 200 with outlen=12 in 54 us
20160125 17002144 A ret mORMotSQLite3.TSQLRestServerDB(038381E0) 135294685205
20160125 17002144 A - 00.000.059
20160125 17003555 " + mORMotSQLite3.TSQLRestServerDB(038381E0).URI(POST root/Address inlen=109)
20160125 17003555 B trace mORMotSQLite3.TSQLRestServerDB(038381E0) BeginCurrentThread(TSynBackgroundThreadMethod) ThreadID=00003F44 ThreadCount=33
20160125 17003555 B + SynDBFireDAC.TSQLDBFireDACStatement(037B7D60).0065357B
20160125 17003555 B - 00.000.029
20160125 17003555 B + SynDBFireDAC.TSQLDBFireDACStatement(037B7D60).006536ED
20160125 17003555 B SQL SynDBFireDAC.TSQLDBFireDACStatement(037B7D60) select max(ID) from dbo.Address
20160125 17003558 B - 00.046.530
20160125 17003558 B + SynDBFireDAC.TSQLDBFireDACStatement(037B7E20).0065357B
20160125 17003558 B - 00.000.069
20160125 17003558 B + SynDBFireDAC.TSQLDBFireDACStatement(037B7E20).006536ED
20160125 17003558 B SQL SynDBFireDAC.TSQLDBFireDACStatement(037B7E20) insert into dbo.Address (ID,Descrip,Country,State_,Locality,Address1,Address2,zipcode,Phones) values (1,'Casa',NULL,NULL,NULL,NULL,NULL,NULL,NULL)
20160125 17003558 B EXC EFDException ("[FireDAC][Phys][MSSQL]-335. Parameter [CA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call") at 00656C52 stack trace API 00562F44 00562F6C 0040AB08
20160125 17003558 B EXC EFDException ("[FireDAC][Phys][MSSQL]-335. Parameter [CA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call") at 00656C52 stack trace API 00562F44 00562F6C 0040A980 7780B534 777F8DAF 00656C52 00658C18 00801403 008248B3 00825841 008363D7 006F0E27 006F1181 006F16BE 006BE14F 0070A6A6 00653953 007DA644 007D7E67 00788FB2 007B89C0 0055CBB6 0055C657 004BF2D8 0040B42E 759038F4 777E56C3 777E568E
20160125 17003558 B EXC EFDException ("[FireDAC][Phys][MSSQL]-335. Parameter [CA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call") at 00656C52 stack trace API 00562F44 00562F6C 0040A980 7780B534 777F8DAF 00656C52 00658C18 00801403 008248B3 00825841 008363D7 006F0E27 006F1181 006F16BE 006BE14F 0070A6A6 00653953 007DA644 007D7E67 00788FB2 007B89C0 0055CBB6 0055C657 004BF2D8 0040B42E 759038F4 777E56C3 777E568E
20160125 17003558 B EXC EFDException ("[FireDAC][Phys][MSSQL]-335. Parameter [CA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call") at 00656C52 stack trace API 00562F44 00562F6C 0040A980 7780B534 777F8DAF 00656C52 00658C18 00801403 008248B3 00825841 008363D7 006F0E27 006F1181 006F16BE 006BE14F 0070A6A6 00653953 007DA644 007D7E67 00788FB2 007B89C0 0055CBB6 0055C657 004BF2D8 0040B42E 759038F4 777E56C3 777E568E
20160125 17003558 B EXC EFDException ("[FireDAC][Phys][MSSQL]-335. Parameter [CA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call") at 00656C52 stack trace API 00562F44 00562F6C 0040AB08
20160125 17003558 B EXC EFDException ("[FireDAC][Phys][MSSQL]-335. Parameter [CA] data type is unknown. Hint: specify TFDParam.DataType or assign TFDParam value before Prepare/Execute call") at 00656C52 stack trace API 00562F44 00562F6C
Thanks a lot for any help!
Guillermo
Pages: 1