@op-engineering/op-sqlite 8.0.2 → 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.
Files changed (2) hide show
  1. package/cpp/bridge.cpp +25 -19
  2. package/package.json +1 -1
package/cpp/bridge.cpp CHANGED
@@ -393,24 +393,23 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
393
393
  sqlite3 *db = dbMap[name];
394
394
 
395
395
  sqlite3_stmt *statement;
396
- const char *errorMessage;
396
+ const char *errorMessage = nullptr;
397
397
  const char *remainingStatement = nullptr;
398
-
399
- bool isFailed = false;
400
- int step_result, current_column, column_count, column_type;
398
+ bool has_failed = false;
399
+ int status, current_column, column_count, column_type;
401
400
  std::string column_name, column_declared_type;
402
401
  std::vector<std::string> column_names;
403
402
  std::vector<std::vector<JSVariant>> rows;
404
403
  std::vector<JSVariant> row;
405
404
 
406
405
  do {
407
- const char *queryStr =
406
+ const char *query_str =
408
407
  remainingStatement == nullptr ? query.c_str() : remainingStatement;
409
408
 
410
- int statementStatus =
411
- sqlite3_prepare_v2(db, queryStr, -1, &statement, &remainingStatement);
409
+ status =
410
+ sqlite3_prepare_v2(db, query_str, -1, &statement, &remainingStatement);
412
411
 
413
- if (statementStatus != SQLITE_OK) {
412
+ if (status != SQLITE_OK) {
414
413
  errorMessage = sqlite3_errmsg(db);
415
414
  return {.type = SQLiteError,
416
415
  .message =
@@ -418,24 +417,31 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
418
417
  .affectedRows = 0};
419
418
  }
420
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
+
421
426
  if (params != nullptr && !params->empty()) {
422
427
  opsqlite_bind_statement(statement, params);
423
428
  }
424
429
 
425
430
  column_count = sqlite3_column_count(statement);
426
- bool is_consuming = true;
431
+ bool is_consuming_rows = true;
432
+ double double_value;
433
+ const char *string_value;
434
+
427
435
  // Do a first pass to get the column names
428
436
  for (int i = 0; i < column_count; i++) {
429
437
  column_name = sqlite3_column_name(statement, i);
430
438
  column_names.push_back(column_name);
431
439
  }
432
440
 
433
- double double_value;
434
- const char *string_value;
435
- while (is_consuming) {
436
- step_result = sqlite3_step(statement);
441
+ while (is_consuming_rows) {
442
+ status = sqlite3_step(statement);
437
443
 
438
- switch (step_result) {
444
+ switch (status) {
439
445
  case SQLITE_ROW:
440
446
  current_column = 0;
441
447
  row = std::vector<JSVariant>();
@@ -488,20 +494,20 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query,
488
494
  break;
489
495
 
490
496
  case SQLITE_DONE:
491
- is_consuming = false;
497
+ is_consuming_rows = false;
492
498
  break;
493
499
 
494
500
  default:
495
- isFailed = true;
496
- is_consuming = false;
501
+ has_failed = true;
502
+ is_consuming_rows = false;
497
503
  }
498
504
  }
499
505
 
500
506
  sqlite3_finalize(statement);
501
507
  } while (remainingStatement != nullptr &&
502
- strcmp(remainingStatement, "") != 0 && !isFailed);
508
+ strcmp(remainingStatement, "") != 0 && !has_failed);
503
509
 
504
- if (isFailed) {
510
+ if (has_failed) {
505
511
  const char *message = sqlite3_errmsg(db);
506
512
  return {.type = SQLiteError,
507
513
  .message =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@op-engineering/op-sqlite",
3
- "version": "8.0.2",
3
+ "version": "8.0.3",
4
4
  "description": "Next generation SQLite for React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",