How to create a DB

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
akli_agha
Junior Boarder
Junior Boarder
Posts: 41
Joined: 08.01.2008, 20:35

How to create a DB

Post 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.
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Post by gto »

Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
SlavoF
Junior Boarder
Junior Boarder
Posts: 29
Joined: 12.02.2009, 15:31
Location: Nitra, Slovakia
Contact:

Post 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
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
trupka
Expert Boarder
Expert Boarder
Posts: 140
Joined: 26.08.2007, 22:10

Post 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.
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
trupka
Expert Boarder
Expert Boarder
Posts: 140
Joined: 26.08.2007, 22:10

Post 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;
SlavoF
Junior Boarder
Junior Boarder
Posts: 29
Joined: 12.02.2009, 15:31
Location: Nitra, Slovakia
Contact:

Post by SlavoF »

:-(
I don´t know
error must be otherwhere
connected = true , but database not exists

http://www.davidplus.sk/test/firebird.zip
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
SlavoF
Junior Boarder
Junior Boarder
Posts: 29
Joined: 12.02.2009, 15:31
Location: Nitra, Slovakia
Contact:

Post 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
SlavoF
Junior Boarder
Junior Boarder
Posts: 29
Joined: 12.02.2009, 15:31
Location: Nitra, Slovakia
Contact:

Post by SlavoF »

HERE IS THE SOLUTION OF THIS PROBLEM
http://zeos.firmos.at/viewtopic.php?t=2259
:wallb:
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post 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
Image
SlavoF
Junior Boarder
Junior Boarder
Posts: 29
Joined: 12.02.2009, 15:31
Location: Nitra, Slovakia
Contact:

Post by SlavoF »

yes,
7.x on D2009
Post Reply