@@ -52,18 +52,23 @@ using v8::Value;
52
52
} \
53
53
} while (0 )
54
54
55
- inline Local<Value> CreateSQLiteError (Isolate* isolate, sqlite3* db) {
56
- int errcode = sqlite3_extended_errcode (db);
57
- const char * errstr = sqlite3_errstr (errcode);
58
- const char * errmsg = sqlite3_errmsg (db);
59
- Local<String> js_msg = String::NewFromUtf8 (isolate, errmsg).ToLocalChecked ();
55
+ inline Local<Object> CreateSQLiteError (Isolate* isolate, const char * message) {
56
+ Local<String> js_msg = String::NewFromUtf8 (isolate, message).ToLocalChecked ();
60
57
Local<Object> e = Exception::Error (js_msg)
61
58
->ToObject (isolate->GetCurrentContext ())
62
59
.ToLocalChecked ();
63
60
e->Set (isolate->GetCurrentContext (),
64
61
OneByteString (isolate, " code" ),
65
62
OneByteString (isolate, " ERR_SQLITE_ERROR" ))
66
63
.Check ();
64
+ return e;
65
+ }
66
+
67
+ inline Local<Object> CreateSQLiteError (Isolate* isolate, sqlite3* db) {
68
+ int errcode = sqlite3_extended_errcode (db);
69
+ const char * errstr = sqlite3_errstr (errcode);
70
+ const char * errmsg = sqlite3_errmsg (db);
71
+ Local<Object> e = CreateSQLiteError (isolate, errmsg);
67
72
e->Set (isolate->GetCurrentContext (),
68
73
OneByteString (isolate, " errcode" ),
69
74
Integer::New (isolate, errcode))
@@ -79,6 +84,10 @@ inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, sqlite3* db) {
79
84
isolate->ThrowException (CreateSQLiteError (isolate, db));
80
85
}
81
86
87
+ inline void THROW_ERR_SQLITE_ERROR (Isolate* isolate, const char * message) {
88
+ isolate->ThrowException (CreateSQLiteError (isolate, message));
89
+ }
90
+
82
91
DatabaseSync::DatabaseSync (Environment* env,
83
92
Local<Object> object,
84
93
Local<String> location,
@@ -623,7 +632,13 @@ void StatementSync::ExpandedSQL(const FunctionCallbackInfo<Value>& args) {
623
632
Environment* env = Environment::GetCurrent (args);
624
633
THROW_AND_RETURN_ON_BAD_STATE (
625
634
env, stmt->IsFinalized (), " statement has been finalized" );
635
+
636
+ // sqlite3_expanded_sql may return nullptr without producing an error code.
626
637
char * expanded = sqlite3_expanded_sql (stmt->statement_ );
638
+ if (expanded == nullptr ) {
639
+ return THROW_ERR_SQLITE_ERROR (
640
+ env->isolate (), " Expanded SQL text would exceed configured limits" );
641
+ }
627
642
auto maybe_expanded = String::NewFromUtf8 (env->isolate (), expanded);
628
643
sqlite3_free (expanded);
629
644
Local<String> result;
0 commit comments