<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Maximum number of boundValues QSqlQuery]]></title><description><![CDATA[<p dir="auto">Hi guys,</p>
<p dir="auto">i build some own classes and functions to build my query strings. It seems working till I build a multi insert including 100 rows and 11 values per row. I got the error: parameter count mismatch. I found a functions some time ago to maintain my query strings (posted below). The executed query is fine, if I copy, paste and execute the stmt directly in SQLiteStudio there is no error.<br />
I made some further tests and i realized the the maximum number of boundValues must be 1.000. I can insert exactly 90 rows. I get the error if my rows have a number&gt;91.<br />
I am using Visual Studio 2015 IDE and compiler and Qt 5.9.1<br />
Is there a know limit of boundValues?</p>
<pre><code>QString qtdb::getLastExecutedQuery(const QSqlQuery &amp; query)
{
	QString sql = query.executedQuery();
	int nbBindValues = query.boundValues().size();

	for (int i = 0, j = 0; j &lt; nbBindValues;)
	{
		int s = sql.indexOf(QLatin1Char('\''), i);
		i = sql.indexOf(QLatin1Char('?'), i);
		if (i &lt; 1)
		{
			break;
		}

		if (s &lt; i &amp;&amp; s &gt; 0)
		{
			i = sql.indexOf(QLatin1Char('\''), s + 1) + 1;
			if (i &lt; 2)
			{
				break;
			}
		}
		else
		{
			const QVariant &amp;var = query.boundValue(j);
			QSqlField field(QLatin1String(""), var.type());
			if (var.isNull())
			{
				field.clear();
			}
			else
			{
				field.setValue(var);
			}
			QString formatV = query.driver()-&gt;formatValue(field);
			sql.replace(i, 1, formatV);
			i += formatV.length();
			++j;
		}
	}

	return sql;
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/92975/maximum-number-of-boundvalues-qsqlquery</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Jul 2026 06:50:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/92975.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 23 Jul 2018 21:50:11 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Wed, 25 Jul 2018 18:58:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stephocke">@<bdi>Stephocke</bdi></a><br />
Well getting the header is not overly complicated.<br />
If you used the online installer to install Qt, you just<br />
open maintenance.exe in Qt folder<br />
and select the source under the Qt u are using.<br />
<img src="http://imagizer.imageshack.com/img921/3703/UzBPOs.png" alt="alt text" class=" img-fluid img-markdown" /></p>
<p dir="auto">but if the workaround is acceptable, i guess its easier.</p>
]]></description><link>https://forum.qt.io/post/472032</link><guid isPermaLink="true">https://forum.qt.io/post/472032</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 25 Jul 2018 18:58:43 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Wed, 25 Jul 2018 17:01:53 GMT]]></title><description><![CDATA[<p dir="auto">Ok, thx.  A completely different solution, from one problem to the next to call one function, that is out of proportion. Then i dont need it either. I'll add an if(i&gt;1000) compute the corresponding string, prepare the query again and fire the stmt successfully.</p>
]]></description><link>https://forum.qt.io/post/472022</link><guid isPermaLink="true">https://forum.qt.io/post/472022</guid><dc:creator><![CDATA[Stephocke]]></dc:creator><pubDate>Wed, 25 Jul 2018 17:01:53 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Wed, 25 Jul 2018 16:50:45 GMT]]></title><description><![CDATA[<p dir="auto">you have to use the sqlite3.h from the related qt source package - it is not shipped with the binary package since it is normally not needed at all.</p>
]]></description><link>https://forum.qt.io/post/472019</link><guid isPermaLink="true">https://forum.qt.io/post/472019</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Wed, 25 Jul 2018 16:50:45 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Wed, 25 Jul 2018 16:50:34 GMT]]></title><description><![CDATA[<p dir="auto">Thank you, I dont know this post. I will use it as soon as I can access sqlite components in my project. But as i said, there is no sqlite related in my Qt folder. There isnt even a "src" folder. No sqlite.h, no third party folder, no sql_sqlite.h, no sqlite3.h, no qsqlite.lib. There is only a qsqlite.dll within .../plugins/qsqldirver</p>
]]></description><link>https://forum.qt.io/post/472018</link><guid isPermaLink="true">https://forum.qt.io/post/472018</guid><dc:creator><![CDATA[Stephocke]]></dc:creator><pubDate>Wed, 25 Jul 2018 16:50:34 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Wed, 25 Jul 2018 16:22:49 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
im no expert but i think you dont need to compile it again.<br />
please see here<br />
<a href="https://stackoverflow.com/questions/34415351/adding-a-custom-sqlite-function-to-a-qt-application" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/34415351/adding-a-custom-sqlite-function-to-a-qt-application</a><br />
note the sqlite3_initialize<br />
that should allow u to call sqlite3_limit</p>
]]></description><link>https://forum.qt.io/post/472010</link><guid isPermaLink="true">https://forum.qt.io/post/472010</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Wed, 25 Jul 2018 16:22:49 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Wed, 25 Jul 2018 15:45:37 GMT]]></title><description><![CDATA[<p dir="auto">I think you are right, it must be SQLITE_LIMIT_VARIABLE_NUMBER</p>
<p dir="auto">I have found this function within the documentation and i want to try to increase the limit.</p>
<pre><code>sqlite3_limit(sqlite3*, int id, int newVal);
</code></pre>
<p dir="auto">But I am completely overwhelmed. It is again typical C ++, instructions from experts for experts. I already noticed I cannot include &lt;qsql_sqlite.h&gt; - there is no such header file. So I thought mabye I have to set some includes within the project-&gt;properties-&gt;linker - add an include path and a .lib. On the official homepage of sqlite I am not able to find a .lib and header file download. I already downloaded some .dlls and the complete source code. Do I have to build my own lib from the source code? I never did this before. Did I just miss the right Qt include header? Or do i have to download the source code of qsql_sqlite.h and qsql_sqlite.cpp and paste it into the Qt path?<br />
What do I have to do?</p>
]]></description><link>https://forum.qt.io/post/472004</link><guid isPermaLink="true">https://forum.qt.io/post/472004</guid><dc:creator><![CDATA[Stephocke]]></dc:creator><pubDate>Wed, 25 Jul 2018 15:45:37 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Tue, 24 Jul 2018 07:26:43 GMT]]></title><description><![CDATA[<p dir="auto">I think what you are looking for is <a href="https://doc.qt.io/qt-5/qsqlquery.html#execBatch" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qsqlquery.html#execBatch</a></p>
<p dir="auto">The maximum number of batch rows is determined by your database MS SQL Server has 250 limit if I'm not mistaken</p>
]]></description><link>https://forum.qt.io/post/471672</link><guid isPermaLink="true">https://forum.qt.io/post/471672</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Tue, 24 Jul 2018 07:26:43 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Tue, 24 Jul 2018 04:37:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/stephocke">@<bdi>Stephocke</bdi></a></p>
<p dir="auto">Hi<br />
i think maybe its the<br />
SQLITE_LIMIT_VARIABLE_NUMBER (default value: 999).<br />
you are hitting ?<br />
<a href="https://www.sqlite.org/c3ref/bind_blob.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.sqlite.org/c3ref/bind_blob.html</a></p>
]]></description><link>https://forum.qt.io/post/471638</link><guid isPermaLink="true">https://forum.qt.io/post/471638</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Tue, 24 Jul 2018 04:37:21 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Tue, 24 Jul 2018 01:12:04 GMT]]></title><description><![CDATA[<p dir="auto">I build a "small" example of what is happening ... and 1000 boundValues are the limit.<br />
I can insert 200 rows but "parameter count missmatch" from rows&gt;200</p>
<pre><code>
#include &lt;QtCore/QCoreApplication&gt;
#include &lt;QtSql&gt;


int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);


	QSqlDatabase database;
	database = QSqlDatabase::addDatabase("QSQLITE");
	database.setDatabaseName("testDb.sqlite");

	if (!database.open())
	{
		qDebug() &lt;&lt; "cannot open database";
		return 0;
	}

	QSqlQuery query;

	std::vector&lt;QVariant&gt; aux{ "coolio",2.78,13.5,1 };
	std::vector&lt;QVariant&gt; binds;
	binds.push_back(1);
	binds.insert(binds.end(), aux.begin(), aux.end());
	binds.reserve(1250);
	QString insertStr = "INSERT INTO testTable (id,desc,firstDouble,secondDouble,firstInt) VALUES (?,?,?,?,?)";
	for (int i = 2; i &lt; 200; i++)
	{
		insertStr += ",(?,?,?,?,?)";
		binds.push_back(i);
		binds.insert(binds.end(), aux.begin(), aux.end());
	}
	
	query.prepare(insertStr);
	for (auto&amp; e : binds)
		query.addBindValue(e);

	if (!query.exec())
	{
		qDebug() &lt;&lt; "cannot insert into database";
		qDebug() &lt;&lt; query.lastError().text();
	}
	else
	{
		qDebug() &lt;&lt; "yes!";
	}
	database.close();

	return a.exec();
}
</code></pre>
]]></description><link>https://forum.qt.io/post/471628</link><guid isPermaLink="true">https://forum.qt.io/post/471628</guid><dc:creator><![CDATA[Stephocke]]></dc:creator><pubDate>Tue, 24 Jul 2018 01:12:04 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Mon, 23 Jul 2018 22:54:16 GMT]]></title><description><![CDATA[<p dir="auto">update: If I prepare the query a second time with the debugger string, the stmt is executed successfully ... strange. So its really looks like a limit of boundValues<br />
(a row is a customer container including "dbEntities"{columnName, QVariant value, operator})</p>
<pre><code>bool qtdb::dbInsert::query()
{
	if (rows.size() == 0)
		return true;

	qry.prepare(str());

	for (int i = 0; i &lt; rows.size(); i++)
	{
		for (int j = 0; j &lt; cols; j++)
		{
			qry.addBindValue(rows[i].getEntry(j)-&gt;getValue());
		}
	}
	QString debugger = getLastExecutedQuery(qry);
	qry.prepare(debugger);
	bool success = qry.exec();

	lastInsertId = qry.lastInsertId().isValid() ? qry.lastInsertId().toInt() : -1;

	return success;
}
</code></pre>
<p dir="auto">The unprepared stmt the qry receiving from the member function str() looks like:<br />
INSERT INTO patients (id,name,tw_start,tw_end,xCoordinate,yCoordinate,service,duration,id_session,id_problem,type) VALUES (?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?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,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?)</p>
<p dir="auto">There is no unique constraint fail of the database.</p>
]]></description><link>https://forum.qt.io/post/471619</link><guid isPermaLink="true">https://forum.qt.io/post/471619</guid><dc:creator><![CDATA[Stephocke]]></dc:creator><pubDate>Mon, 23 Jul 2018 22:54:16 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Mon, 23 Jul 2018 22:06:03 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">Can you share the query that triggers that ?</p>
]]></description><link>https://forum.qt.io/post/471614</link><guid isPermaLink="true">https://forum.qt.io/post/471614</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 23 Jul 2018 22:06:03 GMT</pubDate></item><item><title><![CDATA[Reply to Maximum number of boundValues QSqlQuery on Mon, 23 Jul 2018 21:58:59 GMT]]></title><description><![CDATA[<p dir="auto">Hi And welcome to the forums.<br />
its seems to be using a vector internally<br />
<img src="http://imagizer.imageshack.com/img921/8881/q7brxt.png" alt="alt text" class=" img-fluid img-markdown" /></p>
<p dir="auto">so i do not think there should be a fixed limit besides memory.</p>
<p dir="auto"><a href="https://code.woboq.org/qt5/qtbase/src/sql/kernel/qsqlquery.cpp.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://code.woboq.org/qt5/qtbase/src/sql/kernel/qsqlquery.cpp.html</a></p>
]]></description><link>https://forum.qt.io/post/471613</link><guid isPermaLink="true">https://forum.qt.io/post/471613</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 23 Jul 2018 21:58:59 GMT</pubDate></item></channel></rss>