Results 1 to 15 of 15

Thread: Create firebird database programmatically with Qt

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Create firebird database programmatically with Qt

    Hello all!

    I am trying to create a database directly from my code in Qt, but until now I did not have success, Can anyone help me with some article or some code?

    Thanks.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Create firebird database programmatically with Qt

    Can you help us with any idea what you have tried and how it "did not have success"?
    How are you trying to connect from Qt to Firebird?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Create firebird database programmatically with Qt

    The Firebird project offers an ODBC driver, so maybe you can connect to the database using Qt's ODBC driver instead. Make sure you have the Qt database plugins in the right place with respect to your executable, otherwise you won't be able to instantiate the driver.

  4. The following user says thank you to d_stranz for this useful post:

    guidupas (20th February 2015)

  5. #4
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    I am using the IBase driver and trying to do that with QSqlDriver, but it does not have the statement to create database.

    I need to do it directly from the Qt code, like is done with manager softwares but the connection to database returns an error if I dont select a database to connect.

  6. #5
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Create firebird database programmatically with Qt

    "Firebird doesn't provide a way to create database using SQL. You need to either use the Services API, or external tool. As API for database creation is often not available in libraries, you can call Firebird's isql tool to do it for you..."

    http://www.firebirdfaq.org/faq67/

  7. The following user says thank you to ChrisW67 for this useful post:

    guidupas (19th February 2015)

  8. #6
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    Thanks for the reply ChrisW67, it helped a lot. But I am trying to figure out how to execute to isql via stdin. Could you help me with this doubt?

  9. #7
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Create firebird database programmatically with Qt

    Use QProcess to run isql from your application. You can either use isql -i to read/execute SQL commands from a file or you can use QProcess and write commands to the stdin of the running QProcess using QProcess:write().

  10. The following user says thank you to jefftee for this useful post:

    guidupas (20th February 2015)

  11. #8
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    Thanks jthomps, I am going to try it.

    Thanks to d_stranz too. I will take a look at the firebird ODBC driver too.

  12. #9
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Create firebird database programmatically with Qt

    One comment regarding your approach. Is it reasonable to expect your users to have isql installed or are you planning on shipping isql somewhere in your bundle?

    Another thing you could consider is to ship an empty firebird database (created with isql but not objects created) with your app and copy that empty database the first time you start your app. You should be able to then create any tables, indexes, or views needed by your app, etc.

    Good luck.

  13. #10
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    Quote Originally Posted by jthomps View Post
    One comment regarding your approach. Is it reasonable to expect your users to have isql installed or are you planning on shipping isql somewhere in your bundle?

    Another thing you could consider is to ship an empty firebird database (created with isql but not objects created) with your app and copy that empty database the first time you start your app. You should be able to then create any tables, indexes, or views needed by your app, etc.

    Good luck.
    Possible only when the application is running on a database server. And what if the database server is another computer and You are connecting to them with TCP/IP?

  14. #11
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Create firebird database programmatically with Qt

    Quote Originally Posted by Lesiok View Post
    Possible only when the application is running on a database server.
    Lesiok, wouldn't this approach work also for an embedded Firebird database?

  15. #12
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    With embedded database condition "application is running on a database server" is true of course.

  16. #13
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    Guys, when I try to connect with this code:

    Qt Code:
    1. bool DB::conectarServidorFirebird(QSqlDatabase db)
    2. {
    3. bool retorno = true;
    4.  
    5. db.setHostName("localhost");
    6. db.setPassword("gui080381");
    7. db.setUserName("sysdba");
    8. //db.setPort(3050);
    9.  
    10. if(db.open())
    11. {
    12. retorno = true;
    13. }
    14. else
    15. {
    16. qDebug() << db.lastError();
    17.  
    18. retorno = false;
    19. }
    20.  
    21. return retorno;
    22. }
    To copy to clipboard, switch view to plain text mode 

    It returns me the error:

    QSqlError("-901", "Error opening database", "Can't access lock files' directory /tmp/firebird")

  17. #14
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Create firebird database programmatically with Qt

    Quote Originally Posted by guidupas View Post
    It returns me the error:

    QSqlError("-901", "Error opening database", "Can't access lock files' directory /tmp/firebird")
    What are the permissions on your /tmp/ and /tmp/firebird directories? The user you are running with will require write access to the /tmp and /tmp/firebird directories.

  18. #15
    Join Date
    Aug 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Create firebird database programmatically with Qt

    I find this on www an i hope, that this help You and others:

    Qt Code:
    1. bool CreateDB(const QString& filePath, const QString& userName, const QString& password)
    2. {
    3. if (QFile::exists(filePath))
    4. {
    5. return false;
    6. }
    7.  
    8. databasePath_ = filePath;
    9.  
    10. QString queryString;
    11. queryString += "CREATE DATABASE";
    12. queryString += " \'" + filePath + "\'";
    13. queryString += " USER \'" + userName + "\'";
    14. queryString += " PASSWORD \'" + password + "\'";
    15. queryString += " DEFAULT CHARACTER SET UNICODE_FSS";
    16.  
    17. ISC_STATUS_ARRAY status;
    18. isc_db_handle databaseHandle = NULL;
    19. isc_tr_handle transactionHandle = NULL;
    20.  
    21. unsigned short g_nFbDialect = SQL_DIALECT_V6;
    22.  
    23. if (isc_dsql_execute_immediate(status, &databaseHandle, &transactionHandle, 0, queryString.toStdString().c_str (), g_nFbDialect, NULL))
    24. {
    25. long SQLCODE=isc_sqlcode(status);
    26. return false;
    27. }
    28.  
    29. isc_commit_transaction( status, &transactionHandle );
    30.  
    31. if (databaseHandle != NULL)
    32. {
    33. ISC_STATUS_ARRAY status;
    34. isc_detach_database(status, &databaseHandle);
    35. }
    36.  
    37. return true;
    38. }
    To copy to clipboard, switch view to plain text mode 
    Of course You must have Firebird installed and into Your project You must add
    include ibase.h
    and
    library fbclient

    Regards.
    Last edited by ravelsk; 22nd August 2016 at 18:14.

Similar Threads

  1. How to Create sqlcipher database plugin for qt
    By malleeswarareddy.s in forum Qt Programming
    Replies: 2
    Last Post: 1st April 2014, 11:58
  2. Replies: 3
    Last Post: 27th December 2013, 15:43
  3. create database if not exist
    By snaderi in forum Qt Programming
    Replies: 4
    Last Post: 29th June 2013, 23:33
  4. Qt and embedded Firebird-Database
    By Djon in forum Installation and Deployment
    Replies: 0
    Last Post: 31st May 2010, 21:04
  5. Create database
    By waynew in forum Newbie
    Replies: 2
    Last Post: 8th October 2009, 13:10

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.