PDA

View Full Version : MySQL - Returning a value in a record



ksqt
11th September 2006, 02:27
I cannot seem to return text from a record in a table..:confused:
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)


void Dialog::translate()
{
QString bg;
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("");
db.setDatabaseName("enbg_database");
db.setUserName("");
db.setPassword("");
bool ok = db.open();

QSqlQuery query;
bool queryok = query.exec("select bg_word from enbg_table where id=1");
while(query.next())
{
bg = query.value(0).toString();
}

translated_bg->setText(bg);
}

ksqt
13th September 2006, 01:12
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.

sunil.thaha
13th September 2006, 09:52
Is bg_word a field or data ?
Query seems to be fine.

Whatis the return value for the open()

ksqt
13th September 2006, 13:48
bg_word is a field in the table.
If I change the query, I can have an integer show, so open() is "working".....:o

sunil.thaha
13th September 2006, 14:26
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

ksqt
13th September 2006, 18:50
That doesn't work....
and it is varchar...

sunil.thaha
14th September 2006, 06:00
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 :confused:

what was the output of the debug