Skip to content

Commit 3f8cce7

Browse files
committed
resolve feedback
1 parent cbcd03f commit 3f8cce7

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

src/node_sqlite.cc

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ using v8::Value;
6666

6767
inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate,
6868
std::string_view input) {
69-
int len = static_cast<int>(input.size());
69+
const int len = static_cast<int>(input.size());
7070
if (simdutf::validate_ascii(input.data(), input.size())) {
7171
return String::NewFromOneByte(
7272
isolate,
@@ -120,7 +120,7 @@ inline MaybeLocal<String> Utf8StringMaybeOneByte(Isolate* isolate,
120120
case SQLITE_TEXT: { \
121121
const char* v = \
122122
reinterpret_cast<const char*>(sqlite3_##from##_text(__VA_ARGS__)); \
123-
int v_len = sqlite3_##from##_bytes(__VA_ARGS__); \
123+
const int v_len = sqlite3_##from##_bytes(__VA_ARGS__); \
124124
(result) = \
125125
Utf8StringMaybeOneByte((isolate), std::string_view(v, v_len)) \
126126
.As<Value>(); \
@@ -2434,6 +2434,10 @@ StatementSync::~StatementSync() {
24342434
void StatementSync::Finalize() {
24352435
sqlite3_finalize(statement_);
24362436
statement_ = nullptr;
2437+
InvalidateColumnNameCache();
2438+
}
2439+
2440+
void StatementSync::InvalidateColumnNameCache() {
24372441
cached_column_names_.clear();
24382442
}
24392443

@@ -2623,17 +2627,16 @@ MaybeLocal<Name> StatementSync::ColumnNameToName(const int column) {
26232627
.As<Name>();
26242628
}
26252629

2626-
// Returns cached internalized column name strings for this statement,
2627-
// invalidating the cache when SQLite re-prepares the statement (e.g. after
2628-
// schema changes like ALTER TABLE) detected via SQLITE_STMTSTATUS_REPREPARE.
2630+
// Populates `keys` with cached column names, rebuilding the cache if the
2631+
// statement was re-prepared.
26292632
bool StatementSync::GetCachedColumnNames(LocalVector<Name>* keys) {
26302633
Isolate* isolate = env()->isolate();
26312634

2632-
int reprepare_count =
2633-
sqlite3_stmt_status(statement_, SQLITE_STMTSTATUS_REPREPARE, 0);
2635+
const int reprepare_count =
2636+
sqlite3_stmt_status(statement_, SQLITE_STMTSTATUS_REPREPARE, false);
26342637
if (reprepare_count != cached_column_names_reprepare_count_) {
26352638
cached_column_names_.clear();
2636-
int num_cols = sqlite3_column_count(statement_);
2639+
const int num_cols = sqlite3_column_count(statement_);
26372640
if (num_cols == 0) {
26382641
cached_column_names_reprepare_count_ = reprepare_count;
26392642
return true;
@@ -2642,7 +2645,7 @@ bool StatementSync::GetCachedColumnNames(LocalVector<Name>* keys) {
26422645
for (int i = 0; i < num_cols; ++i) {
26432646
Local<Name> key;
26442647
if (!ColumnNameToName(i).ToLocal(&key)) {
2645-
cached_column_names_.clear();
2648+
InvalidateColumnNameCache();
26462649
return false;
26472650
}
26482651
cached_column_names_.emplace_back(Global<Name>(isolate, key));

src/node_sqlite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class StatementSync : public BaseObject {
298298
inline int ResetStatement();
299299
std::vector<v8::Global<v8::Name>> cached_column_names_;
300300
int cached_column_names_reprepare_count_ = -1;
301+
void InvalidateColumnNameCache();
301302
bool BindParams(const v8::FunctionCallbackInfo<v8::Value>& args);
302303
bool BindValue(const v8::Local<v8::Value>& value, const int index);
303304

0 commit comments

Comments
 (0)