Page 1 of 1

How to create a DB

Posted: 02.02.2008, 18:36
by akli_agha
Hi,

I'm newer in Zeos and Firebird, then, I think, my question will be so easy for you but seems so difficult for me. Ok.

How Can I create a new DB with FB server on disk ??
Wich Zeos component I use ??

I tried creating it this evening. I used TZSQLProcessor component but it has to be connected to TZConnection wich, itself, must be connected to physical DB.

My goal is to create this DB ! This is my problem !

Thanks for your help.

Regards.

Posted: 06.02.2008, 19:48
by gto

Posted: 12.02.2009, 15:41
by SlavoF
firebirdd-2.1
RAD 2009
svn://zeos.firmos.at/zeos/trunk from 11.2.2009

ZConnection1.Database := MyDir+'\COL.FDB';
- not exists
ZConnection1.Connect;
// ZConnection1.Connected return true ??????
ZConnection1.DisConnect; // or not

ZSQLProcessor1.Script.Text := 'CREATE DATABASE '+
QuotedStr(ZConnection1.Database)+ ' USER ' + QuotedStr(ZConnection1.User) +' PASSWORD ' + QuotedStr(ZConnection1.Password);
ZSQLProcessor1.Execute;
ERROR> Statement is not allowed

?
Thanks

Posted: 12.02.2009, 22:42
by mdaems
Can you add a TZSQLMonitor to your application to log the generated SQL? (Using dummy user/password combinations, of course)

When that doesn't help us, we you might try to zip all needed files (your project dir without dcu's and exe file but including the embedded server stuff) and send it to our project mail adres ( reverse('moc.liamg@bilsoez') )
So we can try it ourselves.

Mark

Posted: 13.02.2009, 00:27
by trupka
See: http://www.firebirdfaq.org/faq67/

isc_create_database function isn't declared in ZPlain(Interbase|Firebird)Driver.pas, so currently is not possible to create firebird db programaticaly.

Posted: 13.02.2009, 08:33
by mdaems
trupka,

This functionality actually IS provided in zeoslib.
To use it, you must set a connection.properties line:

Code: Select all

createNewDatabase=<sql command database creation>
(From doc\pdf\parameters.pdf in the zeoslib package)
This does really work. If you provide me with an email address using a private message I could send you a working example.

SlavoF, gto,
The referenced article was for postgres. There creating a database after connecting is possible using SQL. For interbase the database will be created before the actual connect.

Mark

Posted: 13.02.2009, 10:04
by trupka
Thanks for info, Mark.
Things are much clearer after reading docs - "createNewDatabase" is feature I wasn't aware of :shock:
For those who want to create Firebird database programaticaly, here is little code sample that works with embedded firebird:

Code: Select all

    with ZConnection1 do
    begin
        if not Connected
        then begin
            // if database doesn't exists
            if not FileExists(Database)
            then
                // try to create it on connection
                Properties.Add(
                    format('createNewDatabase=CREATE DATABASE %s USER %s PASSWORD %s',
                        [QuotedStr(Database), QuotedStr(User), QuotedStr(Password)])
                );
            Connect;
        end;
    end;

Posted: 13.02.2009, 11:29
by SlavoF
:-(
I don´t know
error must be otherwhere
connected = true , but database not exists

http://www.davidplus.sk/test/firebird.zip

Posted: 13.02.2009, 12:04
by mdaems
Sorry, no FB server installed here. So I can't test this myself. Do you get an error at connection when pressing button 3? Which one?

From the log file in the zip file I make the conclusion this database has been created. The connection was successful and a transaction has started.
I think the main question is where the firebird server has stored the file exactly. I don't know how the server decides where to put his databases.

Code: Select all

2009-02-13 11:20:04 cat: Connect, proto: firebird-2.1, msg: CREATE DATABASE "CREATE DATABASE 'D:\CodeGear\RAD Studio\6.0\Projects\Firebird\DB\COL.FDB' USER 'SYSDBA' PASSWORD 'masterkey'" AS USER "SYSDBA"
2009-02-13 11:20:04 cat: Connect, proto: firebird-2.1, msg: CONNECT TO "D:\CodeGear\RAD Studio\6.0\Projects\Firebird\DB\COL.FDB" AS USER "SYSDBA"
2009-02-13 11:20:04 cat: Transaction, proto: firebird-2.1, msg: TRANSACTION STARTED.
Some idea's I have as a FB amateur:
- Does FB server puts the files somewhere relative to a datadir?
- May the 'Space' in the path cause trouble putting the file somewhere in a strange location?

Mark

Posted: 13.02.2009, 12:50
by SlavoF
thanks,
I´m FB amateur :D
create database "D:\CodeGear\RAD Studio\6.0\Projects\Firebird\DB\COL.FDB";
in SQL Manager for InterBase & Firebird is OK and DB is created.
therefore am assertive:
error must be otherwhere
yet once thanks

Posted: 06.03.2009, 16:04
by SlavoF
HERE IS THE SOLUTION OF THIS PROBLEM
http://zeos.firmos.at/viewtopic.php?t=2259
:wallb:

Posted: 20.03.2009, 22:13
by mdaems
SlavoF,

Are you using the 7.x version on D2009? Or is this fix also important on 6.6?

Did commit to SVN. (Rev 603)

Mark

Posted: 10.04.2009, 12:38
by SlavoF
yes,
7.x on D2009