#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0

    Firebird DB_NAME() equivalent


    Hey everyone,

    I'm building some crystal reports to run against a number of our historical Firebird databases. They all have the same schema, so we will be running a number of the reports against multiple databases. We need some way to get the name of the database that the report is being run against. In MS SQL, it would just take a 'SELECT DB_NAME()'.

    I've read through the system tables, and I couldn't find any place where the name of the database was being stored.

    Is there any SQL funciton of command or SELECT statement that can be used to return the name of the database?

    Thank you for any help that you might be able to offer,

    - Scott
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,781
    Rep Power
    348
    I think this should be available through
    Code:
    SELECT *
    FROM RDB$DATABASE
    That should return exactly one row. One of the columns is the name of the database as far as I remember.

    But I don't have a Firebird installation available right now.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0
    Originally Posted by shammat
    I think this should be available through
    Code:
    SELECT *
    FROM RDB$DATABASE
    That should return exactly one row. One of the columns is the name of the database as far as I remember.

    But I don't have a Firebird installation available right now.
    I had read in the language reference that it only had 'Description', 'Relation_ID', 'Security_Class', 'Character_Set_Name'. Just in case it was held in one of those fields, I ran the query and it returned:
    '','245','','ISO_8859_1'

    'Description' looked potentially helpful, but seeing as it's empty, I guess I'm out of luck there.

    Thanks for the response, though.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,781
    Rep Power
    348
    You can also try MON$DATABASE, it contains a bit more information. At least with my installation it actually shows the full filename of the database in the MON$DATABASE_NAME column.

    Comments on this post

    • pabloj agrees
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0
    Originally Posted by shammat
    You can also try MON$DATABASE, it contains a bit more information. At least with my installation it actually shows the full filename of the database in the MON$DATABASE_NAME column.
    Unfortunately, I don't see any system tables with the MON$ prefix, but I tried running the query anyhow... I got a 'table not found' error, which confirms it.

    I think that I might not be working with a Firebird database... I might be working with an interbase database (is there even a difference? I don't know). I've inherited these databases from an old RMS System, and I don't know how to check.

    I'm thinking that I might just be out of luck. If someone has another idea, I'd love to hear it, but seeing as I'm not even sure that it's a Firebird database, I'm willing to call this one closed. Thanks to everyone who answered, I really appreciate your help.

    - Scott
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2006
    Location
    Plovdiv. Bulgaria
    Posts
    226
    Rep Power
    12
    What is your FB version? MON$ tables are introduced in version 2.1
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0
    Originally Posted by mIRCata
    What is your FB version? MON$ tables are introduced in version 2.1
    After the little bit of digging that I was able to do, I beleive that I'm dealing with either Firebird 1.0 or Interbase 6.0. I have no idea how to differentiate between the two.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2006
    Posts
    205
    Rep Power
    15
    I think i have a more simple one:

    No matter how old FB or IB you are using, since you know the database file name when you connect to it. So no need to query it, but you can use the information from the connection parameters.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    5
    Rep Power
    0
    Originally Posted by nagysz
    I think i have a more simple one:

    No matter how old FB or IB you are using, since you know the database file name when you connect to it. So no need to query it, but you can use the information from the connection parameters.
    I'm using crystal reports to create the reports that we will be running. Currently, I just have the user's enter the name of the database, but I'm a bit pained to do it that way, as it's prone to human error. I've tried to work out how to get crystal reports to display the connection string on the report itself, but it's looking to be an impossibility.

    I'm thinking that the only way to do it right would be for me to build a small c# application that micromanages the running of the reports. If I were to do that, then I could do as the above poster suggested, and just parse the DB Name from the connection string.

    I was hoping to be able to avoid that with a simple query, but it's looking like the version of the Firebird databases that we have are too old to have the db Name stored locally.

    Thanks to everyone who has posted. I'm really impressed by how active this forum is, and how helpful everyone has been.

IMN logo majestic logo threadwatch logo seochat tools logo