mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
empty commit to trigger formatting ci (#20378)
Co-authored-by: nektro <5464072+nektro@users.noreply.github.com>
This commit is contained in:
@@ -2380,17 +2380,17 @@ JSC_DEFINE_CUSTOM_GETTER(jsSqlStatementGetColumnTypes, (JSGlobalObject * lexical
|
||||
// but only do this for read-only statements to avoid side effects
|
||||
bool isReadOnly = sqlite3_stmt_readonly(castedThis->stmt) != 0;
|
||||
|
||||
if (! isReadOnly) {
|
||||
if (!isReadOnly) {
|
||||
// For non-read-only statements, throw an error since column types don't make sense
|
||||
throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "columnTypes is not available for non-read-only statements (INSERT, UPDATE, DELETE, etc.)"_s));
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
// Reset the statement (safe for read-only statements)
|
||||
int resetStatus = sqlite3_reset(castedThis->stmt);
|
||||
if (resetStatus != SQLITE_OK) {
|
||||
throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db));
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
MarkedArgumentBuffer args;
|
||||
@@ -2439,7 +2439,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsSqlStatementGetColumnTypes, (JSGlobalObject * lexical
|
||||
// If there was an error stepping, throw it
|
||||
throwException(lexicalGlobalObject, scope, createSQLiteError(lexicalGlobalObject, castedThis->version_db->db));
|
||||
sqlite3_reset(castedThis->stmt);
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
// Reset the statement back to its original state
|
||||
@@ -2462,7 +2462,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsSqlStatementGetColumnDeclaredTypes, (JSGlobalObject *
|
||||
// Ensure the statement has been executed at least once
|
||||
if (!castedThis->hasExecuted) {
|
||||
throwException(lexicalGlobalObject, scope, createError(lexicalGlobalObject, "Statement must be executed before accessing declaredTypes"_s));
|
||||
return { };
|
||||
return {};
|
||||
}
|
||||
|
||||
int count = sqlite3_column_count(castedThis->stmt);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from "bun:test";
|
||||
import { Database } from "bun:sqlite";
|
||||
import { describe, expect, it } from "bun:test";
|
||||
|
||||
describe("SQLite Statement column types", () => {
|
||||
it("reports correct column types for a variety of data types", () => {
|
||||
@@ -37,13 +37,13 @@ describe("SQLite Statement column types", () => {
|
||||
expect(stmt.columnTypes).toBeDefined();
|
||||
expect(Array.isArray(stmt.columnTypes)).toBe(true);
|
||||
expect(stmt.columnTypes.length).toBe(5);
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'TEXT', 'FLOAT', 'BLOB', 'INTEGER']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "TEXT", "FLOAT", "BLOB", "INTEGER"]);
|
||||
|
||||
// Test the declaredTypes property (uses declared types from sqlite3_column_decltype)
|
||||
expect(stmt.declaredTypes).toBeDefined();
|
||||
expect(Array.isArray(stmt.declaredTypes)).toBe(true);
|
||||
expect(stmt.declaredTypes.length).toBe(5);
|
||||
expect(stmt.declaredTypes).toEqual(['INTEGER', 'TEXT', 'REAL', 'BLOB', 'INTEGER']);
|
||||
expect(stmt.declaredTypes).toEqual(["INTEGER", "TEXT", "REAL", "BLOB", "INTEGER"]);
|
||||
});
|
||||
|
||||
it("handles NULL values correctly", () => {
|
||||
@@ -64,10 +64,10 @@ describe("SQLite Statement column types", () => {
|
||||
const row = stmt.get();
|
||||
|
||||
// columnTypes now returns actual data types - NULL values are reported as 'NULL'
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'NULL']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "NULL"]);
|
||||
|
||||
// declaredTypes still shows the declared table schema
|
||||
expect(stmt.declaredTypes).toEqual(['INTEGER', 'TEXT']);
|
||||
expect(stmt.declaredTypes).toEqual(["INTEGER", "TEXT"]);
|
||||
});
|
||||
|
||||
it("reports actual column types based on data values", () => {
|
||||
@@ -89,7 +89,7 @@ describe("SQLite Statement column types", () => {
|
||||
let row = stmt.get();
|
||||
|
||||
// We should get the actual type of the value (integer)
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'INTEGER']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "INTEGER"]);
|
||||
|
||||
// Update to a text value
|
||||
db.run(`UPDATE dynamic_types SET value = 'text' WHERE id = 1`);
|
||||
@@ -99,7 +99,7 @@ describe("SQLite Statement column types", () => {
|
||||
row = stmt.get();
|
||||
|
||||
// We should get the actual type of the value (text)
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'TEXT']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "TEXT"]);
|
||||
|
||||
// Update to a float value
|
||||
db.run(`UPDATE dynamic_types SET value = 3.14 WHERE id = 1`);
|
||||
@@ -109,7 +109,7 @@ describe("SQLite Statement column types", () => {
|
||||
row = stmt.get();
|
||||
|
||||
// We should get the actual type of the value (float)
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'FLOAT']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "FLOAT"]);
|
||||
});
|
||||
|
||||
it("reports actual types for columns from expressions", () => {
|
||||
@@ -124,14 +124,14 @@ describe("SQLite Statement column types", () => {
|
||||
expect(row).toEqual({
|
||||
str_length: 3,
|
||||
magic_number: 42,
|
||||
greeting: "hello"
|
||||
greeting: "hello",
|
||||
});
|
||||
|
||||
// Check columns are correctly identified
|
||||
expect(stmt.native.columns).toEqual(['str_length', 'magic_number', 'greeting']);
|
||||
expect(stmt.native.columns).toEqual(["str_length", "magic_number", "greeting"]);
|
||||
|
||||
// For expressions, expect the actual data types
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'INTEGER', 'TEXT']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "INTEGER", "TEXT"]);
|
||||
});
|
||||
|
||||
it("handles multiple different expressions and functions", () => {
|
||||
@@ -153,28 +153,26 @@ describe("SQLite Statement column types", () => {
|
||||
|
||||
// Verify we have the expected columns
|
||||
expect(stmt.native.columns).toEqual([
|
||||
'int_val',
|
||||
'float_val',
|
||||
'text_val',
|
||||
'blob_val',
|
||||
'null_val',
|
||||
'func_result',
|
||||
'timestamp'
|
||||
"int_val",
|
||||
"float_val",
|
||||
"text_val",
|
||||
"blob_val",
|
||||
"null_val",
|
||||
"func_result",
|
||||
"timestamp",
|
||||
]);
|
||||
|
||||
// Expression columns should be reported with their actual types
|
||||
expect(stmt.columnTypes).toEqual([
|
||||
'INTEGER', 'FLOAT', 'TEXT', 'BLOB', 'NULL', 'INTEGER', 'TEXT'
|
||||
]);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "FLOAT", "TEXT", "BLOB", "NULL", "INTEGER", "TEXT"]);
|
||||
|
||||
// Verify data types were correctly identified at runtime
|
||||
expect(typeof row.int_val).toBe('number');
|
||||
expect(typeof row.float_val).toBe('number');
|
||||
expect(typeof row.text_val).toBe('string');
|
||||
expect(typeof row.int_val).toBe("number");
|
||||
expect(typeof row.float_val).toBe("number");
|
||||
expect(typeof row.text_val).toBe("string");
|
||||
expect(row.blob_val instanceof Uint8Array).toBe(true);
|
||||
expect(row.null_val).toBe(null);
|
||||
expect(typeof row.func_result).toBe('number');
|
||||
expect(typeof row.timestamp).toBe('string');
|
||||
expect(typeof row.func_result).toBe("number");
|
||||
expect(typeof row.timestamp).toBe("string");
|
||||
});
|
||||
|
||||
it("shows difference between columnTypes and declaredTypes for expressions", () => {
|
||||
@@ -185,7 +183,7 @@ describe("SQLite Statement column types", () => {
|
||||
const row = stmt.get();
|
||||
|
||||
// columnTypes shows actual data types based on the values
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'INTEGER', 'TEXT']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "INTEGER", "TEXT"]);
|
||||
|
||||
// declaredTypes shows declared types (which are null for expressions without explicit declarations)
|
||||
expect(stmt.declaredTypes).toEqual([null, null, null]);
|
||||
@@ -208,10 +206,10 @@ describe("SQLite Statement column types", () => {
|
||||
let row = stmt.get();
|
||||
|
||||
// columnTypes shows actual type (integer) for the current value
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'INTEGER']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "INTEGER"]);
|
||||
|
||||
// declaredTypes shows the declared table schema
|
||||
expect(stmt.declaredTypes).toEqual(['INTEGER', 'ANY']);
|
||||
expect(stmt.declaredTypes).toEqual(["INTEGER", "ANY"]);
|
||||
|
||||
// Update to a text value
|
||||
db.run(`UPDATE dynamic_types SET value = 'text' WHERE id = 1`);
|
||||
@@ -220,10 +218,10 @@ describe("SQLite Statement column types", () => {
|
||||
row = stmt.get();
|
||||
|
||||
// columnTypes now shows text for the current value
|
||||
expect(stmt.columnTypes).toEqual(['INTEGER', 'TEXT']);
|
||||
expect(stmt.columnTypes).toEqual(["INTEGER", "TEXT"]);
|
||||
|
||||
// declaredTypes still shows the declared table schema
|
||||
expect(stmt.declaredTypes).toEqual(['INTEGER', 'ANY']);
|
||||
expect(stmt.declaredTypes).toEqual(["INTEGER", "ANY"]);
|
||||
});
|
||||
|
||||
it("throws an error when accessing columnTypes before statement execution", () => {
|
||||
|
||||
Reference in New Issue
Block a user