#include <QtCore>
#include <QtSql>
#include <QDebug>
int main(int argc, char **argv)
{
db.setHostName("newton");
db.setDatabaseName("test");
db.setUserName("test");
db.setPassword("password");
bool ok = db.open();
qDebug() << "Opened:" << ok;
db.exec(
"CREATE TABLE IF NOT EXISTS crawl_virtuemart_categories ("
" virtuemart_category_id int(11) NOT NULL,"
" virtuemart_vendor_id int(11) NOT NULL,"
" category_layout varchar(10) NOT NULL,"
" category_product_layout varchar(10) NOT NULL,"
" products_per_row int(11) NOT NULL,"
" limit_list_start int(11) NOT NULL,"
" limit_list_step int(11) NOT NULL,"
" limit_list_max int(11) NOT NULL,"
" limit_list_initial int(11) NOT NULL,"
" ordering int(11) NOT NULL,"
" finished int(11) NOT NULL,"
" PRIMARY KEY (virtuemart_category_id)"
") "
);
// Your code
insQuery.prepare("INSERT INTO crawl_virtuemart_categories (virtuemart_category_id, virtuemart_vendor_id, category_layout, category_product_layout, products_per_row, limit_list_start, limit_list_step, limit_list_max, limit_list_initial, ordering, finished) VALUES ( :id , 1, 'default', 'default', 3, 0, 10, 0, 10, 1, 1)");
insQuery.bindValue(":id",100);
// end of your code
ok = insQuery.exec();
qDebug() << "Insert:" << ok;
if (!ok)
qDebug() << insQuery.lastError();
return 0;
}
#include <QtCore>
#include <QtSql>
#include <QDebug>
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("newton");
db.setDatabaseName("test");
db.setUserName("test");
db.setPassword("password");
bool ok = db.open();
qDebug() << "Opened:" << ok;
db.exec(
"CREATE TABLE IF NOT EXISTS crawl_virtuemart_categories ("
" virtuemart_category_id int(11) NOT NULL,"
" virtuemart_vendor_id int(11) NOT NULL,"
" category_layout varchar(10) NOT NULL,"
" category_product_layout varchar(10) NOT NULL,"
" products_per_row int(11) NOT NULL,"
" limit_list_start int(11) NOT NULL,"
" limit_list_step int(11) NOT NULL,"
" limit_list_max int(11) NOT NULL,"
" limit_list_initial int(11) NOT NULL,"
" ordering int(11) NOT NULL,"
" finished int(11) NOT NULL,"
" PRIMARY KEY (virtuemart_category_id)"
") "
);
// Your code
QSqlQuery insQuery;
insQuery.prepare("INSERT INTO crawl_virtuemart_categories (virtuemart_category_id, virtuemart_vendor_id, category_layout, category_product_layout, products_per_row, limit_list_start, limit_list_step, limit_list_max, limit_list_initial, ordering, finished) VALUES ( :id , 1, 'default', 'default', 3, 0, 10, 0, 10, 1, 1)");
insQuery.bindValue(":id",100);
// end of your code
ok = insQuery.exec();
qDebug() << "Insert:" << ok;
if (!ok)
qDebug() << insQuery.lastError();
return 0;
}
To copy to clipboard, switch view to plain text mode
(provided a row with id == 100 does not already exist)
Bookmarks