diff --git a/example/tests/unit/specs/operations/execute.spec.ts b/example/tests/unit/specs/operations/execute.spec.ts index 6476ec7a..795a3440 100644 --- a/example/tests/unit/specs/operations/execute.spec.ts +++ b/example/tests/unit/specs/operations/execute.spec.ts @@ -1,6 +1,29 @@ import { chance, expect, isNitroSQLiteError } from '@tests/unit/common' import { describe, it } from '@tests/TestApi' import { createArrayBufferTestDb, testDb } from '@tests/db' +import type { ColumnType } from 'react-native-nitro-sqlite' + +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) +} export default function registerExecuteUnitTests() { describe('execute', () => { @@ -137,6 +160,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/types.hpp b/packages/react-native-nitro-sqlite/cpp/types.hpp index eefa83a0..839d20ca 100644 --- a/packages/react-native-nitro-sqlite/cpp/types.hpp +++ b/packages/react-native-nitro-sqlite/cpp/types.hpp @@ -25,15 +25,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;