How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
I am using the following code: but it fails. Kindly help on this:
Code:
bool ok=false;
db.setHostName("localhost");
db.setDatabaseName("screengrabber");
db.setUserName("root");
db.setPassword("1");
ok = db.open();
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
What is the result of QSqlDatabase::drivers function call ?
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
It gives QSQLLITE,QODBC3, QODBC
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
That means you do not have MYSQL driver plug-in. See this thread ... or search on QtCentre other threads related to this problem ...
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
Connection Succeeds, But inserting fails. Am using the following code:
Code:
QFile file("D:\\image1.jpeg");
file.seek(0);
buf=file.read(250000);
query.prepare("INSERT INTO log VALUES(grab_date='2011-04-26 15:55:09',ip_address='172.16.0.51',image=:val);");
query.bindValue ( ":val", buf);
query.exec();
Here image is the BLOB field in the database.
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
If you write prepare statement as: INSERT INTO log(grab_date, ip_address, image) VALUES ('2011-04-26 15:55:09','172.16.0.51',:val) did it work ?
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
I have tried with both the methods, still fails
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
What is the return of last error ?
Re: How to connect QT with MYSQL and perform opeartions like Insert,Delete,Update?
Quote:
Originally Posted by
Gokulnathvc
Connection Succeeds, But inserting fails.
Did you manage to download MySQL, build the Qt MySQL plugin, and make it work in the twenty minutes between posts 4 and 5?
You say this fails:
Quote:
Am using the following code:
Code:
QFile file("D:\\image1.jpeg");
file.seek(0);
buf=file.read(250000);
query.prepare("INSERT INTO log VALUES(grab_date='2011-04-26 15:55:09',ip_address='172.16.0.51',image=:val);");
query.bindValue ( ":val", buf);
query.exec();
Here image is the BLOB field in the database.
What about it fails?
Does a row get created without data in the blob column, is the blob data incomplete, or does no row get created?
What does QSqlQuery::lastError() tell you after each line? Cincirin identifies the really obvious invalid SQL problem but you say it still doesn't work.
Taking a step back: are you sure the file was opened successfully? You don't check. Are you sure the file had data to read and that it ended up in the QByteArray? Are you sure that 250000 bytes is large enough?
Unless you get into the habit of checking error return values, warning and messages you will always be thrashing about guessing.