margelo / margelo/react-native-nitro-sqlite

Incorrect column metadata types because strcmp comparisons are inverted

Open
#305 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
565
Forks
53
Avg merge
1d 21h
Merged PRs (30d)
18

Description

Summary

QueryResult.metadata[*].type is incorrect for every non-null declared SQLite type because mapSQLiteTypeToColumnType() treats a non-zero strcmp() result as a match.

Verified on main at ad8b835 (v9.7.0).

Code evidence

types.hpp#L25-L40 currently contains conditions such as:

} else if (strcmp(type, "BOOLEAN")) {
  return ColumnType::BOOLEAN;
}

strcmp() returns 0 when strings are equal. Consequently:

  • INTEGER, TEXT, BLOB, FLOAT, and any other non-BOOLEAN declaration take the first branch and report BOOLEAN.
  • BOOLEAN skips the first branch, then differs from FLOAT, so it reports NUMBER.
  • The later intended mappings are effectively unreachable.

The result is exposed through the metadata construction in operations.cpp#L247-L258.

Smallest reproducer

const db = open({ name: 'metadata.sqlite' })

db.execute(`
  CREATE TABLE values_table (
    boolean_value BOOLEAN,
    float_value FLOAT,
    integer_value INTEGER,
    text_value TEXT,
    blob_value BLOB
  )
`)

const result = db.execute('SELECT * FROM values_table')
console.log(result.metadata)

Expected declared types:

BOOLEAN, NUMBER, INT64, TEXT, ARRAY_BUFFER

Observed from the current mapping logic:

NUMBER, BOOLEAN, BOOLEAN, BOOLEAN, BOOLEAN

This is distinct from #194, which reports missing metadata entries. This issue concerns the declared type values assigned to entries that are present.

Impact

Consumers cannot rely on query metadata for schema introspection, adapters, serializers, or ORMs. In particular, integer, text, and blob columns can be interpreted as booleans.

Acceptance criteria

  • Compare declared types for equality (strcmp(...) == 0) or use a less error-prone mapping.
  • Add focused coverage for BOOLEAN, FLOAT, INTEGER, TEXT, BLOB, and a null declaration (sqlite3_column_decltype() == nullptr).
  • Define and test behavior for common SQLite affinity declarations such as REAL, DOUBLE, VARCHAR(...), and INT, or document that only the current exact declarations are supported.
  • Verify both execute() and executeAsync() expose the corrected metadata.

Regression-test target

A native or Harness test that creates one column per supported declared type and asserts result.metadata[column].type for both sync and async execution.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cpp/types.hpp at mapSQLiteTypeToColumnType(), then inspect metadata construction in cpp/operations.cpp. Add focused native or Harness coverage for BOOLEAN, FLOAT, INTEGER, TEXT, BLOB, null declarations, and common SQLite affinity declarations through both execute() and executeAsync(). Done means metadata types match the supported behavior in both paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, react-native, sqlite
Domain
database, mobile, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.