#1 2012-09-05 14:00:34

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Creating a database

Maybe I am not looking straight ... but I can't seem to find any possibility to create a new database through a TSQLDBconnection or TSQLDBConnectionproperties...
Any plans on this?

Offline

#2 2012-09-05 16:05:40

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

Re: Creating a database

SQLite3 databases (i.e. SQLite3 files) are created by the framework.
But up to now, we must have an existing database, for all external DB engines.

From my little experiment, creating a database is not a trivial task.
You have to use tools or connect in a special mode, not handled by OleDB or ODBC for instance.
Under Oracle for instance, you should better use the Wizard, otherwise you'll have a lot of commands to run.

So there is no plan on this.
There is already a TOleDBConnectionProperties.CreateDatabase virtual method, used e.g. to create a Jet/MSAccess file.
We may define this method at TSQLDBConnectionProperties generic level, then call it from ORM, e.g. for Jet or Nexus.
But should be difficult to make it generic.

I suspect the easiest could be to implement the same behavior as SQLite3, for the DB engines which may be able to easily create databases: if the database does not exist, try to create it.
That is, an auto-creation feature, not a specific ORM command.

Offline

#3 2012-09-07 06:48:18

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: Creating a database

OK, i'll add my own implementation of CreateDatabase to my NexusDB driver.

Maybe its an idea to add some kind of "CanCreate():boolean" function to the main TSQLDBCOnnectionProperties, or add interfaces to let the code determine if its possible to create a database, independent of the actual TConnectionproperties implementation..

type
  ICanCreateDatabase = interface(IInterface)
  ['{C6A016A5-2A6E-48F6-9A4D-310B643B53C0}']
    function CanCreate: boolean;
    function DatabaseExists: boolean;
    function CreateDatabase: boolean;
  end;

Offline

#4 2012-09-07 09:05:35

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

Re: Creating a database

Good idea.

I've added this feature to the mORMot roadmap.

Offline

Board footer

Powered by FluxBB