Re: QSqlQuery not working
Try to identify the problem using QSqlQuery::lastError().
Re: QSqlQuery not working
Quote:
Originally Posted by
saa7_go
Try to identify the problem using QSqlQuery::lastError().
it returns -1, no error =T
Re: QSqlQuery not working
If you modify your codes to the following:
Code:
int ProductsForm::categoryIdByName(const QString& name)
{
categories.
exec(QString("SELECT id FROM Categories WHERE name='%1'").
arg(name
));
if(categories.size()==-1)
{
qDebug() << "error";
return 1;
}
.....
}
is categories.size() value still -1 ?
Re: QSqlQuery not working
Quote:
Originally Posted by
saa7_go
If you modify your codes to the following:
Code:
int ProductsForm::categoryIdByName(const QString& name)
{
categories.
exec(QString("SELECT id FROM Categories WHERE name='%1'").
arg(name
));
if(categories.size()==-1)
{
qDebug() << "error";
return 1;
}
.....
}
is categories.size() value still -1 ?
yesss...:(
Re: QSqlQuery not working
Code:
int ProductsForm::categoryIdByName(const QString& name)
{
categories.
exec(QString("SELECT id FROM Categories WHERE name='%1'").
arg(name
));
categories.first();
return categories.value(0).toInt();
it works now, and i still don't know why! ^^" but thanks anyway :)
Re: QSqlQuery not working
Are you using sqlite database? If you are using sqlite, it doesn't support reporting information about query sizes. So, this is why you always get -1.
Re: QSqlQuery not working
Quote:
Originally Posted by
saa7_go
Are you using sqlite database? If you are using sqlite, it doesn't support reporting information about query sizes. So, this is why you always get -1.
yes, i'm using sqlite :eek:
:o
Re: QSqlQuery not working
Quote:
Originally Posted by
BrainStorm
yes, i'm using sqlite
then you can check via
Code:
categories.prepare("SELECT id FROM Categories "
"WHERE name=:name)");
categories.bindValue(":name",name);
categories.exec();
if (!categories.next())
{
// error and return;
}
categories.value(0)/*...*/
Re: QSqlQuery not working
Is this code "copy and paste" ? If YES, You have an error in line 2. Signe ) after :name.
Re: QSqlQuery not working
Quote:
Originally Posted by
Lykurg
then you can check via
Code:
categories.prepare("SELECT id FROM Categories "
"WHERE name=:name)");
categories.bindValue(":name",name);
categories.exec();
if (!categories.next())
{
// error and return;
}
categories.value(0)/*...*/
i see.. but i think using QSqlQuery::next(); once is the same as using QSqlQuery::first(); :)
Re: QSqlQuery not working
By the way, does anyone knows how to create a button (flat would be nice) that drops a drop menu? :p
Re: QSqlQuery not working
Quote:
Originally Posted by
BrainStorm
i see.. but i think using QSqlQuery::next(); once is the same as using QSqlQuery::first(); :)
Yes, missed that, since in the code snippet the return was not checked if it is valid.
Quote:
Originally Posted by
BrainStorm
By the way, does anyone knows how to create a button (flat would be nice) that drops a drop menu? :p
Use a normal buttun and set a menu via QPushButton::setMenu(). for flat use QPushButton::setFlat().
Re: QSqlQuery not working
Quote:
Originally Posted by
Lykurg
Ohh.. i see ^^ thanks, i was using QMenu::popup() with QPushButton::pos() :p