| 221 | } |
| 222 | |
| 223 | DB::Rows DB::queryUnsafe(SQLite::Database* db, String sql, const std::vector<Own<Value>>& args, bool withColumns) { |
| 224 | Rows result; |
| 225 | SQLite::Statement statement(*db, sql.toString()); |
| 226 | bindValues(statement, args); |
| 227 | bool columnCollected = false; |
| 228 | while (statement.executeStep()) { |
| 229 | int colCount = statement.getColumnCount(); |
| 230 | if (!columnCollected && withColumns) { |
| 231 | columnCollected = true; |
| 232 | auto& values = result.emplace_back(colCount); |
| 233 | for (int i = 0; i < colCount; i++) { |
| 234 | values[i] = std::string(statement.getColumn(i).getName()); |
| 235 | } |
| 236 | } |
| 237 | auto& values = result.emplace_back(colCount); |
| 238 | for (int i = 0; i < colCount; i++) { |
| 239 | auto col = statement.getColumn(i); |
| 240 | if (col.isInteger()) { |
| 241 | values[i] = col.getInt64(); |
| 242 | } else if (col.isFloat()) { |
| 243 | values[i] = col.getDouble(); |
| 244 | } else if (col.isText() || col.isBlob()) { |
| 245 | values[i] = std::string(col.getText()); |
| 246 | } else if (col.isNull()) { |
| 247 | values[i] = false; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | return result; |
| 252 | } |
| 253 | |
| 254 | void DB::insertUnsafe(SQLite::Database* db, String tableName, const std::deque<std::vector<Own<Value>>>& rows) { |
| 255 | if (rows.empty() || rows.front().empty()) return; |
no test coverage detected