diff --git a/example/tests/unit/specs/operations/execute.spec.ts b/example/tests/unit/specs/operations/execute.spec.ts index a303921d..0f2fb445 100644 --- a/example/tests/unit/specs/operations/execute.spec.ts +++ b/example/tests/unit/specs/operations/execute.spec.ts @@ -3,9 +3,31 @@ import { describe, it } from '@tests/TestApi' import { createArrayBufferTestDb, testDb } from '@tests/db' import { open } from 'react-native-nitro-sqlite' import { buildJSQueryResult } from '@nitro-sqlite/operations/execute' +import type { ColumnType } from 'react-native-nitro-sqlite' import type { NitroSQLiteQueryResult } from '@nitro-sqlite/specs/NitroSQLiteQueryResult.nitro' const QUERY_RESULT_SIZES = [60, 1_000, 10_000] +const metadataQuery = ` + SELECT + boolean_value, + float_value, + integer_value, + text_value, + blob_value, + NULL AS null_value + FROM ColumnMetadata +` + +function expectColumnMetadata( + metadata: Record | undefined, +) { + expect(metadata?.boolean_value?.type).toBe(0) + expect(metadata?.float_value?.type).toBe(1) + expect(metadata?.integer_value?.type).toBe(2) + expect(metadata?.text_value?.type).toBe(3) + expect(metadata?.blob_value?.type).toBe(4) + expect(metadata?.null_value?.type).toBe(5) +} function createQueryResultTestDb(name: string) { const db = open({ name }) @@ -261,6 +283,28 @@ export default function registerExecuteUnitTests() { }) }) + describe('metadata', () => { + it('maps declared column types for execute', () => { + testDb.execute('DROP TABLE IF EXISTS ColumnMetadata') + testDb.execute( + 'CREATE TABLE ColumnMetadata (boolean_value BOOLEAN, float_value FLOAT, integer_value INTEGER, text_value TEXT, blob_value BLOB)', + ) + + expectColumnMetadata(testDb.execute(metadataQuery).metadata) + }) + + it('maps declared column types for executeAsync', async () => { + await testDb.executeAsync('DROP TABLE IF EXISTS ColumnMetadata') + await testDb.executeAsync( + 'CREATE TABLE ColumnMetadata (boolean_value BOOLEAN, float_value FLOAT, integer_value INTEGER, text_value TEXT, blob_value BLOB)', + ) + + expectColumnMetadata( + (await testDb.executeAsync(metadataQuery)).metadata, + ) + }) + }) + describe('ArrayBuffer support', () => { describe('execute', () => { it('stores and reads ArrayBuffer values from BLOB columns', () => { diff --git a/packages/react-native-nitro-sqlite/cpp/NitroSQLiteTypes.hpp b/packages/react-native-nitro-sqlite/cpp/NitroSQLiteTypes.hpp index 4fbb9237..b885d1bc 100644 --- a/packages/react-native-nitro-sqlite/cpp/NitroSQLiteTypes.hpp +++ b/packages/react-native-nitro-sqlite/cpp/NitroSQLiteTypes.hpp @@ -23,15 +23,15 @@ struct SQLiteOperationResult { inline ColumnType mapSQLiteTypeToColumnType(const char* type) { if (type == NULL) { return ColumnType::NULL_VALUE; - } else if (strcmp(type, "BOOLEAN")) { + } else if (strcmp(type, "BOOLEAN") == 0) { return ColumnType::BOOLEAN; - } else if (strcmp(type, "FLOAT")) { + } else if (strcmp(type, "FLOAT") == 0) { return ColumnType::NUMBER; - } else if (strcmp(type, "INTEGER")) { + } else if (strcmp(type, "INTEGER") == 0) { return ColumnType::INT64; - } else if (strcmp(type, "TEXT")) { + } else if (strcmp(type, "TEXT") == 0) { return ColumnType::TEXT; - } else if (strcmp(type, "BLOB")) { + } else if (strcmp(type, "BLOB") == 0) { return ColumnType::ARRAY_BUFFER; } else { return ColumnType::NULL_VALUE;