I am having issues making my program insert data into an SQLLite db file. I am a bit lost due to the ambigious error message aswell, as I am passing the correct parameters to the insert command(?)
Here is the SQL Lite Table structure:
CREATE TABLE inventory (
id INT PRIMARY KEY NOT NULL,
name CHAR(120) NOT NULL,
description TEXT,
category INT,
employee INT,
location INT
);
CREATE TABLE inventory (
id INT PRIMARY KEY NOT NULL,
name CHAR(120) NOT NULL,
description TEXT,
category INT,
employee INT,
location INT
);
To copy to clipboard, switch view to plain text mode
And here is my QT/C++ Code:
if (!this->db.open()) {
qDebug() <<this->db.lastError().text();
}
query.prepare
("INSERT INTO inventory (name, description, category) VALUES (?,?,?)");
query.addBindValue(name);
query.addBindValue(description);
query.addBindValue(category);
if (!query.exec()) {
qDebug() <<query.lastError().text();
}
QSqlQuery query(this->db);
if (!this->db.open()) {
qDebug() <<this->db.lastError().text();
}
query.prepare
("INSERT INTO inventory (name, description, category) VALUES (?,?,?)");
query.addBindValue(name);
query.addBindValue(description);
query.addBindValue(category);
if (!query.exec()) {
qDebug() <<query.lastError().text();
}
To copy to clipboard, switch view to plain text mode
For the record, the QSqlDatabase object is initiated in the constructor, and I am able to run SELECT queries from the database. So the connection works ....
this
->db
= QSqlDatabase::addDatabase("QSQLITE",
"NETTO_CONNECTION");
this->db.setDatabaseName(settings.value("db").toString());
QSettings settings;
this->db = QSqlDatabase::addDatabase("QSQLITE", "NETTO_CONNECTION");
this->db.setDatabaseName(settings.value("db").toString());
To copy to clipboard, switch view to plain text mode
Any ideas to what I am doing wrong here?
Bookmarks