@op-engineering/op-sqlite 8.0.1 → 8.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cpp/bridge.cpp +29 -21
- package/package.json +1 -1
package/cpp/bridge.cpp
CHANGED
|
@@ -204,8 +204,10 @@ inline void opsqlite_bind_statement(sqlite3_stmt *statement,
|
|
|
204
204
|
int sqIndex = ii + 1;
|
|
205
205
|
JSVariant value = values->at(ii);
|
|
206
206
|
|
|
207
|
-
if (std::holds_alternative<bool>(value)
|
|
208
|
-
|
|
207
|
+
if (std::holds_alternative<bool>(value)) {
|
|
208
|
+
sqlite3_bind_int(statement, sqIndex,
|
|
209
|
+
static_cast<int>(std::get<bool>(value)));
|
|
210
|
+
} else if (std::holds_alternative<int>(value)) {
|
|
209
211
|
sqlite3_bind_int(statement, sqIndex, std::get<int>(value));
|
|
210
212
|
} else if (std::holds_alternative<long long>(value)) {
|
|
211
213
|
sqlite3_bind_double(statement, sqIndex,
|
|
@@ -391,24 +393,23 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
|
|
|
391
393
|
sqlite3 *db = dbMap[name];
|
|
392
394
|
|
|
393
395
|
sqlite3_stmt *statement;
|
|
394
|
-
const char *errorMessage;
|
|
396
|
+
const char *errorMessage = nullptr;
|
|
395
397
|
const char *remainingStatement = nullptr;
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
int step_result, current_column, column_count, column_type;
|
|
398
|
+
bool has_failed = false;
|
|
399
|
+
int status, current_column, column_count, column_type;
|
|
399
400
|
std::string column_name, column_declared_type;
|
|
400
401
|
std::vector<std::string> column_names;
|
|
401
402
|
std::vector<std::vector<JSVariant>> rows;
|
|
402
403
|
std::vector<JSVariant> row;
|
|
403
404
|
|
|
404
405
|
do {
|
|
405
|
-
const char *
|
|
406
|
+
const char *query_str =
|
|
406
407
|
remainingStatement == nullptr ? query.c_str() : remainingStatement;
|
|
407
408
|
|
|
408
|
-
|
|
409
|
-
sqlite3_prepare_v2(db,
|
|
409
|
+
status =
|
|
410
|
+
sqlite3_prepare_v2(db, query_str, -1, &statement, &remainingStatement);
|
|
410
411
|
|
|
411
|
-
if (
|
|
412
|
+
if (status != SQLITE_OK) {
|
|
412
413
|
errorMessage = sqlite3_errmsg(db);
|
|
413
414
|
return {.type = SQLiteError,
|
|
414
415
|
.message =
|
|
@@ -416,24 +417,31 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
|
|
|
416
417
|
.affectedRows = 0};
|
|
417
418
|
}
|
|
418
419
|
|
|
420
|
+
// The statement did not fail to parse but there is nothing to do, just
|
|
421
|
+
// skip to the end
|
|
422
|
+
if (statement == nullptr) {
|
|
423
|
+
continue;
|
|
424
|
+
}
|
|
425
|
+
|
|
419
426
|
if (params != nullptr && !params->empty()) {
|
|
420
427
|
opsqlite_bind_statement(statement, params);
|
|
421
428
|
}
|
|
422
429
|
|
|
423
430
|
column_count = sqlite3_column_count(statement);
|
|
424
|
-
bool
|
|
431
|
+
bool is_consuming_rows = true;
|
|
432
|
+
double double_value;
|
|
433
|
+
const char *string_value;
|
|
434
|
+
|
|
425
435
|
// Do a first pass to get the column names
|
|
426
436
|
for (int i = 0; i < column_count; i++) {
|
|
427
437
|
column_name = sqlite3_column_name(statement, i);
|
|
428
438
|
column_names.push_back(column_name);
|
|
429
439
|
}
|
|
430
440
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
while (is_consuming) {
|
|
434
|
-
step_result = sqlite3_step(statement);
|
|
441
|
+
while (is_consuming_rows) {
|
|
442
|
+
status = sqlite3_step(statement);
|
|
435
443
|
|
|
436
|
-
switch (
|
|
444
|
+
switch (status) {
|
|
437
445
|
case SQLITE_ROW:
|
|
438
446
|
current_column = 0;
|
|
439
447
|
row = std::vector<JSVariant>();
|
|
@@ -486,20 +494,20 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
|
|
|
486
494
|
break;
|
|
487
495
|
|
|
488
496
|
case SQLITE_DONE:
|
|
489
|
-
|
|
497
|
+
is_consuming_rows = false;
|
|
490
498
|
break;
|
|
491
499
|
|
|
492
500
|
default:
|
|
493
|
-
|
|
494
|
-
|
|
501
|
+
has_failed = true;
|
|
502
|
+
is_consuming_rows = false;
|
|
495
503
|
}
|
|
496
504
|
}
|
|
497
505
|
|
|
498
506
|
sqlite3_finalize(statement);
|
|
499
507
|
} while (remainingStatement != nullptr &&
|
|
500
|
-
strcmp(remainingStatement, "") != 0 && !
|
|
508
|
+
strcmp(remainingStatement, "") != 0 && !has_failed);
|
|
501
509
|
|
|
502
|
-
if (
|
|
510
|
+
if (has_failed) {
|
|
503
511
|
const char *message = sqlite3_errmsg(db);
|
|
504
512
|
return {.type = SQLiteError,
|
|
505
513
|
.message =
|