Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions example/tests/unit/specs/operations/execute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, { type: ColumnType }> | 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 })
Expand Down Expand Up @@ -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', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native-nitro-sqlite/cpp/NitroSQLiteTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading