You are not logged in.
Pages: 1
Yes, I was using 1.17!
I see you changed all SQLite3* names to mORMot* in 1.18
Unfortunately I could not make even this example work: (SAD - Global Architecture - Rev. 1.18 Page 127)
"Here is some working sample program, using our SynOleDB unit to connect to a local MS SQL Server 2008 R2 Express edition"
program TestOleDB;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes,
SynCommons,
SynOleDB;
var Props: TOleDBConnectionProperties;
Conn: TSQLDBConnection;
Query: TSQLDBStatement;
F: TFileStream;
begin
with OleDBSynLogClass.Family do begin
Level := LOG_VERBOSE;
AutoFlushTimeOut := 10;
end;
Props := TOleDBMSSQLConnectionProperties.Create('.\SQLEXPRESS','AdventureWorks2008R2','','');
try
//Props.ConnectionStringDialogExecute;
Conn := Props.NewConnection;
try
Query := Conn.NewStatement;
try
Query.Execute('select * from Person.Address',true,[]);
F := TFileStream.Create(ChangeFileExt(paramstr(0),'.json'),fmCreate);
try
Query.FetchAllToJSON(F,false);
finally
F.Free;
end;
finally
Query.Free;
end;
finally
Conn.Free;
end;
finally
Props.Free;
end;
end.
Delphi complains about undeclared identifier "OleDBSynLogClass" and "TSQLDBConnection". If you add "SynDB" to uses so could Delphi find "TSQLDBConnection".
Very nice it is!
One more small question that already took us one day
The manual says: "there is no difference with using the local SQLite3 engine or a remote database engine. From the Client point of view, you just call the usual RESTful methods (i.e. Add / Retrieve / Update/ UnLock / Delete)"
We want to find the record that was just saved in the code above. If you have "Database: TSQLRest" then it works fine to search like this:
Rec := TSQLSampleArticle.Create(Database,'Name=?',['Test']);
writeln( 'Name: ' + Rec.Name);
But it doesn't work with "Database: TSQLRestServerDB", so we tried this:
Rec := TSQLSampleArticle.CreateAndFillPrepare(Database,'Name LIKE ?',['Test']);
try
while Rec.FillOne do
writeln(Rec.Name);
finally
Rec.Free;
end;
and got: OLEDB Error 80040E14 - Invalid column name 'RowID'.
Do you know what procedure should one use to search records in TSQLRestServerDB?
Thanks so much!
Here is my code that could give an idea for other beginners
program Project_mORMot;
uses
SynCommons,
SysUtils,
SQLite3Commons,
SQLite3,
SQLite3DB,
SynDB,
SynOleDB;
{$APPTYPE CONSOLE}
type
TSQLSampleRecord = class(TSQLRecord)
private
fName: RawUTF8;
published
property Name: RawUTF8 index 50 read fName write fName;
end;
var Props: TOleDBConnectionProperties;
Model: TSQLModel;
Database: TSQLRestServerDB;
Rec: TSQLSampleRecord;
begin
Props := TOleDBMSSQLConnectionProperties.Create('.\SQLEXPRESS','TestDatabase','','');
Model := TSQLModel.Create([TSQLSampleRecord],'root');
VirtualTableExternalRegister(Model,TSQLSampleRecord,Props,'');
Database := TSQLRestServerDB.Create(Model,'application.db');
Database.CreateMissingTables();
//Adding data
Rec := TSQLSampleRecord.Create;
Rec.Name := 'Test';
Database.Add(Rec,true);
Rec.Free;
end.
Hello! I am trying to create a very simple code to write data in a database on my local MS SQL Server:
type
TSQLSampleRecord = class(TSQLRecord)
private
fName: RawUTF8;
published
property Name: RawUTF8 read fName write fName;
end;
var Props: TOleDBConnectionProperties;
Model: TSQLModel;
Database: TSQLRestServerDB; //???
Rec: TSQLSampleRecord;
begin
Props := TOleDBMSSQLConnectionProperties.Create('.\SQLEXPRESS','TestDatabase','','');
Model := TSQLModel.Create([TSQLSampleRecord],'root');
VirtualTableExternalRegister(Model,TSQLSampleRecord,Props,'');
Database := TSQLRestServerDB.Create(Model,'application.db'); //???
//Adding data
Rec := TSQLSampleRecord.Create;
Rec.Name := 'Test';
Database.Add(Rec,true);
Rec.Free;
The idea is that mORMot should create a table "SampleRecord" and write down this Rec row, but it doesn't ;)
I really could not find such a simple example in this forum, manual or in working examples.
I guess I choose wrong database type (TSQLRestServerDB) and wrong create procedure? (TSQLRestServerDB.Create)
Pages: 1