我正在测试一段简单的 C++ SQLite 代码:
sqlite3* db;
if (sqlite3_open("SteelTable.db", &db) != SQLITE_OK) {
sqlite3_close(db);
return 0;
}
std::string createQuery = "CREATE TABLE WFPROFILE ("
"ID INT PRIMARY KEY NOT NULL,"
"D REAL NOT NULL,"
"WT REAL NOT NULL,"
"WB REAL NOT NULL,"
"TF REAL NOT NULL,"
"TB REAL NOT NULL);";
sqlite3_stmt* createStmt;
sqlite3_prepare(db, createQuery.c_str(), static_cast<int>(createQuery.size()), &createStmt, nullptr);
if (sqlite3_step(createStmt) != SQLITE_DONE) {
sqlite3_close(db);
return 0;
}
std::vector<std::string> sqlStmList;
sqlStmList.emplace_back("INSERT INTO WFPROFILE ('ID','D','WT','WB','TF','TB') VALUES ('1','20','10','15','1','1.5');");
sqlStmList.emplace_back("INSERT INTO WFPROFILE ('ID','D','WT','WB','TF','TB') VALUES ('2','25','12','17','2.5','2');");
sqlStmList.emplace_back("INSERT INTO WFPROFILE ('ID','D','WT','WB','TF','TB') VALUES ('3','30','14','19.5','2.5','2.5');");
for (const auto& insertQuery : sqlStmList) {
sqlite3_stmt* insertStmt;
sqlite3_prepare(db, insertQuery.c_str(), static_cast<int>(insertQuery.size()), &insertStmt, nullptr);
if (sqlite3_step(insertStmt) != SQLITE_DONE) {
sqlite3_close(db);
return 0;
}
}
sqlite3_close(db);
这在控制台可执行文件中运行良好,但当相同的代码是 AutoCAD 的 ObjectARX C++ 的一部分时,会给出一个奇怪的运行时异常(在 CREATE TABLE 语句中)。
有没有人遇到过这个问题或者有没有人知道如何解决它。任何指针将不胜感激。谢谢