mirror of
https://github.com/denoland/deno.git
synced 2025-08-31 07:47:46 +00:00
fix(ext/sqlite): add sourceSQL
and expandedSQL
getters (#27921)
This commit is contained in:
parent
441b1d307f
commit
c2832d70a1
3 changed files with 40 additions and 0 deletions
|
@ -42,6 +42,9 @@ pub enum SqliteError {
|
|||
#[class(generic)]
|
||||
#[error("Invalid constructor")]
|
||||
InvalidConstructor,
|
||||
#[class(generic)]
|
||||
#[error("Expanded SQL text would exceed configured limits")]
|
||||
InvalidExpandedSql,
|
||||
#[class(range)]
|
||||
#[error("The value of column {0} is too large to be represented as a JavaScript number: {1}")]
|
||||
NumberTooLarge(i32, i64),
|
||||
|
|
|
@ -373,4 +373,38 @@ impl StatementSync {
|
|||
fn set_read_big_ints(&self, enabled: bool) {
|
||||
self.use_big_ints.set(enabled);
|
||||
}
|
||||
|
||||
#[getter]
|
||||
#[rename("sourceSQL")]
|
||||
#[string]
|
||||
fn source_sql(&self) -> String {
|
||||
// SAFETY: `self.inner` is a valid pointer to a sqlite3_stmt
|
||||
// as it lives as long as the StatementSync instance.
|
||||
unsafe {
|
||||
let raw = ffi::sqlite3_sql(self.inner);
|
||||
std::ffi::CStr::from_ptr(raw as _)
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
}
|
||||
}
|
||||
|
||||
#[getter]
|
||||
#[rename("expandedSQL")]
|
||||
#[string]
|
||||
fn expanded_sql(&self) -> Result<String, SqliteError> {
|
||||
// SAFETY: `self.inner` is a valid pointer to a sqlite3_stmt
|
||||
// as it lives as long as the StatementSync instance.
|
||||
unsafe {
|
||||
let raw = ffi::sqlite3_expanded_sql(self.inner);
|
||||
if raw.is_null() {
|
||||
return Err(SqliteError::InvalidExpandedSql);
|
||||
}
|
||||
let sql = std::ffi::CStr::from_ptr(raw as _)
|
||||
.to_string_lossy()
|
||||
.into_owned();
|
||||
ffi::sqlite3_free(raw as _);
|
||||
|
||||
Ok(sql)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,6 +72,9 @@ Deno.test("[node/sqlite] StatementSync read bigints are supported", () => {
|
|||
|
||||
stmt.setReadBigInts(true);
|
||||
assertEquals(stmt.get(), { key: 1n, __proto__: null });
|
||||
|
||||
assertEquals(stmt.sourceSQL, "SELECT * FROM data");
|
||||
assertEquals(stmt.expandedSQL, "SELECT * FROM data");
|
||||
});
|
||||
|
||||
Deno.test("[node/sqlite] StatementSync integer too large", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue