| 84 | } |
| 85 | |
| 86 | arrow::Result<std::shared_ptr<SqliteStatement>> SqliteStatement::Create( |
| 87 | sqlite3* db, const std::string& sql) { |
| 88 | sqlite3_stmt* stmt = nullptr; |
| 89 | int rc = |
| 90 | sqlite3_prepare_v2(db, sql.c_str(), static_cast<int>(sql.size()), &stmt, NULLPTR); |
| 91 | |
| 92 | if (rc != SQLITE_OK) { |
| 93 | std::string err_msg = "Can't prepare statement: " + std::string(sqlite3_errmsg(db)); |
| 94 | if (stmt != nullptr) { |
| 95 | rc = sqlite3_finalize(stmt); |
| 96 | if (rc != SQLITE_OK) { |
| 97 | err_msg += "; Failed to finalize SQLite statement: "; |
| 98 | err_msg += std::string(sqlite3_errmsg(db)); |
| 99 | } |
| 100 | } |
| 101 | return Status::Invalid(err_msg); |
| 102 | } |
| 103 | |
| 104 | std::shared_ptr<SqliteStatement> result(new SqliteStatement(db, stmt)); |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | arrow::Result<std::shared_ptr<Schema>> SqliteStatement::GetSchema() const { |
| 109 | std::vector<std::shared_ptr<Field>> fields; |