I am trying to insert huge data in sqlite, to gain performance, I am using transaction statement. My code looks like this:
CSVParser parser;
query.exec("BEGIN TRANSACTION;");
while (!file.atEnd())
{
line = file.readLine();
if (line == "")
continue;
parser << line.toStdString(); // Feed the line to the parser
// Now extract the columns from the line
parser >> sCol1 >> sCol2 >> sCol3 >> sCol4;
// Method one to insert data
sqlQuery = "INSERT INTO Person(phone, name, firstname, lastname) VALUES (" \
"'" + QString(sCol1.c_str()) + \
"','" + QString(sCol2.c_str()) + \
"','" + QString(sCol4.c_str()) + \
"','" + QString(sCol3.c_str()) + "')";
//query.exec(sqlQuery);
// Method two to insert data
query.prepare("INSERT INTO Person(phone, name, firstname, lastname) VALUES (:phone, :name, firstname, :lastname");
query.bindValue(":phone", QString(sCol1.c_str()));
query.bindValue(":name", QString(sCol2.c_str()));
query.bindValue(":firstname", QString(sCol4.c_str()));
query.bindValue(":lastname", QString(sCol3.c_str()));
query.exec();
cout << query.lastError().text().toStdString();
}
query.exec("END TRANSACTION;");
If I use the first method, the data inserted fine, but the problem may occur later if a text contains charcarter like this “‘”. To avoid this, I switched to prepared statement, a new problem, no data inserted. The only error I see:
Parameter count mismatch Parameter count mismatch Parameter count
mismatch Parameter count mismatch Parameter count mismatch Parameter
count mismatch Parameter count mismatch Parameter count mismatch
Is there I am missing here?
I wonder if this is the cause: