Results 1 to 5 of 5

Thread: create database if not exist

  1. #1
    Join Date
    May 2012
    Posts
    2
    Qt products
    Qt4

    Default create database if not exist

    hello,I create an app that use for save data,but i have an problom!I want when my app execute on other computer for the frist time,automatically create databse on that comuter if not exist! please help me!!

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: create database if not exist

    I don't think this is qt relevant question. check the format of the query regarding to the DBMS you are using, CREATE TABLE IF NOT EXISTS is for mysql I guess.

  3. #3
    Join Date
    May 2012
    Posts
    2
    Qt products
    Qt4

    Default Re: create database if not exist

    my connecting file cantains this code:
    Qt Code:
    1. bool createConnection()
    2. {
    3. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    4. db.setHostName("localhost");
    5. db.setDatabaseName("sa2");
    6. db.setUserName("root");
    7. db.setPassword("");
    8.  
    9. if (!db.open()) {
    10. QMessageBox::critical(0,QObject::tr("Database Error"),
    11. db.lastError().text());
    12. return false;
    13. }
    14.  
    15. return true;
    16.  
    17.  
    18. }
    To copy to clipboard, switch view to plain text mode 

    I have only one problem and thats is I forced to create db manually when I execute my app another computer.I want my db create automatically!

  4. #4
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: create database if not exist

    There should of course be api functions relevant to db_create or db_query and alike. Go through my sql c api functions and execute either the create function or the query function and write the query i mentioned above as a parameter.

  5. #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 database if not exist

    You will need a MySql privileged user account, connect to the mysql system database as that user, execute a "create database" statement, statements to create tables, and statements to create users and/or grant privileges. Then disconnect as the privileged user, connect as the usual minimally privileged user to continue using your new database.

Similar Threads

  1. IS this allright + how to see if it exist
    By Nazgul in forum Newbie
    Replies: 15
    Last Post: 18th March 2011, 23:01
  2. rcc: File does not exist
    By lyuts in forum Qt Programming
    Replies: 2
    Last Post: 18th October 2010, 08:26
  3. Create database
    By waynew in forum Newbie
    Replies: 2
    Last Post: 8th October 2009, 12:10
  4. QSqlDatabase and "CREATE DATABASE ..." ??
    By codematic in forum Qt Programming
    Replies: 19
    Last Post: 11th April 2009, 06:28
  5. XML Database: eXist
    By Lykurg in forum Qt Programming
    Replies: 3
    Last Post: 6th March 2007, 23:22

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.