Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Maximum number of boundValues QSqlQuery
Forum Updated to NodeBB v4.3 + New Features

Maximum number of boundValues QSqlQuery

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 5 Posters 2.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 23 Jul 2018, 21:58 last edited by mrjj
    #2

    Hi And welcome to the forums.
    its seems to be using a vector internally
    alt text

    so i do not think there should be a fixed limit besides memory.

    https://code.woboq.org/qt5/qtbase/src/sql/kernel/qsqlquery.cpp.html

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 23 Jul 2018, 22:06 last edited by
      #3

      Hi and welcome to devnet,

      Can you share the query that triggers that ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Stephocke
        wrote on 23 Jul 2018, 22:07 last edited by
        #4
        This post is deleted!
        1 Reply Last reply
        0
        • S Offline
          S Offline
          Stephocke
          wrote on 23 Jul 2018, 22:29 last edited by Stephocke
          #5

          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
          (a row is a customer container including "dbEntities"{columnName, QVariant value, operator})

          bool qtdb::dbInsert::query()
          {
          	if (rows.size() == 0)
          		return true;
          
          	qry.prepare(str());
          
          	for (int i = 0; i < rows.size(); i++)
          	{
          		for (int j = 0; j < cols; j++)
          		{
          			qry.addBindValue(rows[i].getEntry(j)->getValue());
          		}
          	}
          	QString debugger = getLastExecutedQuery(qry);
          	qry.prepare(debugger);
          	bool success = qry.exec();
          
          	lastInsertId = qry.lastInsertId().isValid() ? qry.lastInsertId().toInt() : -1;
          
          	return success;
          }
          

          The unprepared stmt the qry receiving from the member function str() looks like:
          INSERT INTO patients (id,name,tw_start,tw_end,xCoordinate,yCoordinate,service,duration,id_session,id_problem,type) VALUES (?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(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?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?),(?,?,?,?,?,?,?,?,?,?,?)

          There is no unique constraint fail of the database.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Stephocke
            wrote on 24 Jul 2018, 01:04 last edited by Stephocke
            #6

            I build a "small" example of what is happening ... and 1000 boundValues are the limit.
            I can insert 200 rows but "parameter count missmatch" from rows>200

            
            #include <QtCore/QCoreApplication>
            #include <QtSql>
            
            
            int main(int argc, char *argv[])
            {
            	QCoreApplication a(argc, argv);
            
            
            	QSqlDatabase database;
            	database = QSqlDatabase::addDatabase("QSQLITE");
            	database.setDatabaseName("testDb.sqlite");
            
            	if (!database.open())
            	{
            		qDebug() << "cannot open database";
            		return 0;
            	}
            
            	QSqlQuery query;
            
            	std::vector<QVariant> aux{ "coolio",2.78,13.5,1 };
            	std::vector<QVariant> 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 < 200; i++)
            	{
            		insertStr += ",(?,?,?,?,?)";
            		binds.push_back(i);
            		binds.insert(binds.end(), aux.begin(), aux.end());
            	}
            	
            	query.prepare(insertStr);
            	for (auto& e : binds)
            		query.addBindValue(e);
            
            	if (!query.exec())
            	{
            		qDebug() << "cannot insert into database";
            		qDebug() << query.lastError().text();
            	}
            	else
            	{
            		qDebug() << "yes!";
            	}
            	database.close();
            
            	return a.exec();
            }
            
            M 1 Reply Last reply 24 Jul 2018, 04:37
            0
            • S Stephocke
              24 Jul 2018, 01:04

              I build a "small" example of what is happening ... and 1000 boundValues are the limit.
              I can insert 200 rows but "parameter count missmatch" from rows>200

              
              #include <QtCore/QCoreApplication>
              #include <QtSql>
              
              
              int main(int argc, char *argv[])
              {
              	QCoreApplication a(argc, argv);
              
              
              	QSqlDatabase database;
              	database = QSqlDatabase::addDatabase("QSQLITE");
              	database.setDatabaseName("testDb.sqlite");
              
              	if (!database.open())
              	{
              		qDebug() << "cannot open database";
              		return 0;
              	}
              
              	QSqlQuery query;
              
              	std::vector<QVariant> aux{ "coolio",2.78,13.5,1 };
              	std::vector<QVariant> 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 < 200; i++)
              	{
              		insertStr += ",(?,?,?,?,?)";
              		binds.push_back(i);
              		binds.insert(binds.end(), aux.begin(), aux.end());
              	}
              	
              	query.prepare(insertStr);
              	for (auto& e : binds)
              		query.addBindValue(e);
              
              	if (!query.exec())
              	{
              		qDebug() << "cannot insert into database";
              		qDebug() << query.lastError().text();
              	}
              	else
              	{
              		qDebug() << "yes!";
              	}
              	database.close();
              
              	return a.exec();
              }
              
              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 24 Jul 2018, 04:37 last edited by
              #7

              @Stephocke

              Hi
              i think maybe its the
              SQLITE_LIMIT_VARIABLE_NUMBER (default value: 999).
              you are hitting ?
              https://www.sqlite.org/c3ref/bind_blob.html

              1 Reply Last reply
              2
              • V Offline
                V Offline
                VRonin
                wrote on 24 Jul 2018, 07:26 last edited by
                #8

                I think what you are looking for is https://doc.qt.io/qt-5/qsqlquery.html#execBatch

                The maximum number of batch rows is determined by your database MS SQL Server has 250 limit if I'm not mistaken

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                2
                • S Offline
                  S Offline
                  Stephocke
                  wrote on 25 Jul 2018, 15:45 last edited by
                  #9

                  I think you are right, it must be SQLITE_LIMIT_VARIABLE_NUMBER

                  I have found this function within the documentation and i want to try to increase the limit.

                  sqlite3_limit(sqlite3*, int id, int newVal);
                  

                  But I am completely overwhelmed. It is again typical C ++, instructions from experts for experts. I already noticed I cannot include <qsql_sqlite.h> - there is no such header file. So I thought mabye I have to set some includes within the project->properties->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?
                  What do I have to do?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 25 Jul 2018, 16:22 last edited by
                    #10

                    Hi
                    im no expert but i think you dont need to compile it again.
                    please see here
                    https://stackoverflow.com/questions/34415351/adding-a-custom-sqlite-function-to-a-qt-application
                    note the sqlite3_initialize
                    that should allow u to call sqlite3_limit

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Stephocke
                      wrote on 25 Jul 2018, 16:48 last edited by Stephocke
                      #11

                      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

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 25 Jul 2018, 16:50 last edited by
                        #12

                        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.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        1
                        • S Offline
                          S Offline
                          Stephocke
                          wrote on 25 Jul 2018, 17:01 last edited by Stephocke
                          #13

                          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>1000) compute the corresponding string, prepare the query again and fire the stmt successfully.

                          M 1 Reply Last reply 25 Jul 2018, 18:58
                          0
                          • S Stephocke
                            25 Jul 2018, 17:01

                            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>1000) compute the corresponding string, prepare the query again and fire the stmt successfully.

                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 25 Jul 2018, 18:58 last edited by
                            #14

                            @Stephocke
                            Well getting the header is not overly complicated.
                            If you used the online installer to install Qt, you just
                            open maintenance.exe in Qt folder
                            and select the source under the Qt u are using.
                            alt text

                            but if the workaround is acceptable, i guess its easier.

                            1 Reply Last reply
                            0

                            11/14

                            25 Jul 2018, 16:48

                            • Login

                            • Login or register to search.
                            11 out of 14
                            • First post
                              11/14
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved