diff --git a/cpp/bridge.cpp b/cpp/bridge.cpp index cfe7714e..dc6a55fe 100644 --- a/cpp/bridge.cpp +++ b/cpp/bridge.cpp @@ -400,8 +400,11 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query, int status, current_column, column_count, column_type; std::string column_name, column_declared_type; std::vector column_names; + column_names.reserve(20); std::vector> rows; + rows.reserve(20); std::vector row; + row.reserve(10); do { const char *query_str = @@ -436,7 +439,7 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query, // Do a first pass to get the column names for (int i = 0; i < column_count; i++) { column_name = sqlite3_column_name(statement, i); - column_names.push_back(column_name); + column_names.emplace_back(column_name); } while (is_consuming_rows) { @@ -464,9 +467,9 @@ BridgeResult opsqlite_execute(std::string const &name, std::string const &query, case SQLITE_TEXT: { string_value = reinterpret_cast( sqlite3_column_text(statement, current_column)); - int byteLen = sqlite3_column_bytes(statement, current_column); + int len = sqlite3_column_bytes(statement, current_column); // Specify length too; in case string contains NULL in the middle - row.emplace_back(std::string(string_value, byteLen)); + row.emplace_back(std::string(string_value, len)); break; } diff --git a/cpp/utils.cpp b/cpp/utils.cpp index 1644c072..504773d9 100644 --- a/cpp/utils.cpp +++ b/cpp/utils.cpp @@ -13,7 +13,7 @@ namespace opsqlite { namespace jsi = facebook::jsi; -jsi::Value toJSI(jsi::Runtime &rt, JSVariant value) { +jsi::Value toJSI(jsi::Runtime &rt, const JSVariant &value) { if (std::holds_alternative(value)) { return std::get(value); } else if (std::holds_alternative(value)) { @@ -158,7 +158,7 @@ std::vector to_variant_vec(jsi::Runtime &rt, jsi::Value const &xs) { return res; } -jsi::Value create_js_rows(jsi::Runtime &rt, BridgeResult status) { +jsi::Value create_js_rows(jsi::Runtime &rt, const BridgeResult &status) { if (status.type == SQLiteError) { throw std::invalid_argument(status.message); } @@ -181,10 +181,10 @@ jsi::Value create_js_rows(jsi::Runtime &rt, BridgeResult status) { auto value = toJSI(rt, native_row[j]); row.setValueAtIndex(rt, j, value); } - rows.setValueAtIndex(rt, i, std::move(row)); + rows.setValueAtIndex(rt, i, row); } } - res.setProperty(rt, "rawRows", std::move(rows)); + res.setProperty(rt, "rawRows", rows); size_t column_count = status.column_names.size(); auto column_array = jsi::Array(rt, column_count); diff --git a/cpp/utils.h b/cpp/utils.h index 6f6eb330..8dc58a0e 100644 --- a/cpp/utils.h +++ b/cpp/utils.h @@ -15,7 +15,7 @@ namespace opsqlite { namespace jsi = facebook::jsi; -jsi::Value toJSI(jsi::Runtime &rt, JSVariant value); +jsi::Value toJSI(jsi::Runtime &rt, const JSVariant &value); JSVariant toVariant(jsi::Runtime &rt, jsi::Value const &value); std::vector to_string_vec(jsi::Runtime &rt, jsi::Value const &xs); std::vector to_variant_vec(jsi::Runtime &rt, jsi::Value const &xs); @@ -23,7 +23,7 @@ std::vector to_int_vec(jsi::Runtime &rt, jsi::Value const &xs); jsi::Value createResult(jsi::Runtime &rt, BridgeResult status, std::vector *results, std::shared_ptr> metadata); -jsi::Value create_js_rows(jsi::Runtime &rt, BridgeResult status); +jsi::Value create_js_rows(jsi::Runtime &rt, const BridgeResult &status); jsi::Value create_raw_result(jsi::Runtime &rt, BridgeResult status, const std::vector> *results); diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index ef5b67d8..e5b4a9f9 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -10,7 +10,7 @@ PODS: - hermes-engine (0.74.0): - hermes-engine/Pre-built (= 0.74.0) - hermes-engine/Pre-built (0.74.0) - - op-sqlite (8.0.3): + - op-sqlite (9.0.0): - React - React-callinvoker - React-Core @@ -1393,7 +1393,7 @@ SPEC CHECKSUMS: GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4 glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2 hermes-engine: 6eae7edb2f563ee41d7c1f91f4f2e57c26d8a5c3 - op-sqlite: d567632567b87bedda1f718e4ce6c081457c2f42 + op-sqlite: 4a145846fefc46b14350344450809144775d2ec3 RCT-Folly: 045d6ecaa59d826c5736dfba0b2f4083ff8d79df RCTDeprecation: 3ca8b6c36bfb302e1895b72cfe7db0de0c92cd47 RCTRequired: 9fc183af555fd0c89a366c34c1ae70b7e03b1dc5 diff --git a/example/src/App.tsx b/example/src/App.tsx index 557eb16a..e679d3c8 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -17,8 +17,17 @@ import {reactiveTests} from './tests/reactive.spec'; import {setServerResults, startServer, stopServer} from './server'; import {open} from '@op-engineering/op-sqlite'; import Share from 'react-native-share'; +import {createLargeDB, queryLargeDB} from './Database'; export default function App() { + const [isLoading, setIsLoading] = useState(false); + const [times, setTimes] = useState([]); + const [accessingTimes, setAccessingTimes] = useState([]); + const [prepareTimes, setPrepareTimes] = useState([]); + const [prepareExecutionTimes, setPrepareExecutionTimes] = useState( + [], + ); + const [rawExecutionTimes, setRawExecutionTimes] = useState([]); const [results, setResults] = useState([]); useEffect(() => { runTests( @@ -78,6 +87,28 @@ export default function App() { } }; + const createLargeDb = async () => { + setIsLoading(true); + await createLargeDB(); + setIsLoading(false); + }; + + const queryLargeDb = async () => { + try { + setIsLoading(true); + const times = await queryLargeDB(); + setTimes(times.loadFromDb); + setAccessingTimes(times.access); + setPrepareTimes(times.prepare); + setPrepareExecutionTimes(times.preparedExecution); + setRawExecutionTimes(times.rawExecution); + } catch (e) { + console.error(e); + } finally { + setIsLoading(false); + } + }; + const copyDbPathToClipboad = async () => { const db = await open({name: 'shareableDb.sqlite'}); const path = db.getDbPath(); @@ -91,6 +122,57 @@ export default function App() {