I always execute CREATE TABLE IF NOT EXISTS table .... after connecting.
Sent: Wednesday, April 22, 2015 at 10:08 PM
From: BRM <bm_witn...@yahoo.com>
To: "Tony Rietwyk" <t...@rightsoft.com.au>, "'Qt Project'" <interest@qt-project.org>
Subject: Re: [Interest] QtSql database insertion issues...
From: BRM <bm_witn...@yahoo.com>
To: "Tony Rietwyk" <t...@rightsoft.com.au>, "'Qt Project'" <interest@qt-project.org>
Subject: Re: [Interest] QtSql database insertion issues...
So I dove in more tonight; and discovered a rather dumb mistake - I forgot to initialize the database (e.g load the schema). prepare() had failed sometimes and other times not; seemed to be based on compile. Any how...it failed reliably tonight and when I added the lastError() data to the qDebug() statements it was evident that the tables were missing. Fixed that and...now it works. :)
Thanks for everyone that looked at it, and the ideas.
Now on to finishing the functionality...
Ben
On Wednesday, April 22, 2015 12:12 AM, BRM <bm_witn...@yahoo.com> wrote:
The "prepare(...)" does seem to work.
One thing that really confuses me is that even though I use the named bindings, it always lists the bindings as '?' in the error messages.
Ben
On Tuesday, April 21, 2015 11:20 PM, Tony Rietwyk <t...@rightsoft.com.au> wrote:
Hi Ben,
Does the prepare work?
I assume the database must be open, or you would get a different message.
Hope that helps,
Tony
From: interest-bounces+tony=rightsoft.com...@qt-project.org [mailto:interest-bounces+tony=rightsoft.com...@qt-project.org] On Behalf Of BRM
Sent: Wednesday, 22 April 2015 12:42 PM
To: Qt Project
Subject: [Interest] QtSql database insertion issues...
Sent: Wednesday, 22 April 2015 12:42 PM
To: Qt Project
Subject: [Interest] QtSql database insertion issues...
I've been out of the Qt loop for a little bit; but I'm working to bring myself back up to speed.
I'm presently working on a small project that is basically a GUI equivalent of md5sum/sha1sum where I'm attempting to store the data in a SQLite Database during run-time. I've already done a command-line version using python, and I'm pulling the SQL statements from there. However, I am having trouble with the QSqlQuery prepared statements. The entire code chunk is here:
I'm building the project on Kubuntu 14.10, using the Qt4.8 libraries provided by the distro.
To summarize the code, I'm doing the following:
QSqlQuery insertion(myDb);
insertion.prepare("INSERT INTO master_directory (hash, path) VALUES(:hash, :path)");
insertion.bindValue(":hash", "some hash");
insertion.bindValue(":path", "/some/path");
if (!insertion.exec()) qDebug() << "insertion failed. Log errors and value bindings";
I've added debug output that shows the values being bound; however, it continues to complain about a parameter mismatch.
You can see the output here:
I've tried binding both by name (preferred) and by order. (I have a C Preprocessor Define to control it); but neither are working.
This is my first time really playing with a database via Qt.
What am I doing wrong?
TIA,
Ben
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest