Results 1 to 12 of 12

Thread: i want show all databases names in my project?

  1. #1
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Question i want show all databases names in my project?

    hi

    i need to show all databases in my mysql engine

    1-open database is ok,

    QSqlQuery get_query(QSqlDatabase::database("MY_DB_1")); get_query.prepare("show databases");
    get_query.exec(); // is ok
    get_query.size(); // = -1 ??? i have many databases

    but in mysql command 'cmd' , the query 'show databases' is run normal and show all databases;

    what is the problem??

    plase help me.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: i want show all databases names in my project?

    Which database do you use? Some don't have the possibility to get the affected rows... Just try to print the names out and see if they appear:
    Qt Code:
    1. while (get_query.next())
    2. qWarning() << get_query.value(0).toString();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i want show all databases names in my project?

    I have tried
    but result no thing

    example

    1-open database is ok,

    QSqlQuery get_query(QSqlDatabase::database("MY_DB_1"));
    get_query.prepare("select * from students");
    get_query.exec(); // is ok
    get_query.size(); // = 23
    get_query.next(); // returned true

    very nice
    but

    QSqlQuery get_query(QSqlDatabase::database("MY_DB_1"));
    get_query.prepare("show databases");
    get_query.exec(); // is ok
    get_query.size(); // = -1
    get_query.next(); // returned false

    but in mysql cmd the two cases is ok,

    what is the problem in qt code in case 'show databases'?

  4. #4
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 4 Times in 3 Posts

    Default Re: i want show all databases names in my project?

    I'm doing pretty much the same as you in a project, and the "show databases" statement works fine. Are you logging in as the same user both on the command line and in your Qt code? Could there be some issues with permissions? Performing a query and listing databases requires different grants in MySQL.

  5. #5
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i want show all databases names in my project?

    thanks
    i am used root user , the root user have all rights
    ,plase show me example for grant statment for 'show databases' query.

  6. #6
    Join Date
    Dec 2009
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 4 Times in 3 Posts

    Default Re: i want show all databases names in my project?

    This is described in MySQL's reference manual on the GRANT syntax. Basically you have to GRANT SHOW DATABASES ON mydb.* TO 'someuser'@'somehost';

  7. #7
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i want show all databases names in my project?

    thanks
    I have tried
    i have all rights in root user, and in cmd is all queries works in root user , the problem in qt code.

    the queries 'select , insert , delete , create update' is works,
    but 'show databases' and 'describe tb1' and 'show tables' not works in QSqlQuery Functions

    Concluded
    the Functions " size(), next() , first(), last(), value(int) " is works in select statment only.
    in other words
    the Previous functions is works in table data created from 'select query', but not works in table data created from 'show queries' and 'describe'.

    Am I right?

  8. #8
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: i want show all databases names in my project?

    Can you post the error you get? You can fetch the error using this:
    Qt Code:
    1. QString someQuery = "select whatever you want;"
    2. query.exec(someQuery);
    3. if (query.lastError().isValid())
    4. {
    5. qDebug() << "Error: " << query.lastError().text()
    6. << " in query " << query.lastQuery();
    7. // ...
    8. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Tanuki-no Torigava; 19th December 2009 at 12:53.

  9. #9
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i want show all databases names in my project?

    hi

    I tried

    see
    get_query2.prepare("show databases"); // returned 1 is ok
    get_query2.exec(); // returned 1 is ok
    get_query2.next(); // returned false ??
    get_query2.size(); // -1 ??
    QSqlError _sqlError = get_query2.lastError();
    QString _error = _sqlError.text();
    // _error now "" empty
    the Functions " size(), next() , first(), last(), value(int) " is works in table data created from 'select query'.

    ineed to 'show databases' an 'show tables' query. !!!!

  10. #10
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1
    Thanked 4 Times in 4 Posts

    Default Re: i want show all databases names in my project?

    It seems to me that select from system tables is the only way to get the list. Also you can check the code of any open source MySQL managers for a hint.

    Regards,
    -- tanuki

  11. #11
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i want show all databases names in my project?

    Quote Originally Posted by Tanuki-no Torigava View Post
    It seems to me that select from system tables is the only way to get the list. Also you can check the code of any open source MySQL managers for a hint.

    Regards,
    -- tanuki

    May be this is solution
    thanks for all

  12. #12
    Join Date
    Feb 2009
    Location
    libya
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: i want show all databases names in my project?

    If i am found a solution will tell you

Similar Threads

  1. Translation tools problems
    By MarkoSan in forum Qt Tools
    Replies: 23
    Last Post: 22nd August 2010, 01:43

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
  •  
Qt is a trademark of The Qt Company.