11#include " operations.hpp"
2+ #include " NitroSQLiteException.hpp"
23#include " logs.hpp"
34#include " utils.hpp"
45#include < NitroModules/ArrayBuffer.hpp>
56#include < cmath>
67#include < ctime>
78#include < iostream>
8- #include < optional>
99#include < map>
10+ #include < optional>
1011#include < sqlite3.h>
1112#include < sstream>
1213#include < unistd.h>
13- #include " NitroSQLiteException.hpp"
1414
1515using namespace facebook ;
1616using namespace margelo ::nitro;
@@ -59,7 +59,7 @@ void sqliteCloseAll() {
5959}
6060
6161void sqliteAttachDb (const std::string& mainDBName, const std::string& docPath, const std::string& databaseToAttach,
62- const std::string& alias) {
62+ const std::string& alias) {
6363 /* *
6464 * There is no need to check if mainDBName is opened because sqliteExecuteLiteral will do that.
6565 * */
@@ -69,7 +69,8 @@ void sqliteAttachDb(const std::string& mainDBName, const std::string& docPath, c
6969 try {
7070 sqliteExecuteLiteral (mainDBName, statement);
7171 } catch (NitroSQLiteException& e) {
72- throw NitroSQLiteException (NitroSQLiteExceptionType::UnableToAttachToDatabase, mainDBName + " was unable to attach another database: " + std::string (e.what ()));
72+ throw NitroSQLiteException (NitroSQLiteExceptionType::UnableToAttachToDatabase,
73+ mainDBName + " was unable to attach another database: " + std::string (e.what ()));
7374 }
7475}
7576
@@ -82,7 +83,8 @@ void sqliteDetachDb(const std::string& mainDBName, const std::string& alias) {
8283 try {
8384 sqliteExecuteLiteral (mainDBName, statement);
8485 } catch (NitroSQLiteException& e) {
85- throw NitroSQLiteException (NitroSQLiteExceptionType::UnableToAttachToDatabase, mainDBName + " was unable to detach database: " + std::string (e.what ()));
86+ throw NitroSQLiteException (NitroSQLiteExceptionType::UnableToAttachToDatabase,
87+ mainDBName + " was unable to detach database: " + std::string (e.what ()));
8688 }
8789}
8890
@@ -101,7 +103,7 @@ void sqliteRemoveDb(const std::string& dbName, const std::string& docPath) {
101103
102104void bindStatement (sqlite3_stmt* statement, const SQLiteQueryParams& values) {
103105 for (int valueIndex = 0 ; valueIndex < values.size (); valueIndex++) {
104- int sqliteIndex = valueIndex+ 1 ;
106+ int sqliteIndex = valueIndex + 1 ;
105107 SQLiteValue value = values.at (valueIndex);
106108 if (std::holds_alternative<SQLiteNullValue>(value)) {
107109 sqlite3_bind_null (statement, sqliteIndex);
@@ -119,7 +121,8 @@ void bindStatement(sqlite3_stmt* statement, const SQLiteQueryParams& values) {
119121 }
120122}
121123
122- SQLiteExecuteQueryResult sqliteExecute (const std::string& dbName, const std::string& query, const std::optional<SQLiteQueryParams>& params) {
124+ SQLiteExecuteQueryResult sqliteExecute (const std::string& dbName, const std::string& query,
125+ const std::optional<SQLiteQueryParams>& params) {
123126 if (dbMap.count (dbName) == 0 ) {
124127 throw NitroSQLiteException::DatabaseNotOpen (dbName);
125128 }
@@ -196,21 +199,21 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
196199 results.push_back (std::move (row));
197200 break ;
198201 case SQLITE_DONE:
199- i = 0 ;
200- count = sqlite3_column_count (statement);
201- while (i < count) {
202- column_name = sqlite3_column_name (statement, i);
203- const char * tp = sqlite3_column_decltype (statement, i);
204- column_declared_type = mapSQLiteTypeToColumnType (tp);
205- auto columnMeta = SQLiteQueryColumnMetadata (std::move (column_name), std::move (column_declared_type), i);
206-
207- if (!metadata) {
208- metadata = std::make_optional<SQLiteQueryTableMetadata>();
209- }
210- metadata->insert ({column_name, columnMeta});
211- i++;
202+ i = 0 ;
203+ count = sqlite3_column_count (statement);
204+ while (i < count) {
205+ column_name = sqlite3_column_name (statement, i);
206+ const char * tp = sqlite3_column_decltype (statement, i);
207+ column_declared_type = mapSQLiteTypeToColumnType (tp);
208+ auto columnMeta = SQLiteQueryColumnMetadata (std::move (column_name), std::move (column_declared_type), i);
209+
210+ if (!metadata) {
211+ metadata = std::make_optional<SQLiteQueryTableMetadata>();
212212 }
213- isConsuming = false ;
213+ metadata->insert ({column_name, columnMeta});
214+ i++;
215+ }
216+ isConsuming = false ;
214217 break ;
215218 default :
216219 isFailed = true ;
@@ -226,12 +229,10 @@ SQLiteExecuteQueryResult sqliteExecute(const std::string& dbName, const std::str
226229
227230 int rowsAffected = sqlite3_changes (db);
228231 long long latestInsertRowId = sqlite3_last_insert_rowid (db);
229- return {
230- .rowsAffected = rowsAffected,
231- .insertId = static_cast <double >(latestInsertRowId),
232- .results = std::move (results),
233- .metadata = std::move (metadata)
234- };
232+ return {.rowsAffected = rowsAffected,
233+ .insertId = static_cast <double >(latestInsertRowId),
234+ .results = std::move (results),
235+ .metadata = std::move (metadata)};
235236}
236237
237238SQLiteOperationResult sqliteExecuteLiteral (const std::string& dbName, const std::string& query) {
0 commit comments