Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I am trying to write a Perl script to create a Firebird database but am not having much luck getting anything to work.
Does anyone have any idea how I do this?

Thanks for your time.

Izabelle

Replies are listed 'Best First'.
Re: Creating a Firebird Database
by marto (Cardinal) on Sep 22, 2005 at 14:08 UTC

      Hi Martin,

      I've been using DBI and this is the code I've been trying to use:

      $dbh = DBI->connect("dbi:InterBase:dbname=/usr/local/firebird/security.fdb;ho +st=$host",$fbuser,$fbpass,{AutoCommit =>1}); my $create = qq(CREATE DATABASE '$host:/var/lib/firebird/$dbname.fdb' +user '$username' password '$password'); $dbh->do($create);

      When I try to run it I get these errors, which is what makes me think I might be connected to the wrong database.

      DBD::InterBase::db do failed: Unsuccessful execution caused by an unavailable resource.
      invalid database handle (no active connection)

      Thanks for all your help.

      Izabelle

Re: Creating a Firebird Database
by svenXY (Deacon) on Sep 22, 2005 at 14:07 UTC

      Hi svenXY,

      I think the problem that I've been having is to do with the database that I'm connected to before I create the database. Have you got an example of the actual code that I would use to create the database?

      Thanks for your help.

      Izabelle

        I don't know anything about Firebird/Interbase, but I've had this problem with other RDBMSs before. One possibility is to connect to a system database (many RDBMSs have these to store metadata) in your call to connect and then issue a USE or CREATE DATABASE command once connected. If that doesn't work, you'll need to find a command line tool that works with the RDBMS - something you can use outside of perl to create the database so that you have something to connect to.
Re: Creating a Firebird Database
by radiantmatrix (Parson) on Sep 22, 2005 at 14:21 UTC

    Most of us are very busy people, and would rather spend our time answering very specific questions. Yours is rather vauge -- it does not tell us, for example, what you have tried and exactly what problems (error messages, etc.) you are getting.

    You might want to read How (Not) To Ask A Question for some ideas on what (not) to include in questions in order to get the most useful responses. After reading that, please update your question with the details, and I'm sure you will get the help you need.

    <-radiant.matrix->
    Larry Wall is Yoda: there is no try{} (ok, except in Perl6; way to ruin a joke, Larry! ;P)
    The Code that can be seen is not the true Code
    "In any sufficiently large group of people, most are idiots" - Kaa's Law
Re: Creating a Firebird Database
by svenXY (Deacon) on Sep 22, 2005 at 14:24 UTC
    Hi,
    I'm not sure it is possible to create the database via Perl as you need to specify the database name in the Ds string.
    But if you run your Perl script on the same box as the Firebird daemon, you might be able to use
    system('isql');
    Why can you not first create the database using the usual tools (isql) and then connect to the empty database with perl and proceed?
    Regards,
    svenXY

      The aim of the script is to provide one place for creating MySQL, SQL and Firebird accounts for users, printing off a sheet for them to take away with their account details.

      Unfortunately Firebird and Perl aren't on the same box so I can't use system.

      The back up plan is to use isql as you suggested, it would just be more convenient to have everything in the same place.

      Thanks again for your help.

      Izabelle

        Surely once you have created the database you will be able to use DBI to interface with it to create users or whatever? Am I missing your point here?

        Martin