#include #include static const QVector s_dates = { QDate(2021, 8, 17), QDate(1970, 1, 1) }; void createTable() { QSqlQuery q; q.exec("drop table TESTTABLE"); if (q.exec("create table TESTTABLE (EventDate DATE)")) qDebug() << "Successfully created table."; else qDebug() << "Failed to create table."; } void insertRecords() { QSqlDatabase::database().exec("truncate table TESTTABLE"); for (QDate d : s_dates) { QSqlQuery q; q.prepare("insert into TESTTABLE values (?)"); q.bindValue(0, d); if (q.exec()) qDebug() << "Successfully inserted record for" << d; else qDebug() << "Failed to insert record for" << d; } } void findRecords() { for (QDate d : s_dates) { QSqlQuery q; q.prepare("select count(*) from TESTTABLE where EventDate = ?"); q.bindValue(0, d); if (!q.exec() || !q.next()) qDebug() << "Select failed"; else if (q.value(0).toInt() == 0) qDebug() << "Failed to find record for" << d; else qDebug() << "Successfully found record for" << d; } } int main(int argc, char** argv) { QCoreApplication app(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QOCI"); db.setHostName(""); // change to oracle 10g host db.setPort(1521); db.setDatabaseName(""); // SID db.setUserName(""); db.setPassword(""); if (!db.open()) { qDebug() << "Failed to open database" << db.lastError().text(); return 0; } createTable(); insertRecords(); findRecords(); return 0; }