Skip to content

feat(db.sqlite): add Row.names, get_string/get_int, and improve exec_map#26702

Merged
JalonSolov merged 1 commit intovlang:masterfrom
quaesitor-scientiam:enhance/sqlite-row-named-access
Mar 8, 2026
Merged

feat(db.sqlite): add Row.names, get_string/get_int, and improve exec_map#26702
JalonSolov merged 1 commit intovlang:masterfrom
quaesitor-scientiam:enhance/sqlite-row-named-access

Conversation

@quaesitor-scientiam
Copy link
Contributor

Summary

  • Add names []string to Row — populated by exec and exec_param_many after sqlite3_prepare_v2, shared across all rows in a result set
  • Add get_string(col_name string) string and get_int(col_name string) int accessor methods on Row
  • Improve exec_map to capture column names once before the row loop instead of on every row iteration

Motivation

Row previously only exposed vals []string, requiring callers to hardcode column positions from the originating SELECT. Any reordering of columns would silently break lookups. exec_map provided name-based access but at the cost of a map allocation per row and redundant sqlite3_column_name calls on every row.

Design

Column names are available from sqlite3_column_name immediately after sqlite3_prepare_v2 — before any sqlite3_step call. Names are captured into a single []string slice and the same slice is assigned to every Row in the result set. V slices share the backing array, so there is no per-row name allocation overhead.

get_string and get_int perform a linear scan of r.names, which is acceptable for typical SQL result sets (small number of columns). Both return zero values gracefully when names is empty (manually constructed Row instances).

Impact on existing callers

  • Zero breaking changes. Row{vals: [...]} and Row{} constructions are unaffected; names defaults to []string{} and all existing row.vals[i] access is unchanged.
  • exec_map callers see no API change — same return type and values, fewer sqlite3_column_name calls.

Test plan

  • All existing vlib/db/sqlite/ tests pass (6 passed, 1 skipped — skip is pre-existing and unrelated)

Closes #26701

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e7e8863f7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@quaesitor-scientiam quaesitor-scientiam force-pushed the enhance/sqlite-row-named-access branch 3 times, most recently from 4acc2bd to e0663f2 Compare March 7, 2026 14:53
@JalonSolov
Copy link
Collaborator

A conflict to resolve... possibly from your other PR?

Add `names []string` to `Row` so callers can access column values by
name rather than by hardcoded index. Column names are captured once
after sqlite3_prepare_v2 (before stepping) and the same slice is
assigned to every row, avoiding per-row allocation overhead.

`names` is placed after `vals` to preserve positional struct literal
compatibility — `Row{['a', 'b']}` continues to populate `vals`.

Add `get_string(col_name string) string` and `get_int(col_name string)
int` accessor methods on `Row`. Both return zero values gracefully when
the column name is not found, preserving compatibility with manually
constructed Row instances that have no names.

Improve exec_map to capture column names once before the row loop
instead of calling sqlite3_column_name on every column of every row.
For a result set of N rows and C columns this reduces sqlite3_column_name
calls from N*C to C.

Closes vlang#26701

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@quaesitor-scientiam quaesitor-scientiam force-pushed the enhance/sqlite-row-named-access branch from e0663f2 to d97ba9e Compare March 8, 2026 03:15
@JalonSolov JalonSolov merged commit 602a493 into vlang:master Mar 8, 2026
78 checks passed
@quaesitor-scientiam quaesitor-scientiam deleted the enhance/sqlite-row-named-access branch March 10, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

db.sqlite: add Row.names and get_string/get_int for column-name-based access

3 participants