Results 1 to 7 of 7

Thread: MySQL - Returning a value in a record

  1. #1
    Join Date
    Mar 2006
    Posts
    58
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default MySQL - Returning a value in a record

    I cannot seem to return text from a record in a table..
    In this function - "bg_word" is a text string in a record in a table.
    I can return an integer if I make the necessary changes, but not text...
    What am I missing?
    (Yes, there is warnings of not using the two bools - not important at this point)

    Qt Code:
    1. void Dialog::translate()
    2. {
    3. QString bg;
    4. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    5. db.setHostName("");
    6. db.setDatabaseName("enbg_database");
    7. db.setUserName("");
    8. db.setPassword("");
    9. bool ok = db.open();
    10.  
    11. QSqlQuery query;
    12. bool queryok = query.exec("select bg_word from enbg_table where id=1");
    13. while(query.next())
    14. {
    15. bg = query.value(0).toString();
    16. }
    17.  
    18. translated_bg->setText(bg);
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 11th September 2006 at 09:35. Reason: missing [code] tags

  2. #2
    Join Date
    Mar 2006
    Posts
    58
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL - Returning a value in a record

    Any ideas why the string is returning (I think) null or empty?
    Sorry for the bump, but I can't seem to figure this one out.

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL - Returning a value in a record

    Is bg_word a field or data ?
    Query seems to be fine.

    Whatis the return value for the open()
    We can't solve problems by using the same kind of thinking we used when we created them

  4. #4
    Join Date
    Mar 2006
    Posts
    58
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL - Returning a value in a record

    bg_word is a field in the table.
    If I change the query, I can have an integer show, so open() is "working".....

  5. #5
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL - Returning a value in a record

    Try printing bg inside while() ...

    Also what is the datatype of bg_word in mysql is it varchar ...

    and Ya. Try printing the type of QVariant
    We can't solve problems by using the same kind of thinking we used when we created them

  6. #6
    Join Date
    Mar 2006
    Posts
    58
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL - Returning a value in a record

    That doesn't work....
    and it is varchar...

  7. #7
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MySQL - Returning a value in a record

    Again.

    Did to put a debug inside while and see what is you are getting.
    And what is the type of the QVariant ?

    May be the query returns 2 values and the old bg may be getting overwritten

    what was the output of the debug
    We can't solve problems by using the same kind of thinking we used when we created them

Similar Threads

  1. Replies: 7
    Last Post: 12th August 2006, 15:11
  2. Qt 4.1.4 & Mysql 5 on Linux x64
    By bothapn in forum Installation and Deployment
    Replies: 7
    Last Post: 4th August 2006, 13:23
  3. connecting to MySQL through it's API
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 20
    Last Post: 30th May 2006, 23:22
  4. Qt 4.1 OS on Windows & mysql
    By neeko in forum Installation and Deployment
    Replies: 10
    Last Post: 31st January 2006, 20:22
  5. Record update windowd entered data saving
    By MarkoSan in forum Qt Programming
    Replies: 56
    Last Post: 18th January 2006, 18:50

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.