How to create a database?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ralfiii
Posts: 25
Joined: Wed 16 Mar 2011 09:25

How to create a database?

Post by ralfiii » Wed 11 Jul 2012 16:29

Hello!

I need to (in a program) create a firebird database (either locally or on a server) and then run an sql-script to generate the table-structure.

I could do that by running the fireird tool "isql" with

Code: Select all

  isql -u SYSDBA -p masterkey -q -i GenerateEmptyDb.sql
    (The GenerateEmptyDb-script holds a CREATE DATABASE statement)
  isql EmptyDB.fdb -u SYSDBA -p masterkey -q -i MyDDEScript.sql
Naturally I'd prefer to do both actions with the IBDac-components.

First I tried to execute the scripts directly using TIBCScript as described here http://forums.devart.com/viewtopic.php?f=28&t=24169 and here http://forums.devart.com/viewtopic.php?f=31&t=24052

So I tried this

Code: Select all

     IBCConnection1.Username:='sysdba';
     IBCConnection1.Password:='masterkey';
     IBCConnection1.LoginPrompt:=False;
     IBCConnection1.Server:='localhost';

     IBCScript1.Connection:=IBCConnection1;
     IBCScript1.NoPreconnect:=True;
     IBCScript1.SQL.Text:='CREATE DATABASE ''C:\test.fdb'' PAGE_SIZE 16384 DEFAULT CHARACTER SET UTF8;';
     IBCScript1.Execute;
It failed - IBDac claims the username/password is not defined.

Hmmm... ok, I tried something other.

In the forum I found this entry: http://forums.devart.com/viewtopic.php?f=31&t=24052
CreateDatabase - sounds promising.
In the help I read "Call the CreateDatabase method to create an InterBase database using Params as the rest of the CREATE DATABASE statement." so I tried

Code: Select all

     IBCConnection1.Params.Text:='E:\EmptyDb.fdb PAGE_SIZE 16384 DEFAULT CHARACTER SET UTF8';
     IBCConnection1.CreateDatabase;
That fails also - with an error I don't understand ("I/O error during "open" operation for file "" - database or file exists.").

Now I don't know any futher. Please help!

ZEuS
Devart Team
Posts: 240
Joined: Thu 05 Apr 2012 07:32

Re: How to create a database?

Post by ZEuS » Thu 12 Jul 2012 09:20

In order to create a new database, you should specify the username and password in the "CREATE DATABASE" SQL-statement, and not as properties of TIBCConnection. So, you should modify one line in your example like this:
IBCScript1.SQL.Text:='CREATE DATABASE ''C:\test.fdb'' USER ''SYSDBA'' PASSWORD ''masterkey'' PAGE_SIZE 16384 DEFAULT CHARACTER SET UTF8;';

ralfiii
Posts: 25
Joined: Wed 16 Mar 2011 09:25

Re: How to create a database?

Post by ralfiii » Thu 12 Jul 2012 11:36

Thanks, that works.

Post Reply