#1 2014-06-18 11:27:11

itSDS
Member
From: Germany
Registered: 2014-04-24
Posts: 516

Correct way to Connect HttpServer to MySQL

Hi Arnaud,

I just want to switch from SQLite to MySQL in my REST - Server.

I wrote this code, but I'm not Sure if it is correct to pass a SQLITE_MEMORY_DATABASE_NAME to TSQLRestServerDB.Create as i did.

  Model1 := CreateModel1;
  Model2 := CreateModel2;
  fConnection := TSQLDBUniDACConnectionProperties.Create(TSQLDBUniDACConnectionProperties.URI(dMySQL,'localhost:3306'),'test','root','');
  VirtualTableExternalRegisterAll(Model1, fConnection);
  VirtualTableExternalRegisterAll(Model2, fConnection);
  SQLDB1 := TSQLDatabase.Create(SQLITE_MEMORY_DATABASE_NAME,'');
//  SQLDB1.UseCache := True;
  Model1DB := TSQLRestServerDB.Create(Model1,lSQLDB,false);
  Model1DB.CreateMissingTables(0);
  SQLDB2 := TSQLDatabase.Create(SQLITE_MEMORY_DATABASE_NAME,'');
//  SQLDB2.UseCache := True;
  Model2DB := TSQLRestServerDB.Create(TSJobsDataModel,jSQLDB,false);
  Model2.CreateMissingTables(0);
  Server := TSQLHttpServer.Create('8080',[Model1DB, Model2DB],'+',useHttpApiRegisteringURI, 32, secNone);
  Server.AccessControlAllowOrigin := '*'; // allow cross-site AJAX queries

Can you please look at this code an optimize it ?


Rad Studio 12.1 Santorini

Offline

#2 2014-06-18 12:06:50

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

Re: Correct way to Connect HttpServer to MySQL

Sounds fine to me.

Since VirtualTableExternalRegisterAll() will redirect all tables to MySQL, you do not need to persist any data within the main SQlite3 databases.
So SQLITE_MEMORY_DATABASE_NAME is a perfectly valid option here.

AFAIR, ODBC MySQL or ZEOS MySQL are faster than UniDAC MySQL to access the DB.
See http://blog.synopse.info/post/2014/03/0 … PostgreSQL

Offline

Board footer

Powered by FluxBB