Results 1 to 4 of 4

Thread: database problem

  1. #1
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default database problem

    I do not have the mySql driver so i am trying to connect to mySql using odbc. It seems to connect and open but i can not query the database. can someone please help me out?


    Qt Code:
    1. {
    2. QSqlDatabase Db = QSqlDatabase::addDatabase("QODBC", "Calendar");
    3.  
    4. Db.setHostName("localhost");
    5. Db.setDatabaseName("mySql");
    6. Db.setUserName("root");
    7.  
    8. bool goodQuery;
    9. bool validrec;
    10. int x;
    11. x=1;
    12.  
    13. if(Db.open()) // database is open
    14. {
    15. QSqlQuery query(Db);
    16. query.exec("SELECT * from artist" );
    17. goodQuery=query.isActive(); // this returns true
    18. query.first();
    19. validrec=query.isValid(); // this returns false
    20. x=query.size(); // this returns -1
    21.  
    22. while(query.next()){
    23. new QListWidgetItem(tr("Hazel"), ui->listWidget); //this never executes
    24. }
    25. }
    26. Db.close();
    27. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: database problem

    i have further tracked this down

    query.lasterror() returns :
    QSqlError(0, "QODBC3: Unable to fetch first", " [iODBC][Driver Manager]Optional feature not implemented")

    what does this mean?

  3. #3
    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: database problem

    The query cursor is probably opened in a forward-only mode and cannot 'reverse' to the first record (or the ODBC driver does not support doing this). Comment out line 18 and see how you get on.

  4. #4
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: database problem

    thank you for your response, i did as you suggested :

    now the error is :QSqlError(-1, "", "") , looks like progress

Similar Threads

  1. problem creating a mysql database
    By TonyB in forum Qt Programming
    Replies: 10
    Last Post: 23rd July 2010, 15:39
  2. QString problem...
    By Nefastious in forum Newbie
    Replies: 17
    Last Post: 29th September 2009, 16:29
  3. database problem
    By mind_freak in forum Qt Programming
    Replies: 1
    Last Post: 3rd September 2009, 11:22
  4. Problem regarding database in Qt
    By sudheer168 in forum Qt Programming
    Replies: 4
    Last Post: 6th January 2009, 11:04
  5. Problem while inserting the data into database
    By sudheer168 in forum Qt Programming
    Replies: 2
    Last Post: 13th December 2008, 12:22

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.