Last active
October 22, 2024 15:36
-
-
Save keithel/21d2a27e4f25d2fc652d5b68412bd4f6 to your computer and use it in GitHub Desktop.
QSqlQuery execBatch with single index column parameter count mismatch failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.16) | |
project(index_col_db VERSION 0.1 LANGUAGES CXX) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | |
find_package(Qt6 6.5 REQUIRED COMPONENTS Core Sql) | |
qt_standard_project_setup(REQUIRES 6.5) | |
qt_add_executable(appindex_col_db | |
src/main.cpp | |
) | |
include_directories(src) | |
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. | |
# If you are developing for iOS or macOS you should consider setting an | |
# explicit, fixed bundle identifier manually though. | |
set_target_properties(appindex_col_db PROPERTIES | |
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appindex_col_db | |
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} | |
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} | |
MACOSX_BUNDLE TRUE | |
WIN32_EXECUTABLE TRUE | |
) | |
target_link_libraries(appindex_col_db | |
PRIVATE | |
Qt6::Core | |
Qt6::Sql | |
) | |
include(GNUInstallDirs) | |
install(TARGETS appindex_col_db | |
BUNDLE DESTINATION . | |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | |
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************** | |
** Copyright (c) 2024 The Qt Company | |
** | |
** This file is provided as-is, with no warranties as to use | |
** or fitness for any purpose. | |
** | |
** This file is provided as part of a proof of concept example | |
** distributed by representatives of The Qt Company and may be | |
** used for demonstration purposes only. Any other use must be | |
** explicitly granted in writing by an authorized Qt Company | |
** employee or representative. | |
** | |
**************************************************************/ | |
#include <QCoreApplication> | |
#include <QDebug> | |
#include <QTimer> | |
#include <QSqlDatabase> | |
#include <QSqlError> | |
#include <QSqlQuery> | |
bool createSimpleDb() | |
{ | |
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "indexcoldb"); | |
db.setDatabaseName("/tmp/indexcoldb.sqlite"); | |
if (!db.open()) { | |
qWarning() << "Unable to open database. An error occurred while opening the connection:" << db.lastError().text(); | |
return false; | |
} | |
db.transaction(); | |
QSqlQuery q(db); | |
q.exec("drop table MyTable"); | |
q.exec("CREATE TABLE MyTable (index INTEGER PRIMARY KEY)"); | |
q.prepare("INSERT INTO MyTable VALUES (?)"); | |
for (auto i = 1; i <= 10; i++) { | |
QVariantList l; | |
l.append(i); | |
q.addBindValue(l); | |
} | |
if(!q.execBatch()) | |
qWarning() << "execBatch to /tmp/indexcoldb.sqlite db failed:" << q.lastError().text(); | |
if (!db.commit()) | |
qWarning() << "Commit to indexcoldb.qslite failed"; | |
db.close(); | |
return true; | |
} | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication app(argc, argv); | |
createSimpleDb(); | |
QTimer::singleShot(0, &app, [&app](){ | |
app.quit(); | |
}); | |
return app.exec(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10:07:31: Starting /home/kyzik/Build/timross-stockapp/option-trade-display-poc/build/Desktop_Qt_6_7_2-Release/appoption_trade_display_poc... | |
execBatch to /tmp/optiontrade.sqlite db failed: "Parameter count mismatch" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment