ДмитрийOct. 6, 2021, 6:07 a.m.
Вставка даты и времени в таблицу СУБД SQLite
qt, sql, sqlite, datetime, insert
Всем привет!
Использую базу данных SQLITE.
Пытаюсь в таблицу записать дату и время.
Делаю так:
QString q("CREATE TABLE IF NOT EXISTS dates (date1 DATETIME NOT NULL , date2 DATETIME NOT NULL)"); QSqlQuery query(db); if(!query.exec(q)) { qDebug() << "Unable to create table meter_configurations"; } QString qr("INSERT INTO dates (date1, date2 VALUES (?,?)"); QSqlQuery q1(db); q1.prepare(qr); QDateTime dt1 = QDateTime::currentDateTime(); QDateTime dt2 = QDateTime::currentDateTime(); q1.addBindValue(dt1); q1.addBindValue(dt2); if(!q1.exec()) { qDebug() << "Insert error!"; qDebug() << q1.lastError(); qDebug() << q1.lastQuery(); }
Но получаю ошибку: QSqlError("", "Parameter count mismatch", "")
Пробовал так:
QString qr("INSERT INTO dates (date1, date2 VALUES (datetime(?), datetime(?)"); QSqlQuery q1(db); q1.prepare(qr); QDateTime dt1 = QDateTime::currentDateTime(); QDateTime dt2 = QDateTime::currentDateTime(); q1.addBindValue(dt1.toString("yyyy-MM-dd hh:mm:ss")); q1.addBindValue(dt2.toString("yyyy-MM-dd hh:mm:ss"));
Но получаю ту же ошибку.
Как вставить дату и время? Спасибо!
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
- Дмитрий
- May 7, 2024, 9:40 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:60points,
- Rating points-1
d
- dsfs
- April 26, 2024, 4:56 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
Last comments
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
АК
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
Анатолий КононенкоFeb. 5, 2024, 1:50 a.m.
EVADec. 25, 2023, 10:30 a.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
добавить qlineseries в функции в функции: "GPlotter::addSeries(QString title, QVector &arr)" я вызываю метод setChart(...), я в конструктор передал адрес на QChartView элемент
BlinCTMay 5, 2024, 5:46 a.m.
Best Indian Food Restaurant In Cincinnati OH Ready to embark on a gastronomic journey like no other? Join us at App india restaurant and discover why we're renowned as the Best Indian Food Restaurant In Cincinnati OH . Whether y…
Evgenii LegotckoiMay 2, 2024, 2:07 p.m.
IscanderCheApril 30, 2024, 4:22 a.m.
а если заменить
на
Попробовал - тоже самое
Проблема решилась.
Во вставке забыл одну закрывающую скобку в запросе. Нужно так:
Правда у меня Postgresql