#include #include #include #include #include #include #include "../utils/databasemanager.h" #include "../utils/logger.h" int main(int argc, char* argv[]) { QCoreApplication app(argc, argv); try { // 初始化数据库 DatabaseManager& dbManager = DatabaseManager::getInstance(); QSqlDatabase& db = dbManager.getDatabase(); qDebug() << "Database connected successfully!"; qDebug() << "Database file path:" << db.databaseName(); // 测试表是否创建成功 QSqlQuery query(db); // 检查表是否存在 if (query.exec("SELECT name FROM sqlite_master WHERE type='table' AND name='h_project'")) { if (query.next()) { qDebug() << "Table h_project exists!"; } else { qDebug() << "Table h_project does not exist!"; } } // 测试插入一条数据 query.prepare(R"( INSERT INTO h_project (uuid, name, company_code, blast_status, created_at) VALUES (:uuid, :name, :company_code, :blast_status, :created_at) )"); query.bindValue(":uuid", "test-uuid-123"); query.bindValue(":name", "Test Project"); query.bindValue(":company_code", "TEST001"); query.bindValue(":blast_status", "1"); query.bindValue(":created_at", QDateTime::currentDateTime().toString(Qt::ISODateWithMs)); if (query.exec()) { qDebug() << "Test data inserted successfully!"; } else { qDebug() << "Failed to insert test data:" << query.lastError().text(); } // 测试查询数据 if (query.exec("SELECT uuid, name, company_code FROM h_project WHERE uuid = 'test-uuid-123'")) { if (query.next()) { qDebug() << "Test data retrieved:"; qDebug() << " UUID:" << query.value("uuid").toString(); qDebug() << " Name:" << query.value("name").toString(); qDebug() << " Company Code:" << query.value("company_code").toString(); } } // 清理测试数据 query.exec("DELETE FROM h_project WHERE uuid = 'test-uuid-123'"); qDebug() << "Database migration test completed successfully!"; } catch (const std::exception& e) { qDebug() << "Database error:" << e.what(); return 1; } return 0; }