| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2989311 commit 6302168
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -696,6 +696,9 @@ console.log(query.get()); | |||
| 696 | 696 | <!-- YAML | |
| 697 | 697 | added: v22.5.0 | |
| 698 | 698 | changes: | |
| 699 | + - version: REPLACEME | ||
| 700 | + pr-url: https://github.com/nodejs/node/pull/62757 | ||
| 701 | + description: Add the `persistent` option. | ||
| 699 | 702 | - version: REPLACEME | |
| 700 | 703 | pr-url: https://github.com/nodejs/node/pull/65157 | |
| 701 | 704 | description: Throw `ERR_INVALID_ARG_VALUE` if `sql` contains no statements. | |
@@ -712,10 +715,14 @@ changes: | |||
| 712 | 715 | database options or `true`. | |
| 713 | 716 | * `allowUnknownNamedParameters` {boolean} If `true`, unknown named parameters | |
| 714 | 717 | are ignored. **Default:** inherited from database options or `false`. | |
| 718 | + * `persistent` {boolean} If `true`, hints to SQLite that this statement will | ||
| 719 | + be retained for a long time and likely reused many times. SQLite currently | ||
| 720 | + responds to this hint by avoiding lookaside memory. Corresponds to the | ||
| 721 | + [`SQLITE_PREPARE_PERSISTENT`][] flag. **Default:** `false`. | ||
| 715 | 722 | * Returns: {StatementSync} The prepared statement. | |
| 716 | 723 | ||
| 717 | 724 | Compiles a SQL statement into a [prepared statement][]. This method is a wrapper | |
| 718 | - around [`sqlite3_prepare_v2()`][]. | ||
| 725 | + around [`sqlite3_prepare_v3()`][]. | ||
| 719 | 726 | ||
| 720 | 727 | ### `database.createTagStore([maxSize])` | |
| 721 | 728 | ||
@@ -1882,6 +1889,7 @@ callback function to indicate what type of operation is being authorized. | |||
| 1882 | 1889 | [`SQLITE_DETERMINISTIC`]: https://www.sqlite.org/c3ref/c_deterministic.html | |
| 1883 | 1890 | [`SQLITE_DIRECTONLY`]: https://www.sqlite.org/c3ref/c_deterministic.html | |
| 1884 | 1891 | [`SQLITE_MAX_FUNCTION_ARG`]: https://www.sqlite.org/limits.html#max_function_arg | |
| 1892 | + [`SQLITE_PREPARE_PERSISTENT`]: https://sqlite.org/c3ref/c_prepare_dont_log.html#sqlitepreparepersistent | ||
| 1885 | 1893 | [`SQLTagStore`]: #class-sqltagstore | |
| 1886 | 1894 | [`database.applyChangeset()`]: #databaseapplychangesetchangeset-options | |
| 1887 | 1895 | [`database.createTagStore()`]: #databasecreatetagstoremaxsize | |
@@ -1907,7 +1915,7 @@ callback function to indicate what type of operation is being authorized. | |||
| 1907 | 1915 | [`sqlite3_get_autocommit()`]: https://sqlite.org/c3ref/get_autocommit.html | |
| 1908 | 1916 | [`sqlite3_last_insert_rowid()`]: https://www.sqlite.org/c3ref/last_insert_rowid.html | |
| 1909 | 1917 | [`sqlite3_load_extension()`]: https://www.sqlite.org/c3ref/load_extension.html | |
| 1910 | - [`sqlite3_prepare_v2()`]: https://www.sqlite.org/c3ref/prepare.html | ||
| 1918 | + [`sqlite3_prepare_v3()`]: https://www.sqlite.org/c3ref/prepare.html | ||
| 1911 | 1919 | [`sqlite3_serialize()`]: https://sqlite.org/c3ref/serialize.html | |
| 1912 | 1920 | [`sqlite3_set_authorizer()`]: https://sqlite.org/c3ref/set_authorizer.html | |
| 1913 | 1921 | [`sqlite3_sql()`]: https://www.sqlite.org/c3ref/expanded_sql.html | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1539,6 +1539,7 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) { | |||
| 1539 | 1539 | std::optional<bool> use_big_ints; | |
| 1540 | 1540 | std::optional<bool> allow_bare_named_params; | |
| 1541 | 1541 | std::optional<bool> allow_unknown_named_params; | |
| 1542 | + std::optional<bool> persistent; | ||
| 1542 | 1543 | ||
| 1543 | 1544 | if (args.Length() > 1 && !args[1]->IsUndefined()) { | |
| 1544 | 1545 | if (!args[1]->IsObject()) { | |
@@ -1619,11 +1620,34 @@ void DatabaseSync::Prepare(const FunctionCallbackInfo<Value>& args) { | |||
| 1619 | 1620 | } | |
| 1620 | 1621 | allow_unknown_named_params = allow_unknown_named_params_v->IsTrue(); | |
| 1621 | 1622 | } | |
| 1623 | + | ||
| 1624 | + Local<Value> persistent_v; | ||
| 1625 | + if (!options | ||
| 1626 | + ->Get(env->context(), | ||
| 1627 | + FIXED_ONE_BYTE_STRING(env->isolate(), "persistent")) | ||
| 1628 | + .ToLocal(&persistent_v)) { | ||
| 1629 | + return; | ||
| 1630 | + } | ||
| 1631 | + if (!persistent_v->IsUndefined()) { | ||
| 1632 | + if (!persistent_v->IsBoolean()) { | ||
| 1633 | + THROW_ERR_INVALID_ARG_TYPE( | ||
| 1634 | + env->isolate(), | ||
| 1635 | + "The \"options.persistent\" argument must be a boolean."); | ||
| 1636 | + return; | ||
| 1637 | + } | ||
| 1638 | + persistent = persistent_v->IsTrue(); | ||
| 1639 | + } | ||
| 1622 | 1640 | } | |
| 1623 | 1641 | ||
| 1624 | 1642 | Utf8Value sql(env->isolate(), args[0].As<String>()); | |
| 1625 | 1643 | sqlite3_stmt* s = nullptr; | |
| 1626 | - int r = sqlite3_prepare_v2(db->connection_, *sql, -1, &s, nullptr); | ||
| 1644 | + | ||
| 1645 | + unsigned int prep_flags = | ||
| 1646 | + persistent.value_or(false) ? SQLITE_PREPARE_PERSISTENT : 0; | ||
| 1647 | + | ||
| 1648 | + int r = | ||
| 1649 | + sqlite3_prepare_v3(db->connection_, *sql, -1, prep_flags, &s, nullptr); | ||
| 1650 | + | ||
| 1627 | 1651 | StatementPtr stmt_ptr(s); | |
| 1628 | 1652 | ||
| 1629 | 1653 | CHECK_ERROR_OR_THROW(env->isolate(), db, r, SQLITE_OK, void()); | |
@@ -3845,8 +3869,12 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement( | |||
| 3845 | 3869 | ||
| 3846 | 3870 | if (stmt == nullptr) { | |
| 3847 | 3871 | sqlite3_stmt* s = nullptr; | |
| 3848 | - int r = sqlite3_prepare_v2( | ||
| 3849 | - session->database_->connection_, sql.data(), sql.size(), &s, nullptr); | ||
| 3872 | + int r = sqlite3_prepare_v3(session->database_->connection_, | ||
| 3873 | + sql.data(), | ||
| 3874 | + sql.size(), | ||
| 3875 | + SQLITE_PREPARE_PERSISTENT, | ||
| 3876 | + &s, | ||
| 3877 | + nullptr); | ||
| 3850 | 3878 | StatementPtr stmt_ptr(s); | |
| 3851 | 3879 | ||
| 3852 | 3880 | if (r != SQLITE_OK) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments