Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More APIs. #125

Merged
merged 1 commit into from
Jul 31, 2024
Merged

More APIs. #125

merged 1 commit into from
Jul 31, 2024

Conversation

ncruces
Copy link
Owner

@ncruces ncruces commented Jul 27, 2024

Will wrap these before the next release.

These should be easy:

  • sqlite3_db_cacheflush
  • sqlite3_db_status
  • sqlite3_value_frombind
  • sqlite3_table_column_metadata

sqlite3_trace_v2 raises interesting questions. It'd be a second "constructor" for *sqlite3.Stmt, which raises the question of pointer identity. If we want two *sqlite3.Stmt to be equal, we need to dedup them, which means storing a list of them in *sqlite3.Conn (which incidentally SQLite also does). We'd also probably need identity, to make it easier to trace the start/row/end moments of a *sqlite3.Stmt run.

If we do this, we can also iterate over statements in a connection (replacing sqlite3_next_stmt), and sqlite3_sql and sqlite3_expanded_sql can also start to make sense.


These are also done:

  • sqlite3_sql
  • sqlite3_expanded_sql
  • sqlite3_next_stmt
  • sqlite3_trace_v2

@ncruces
Copy link
Owner Author

ncruces commented Jul 28, 2024

See #126.

@ncruces ncruces force-pushed the more branch 3 times, most recently from 536fbc6 to 5c1e1a7 Compare July 30, 2024 11:06
@ncruces
Copy link
Owner Author

ncruces commented Jul 30, 2024

sqlite3_trace_v2 is half done, and looking good enough for closure notification: it's called just before the connection being closed (which allows running PRAGMA optimize on closure, etc).

Need to work on deduping the *sqlite.Stmt pointers.

PS: There's an additional challenge. Statements we Exec also get a "native" prepared statement, but those are "finalized" immediately after the Exec ends. Deduping those (and the SQL string) to make them traceable, and avoid a bunch of memory churn is complicated; not sure it's feasible.

@ncruces ncruces force-pushed the more branch 2 times, most recently from 81c1fa1 to 7365ee3 Compare July 30, 2024 14:02
@daenney
Copy link
Contributor

daenney commented Jul 30, 2024

sqlite3_trace_v2 is half done, and looking good enough for closure notification: it's called just before the connection being closed (which allows running PRAGMA optimize on closure, etc).

Taking a bit of creative license with how trace is used works for me 😄. The only thing I'm wondering is if people will take exception to it because trace sounds like something that has the potential for performance impact.

@ncruces
Copy link
Owner Author

ncruces commented Jul 30, 2024

This is pretty much wrapped up now.

Documenting decisions.

I decided that only statements explicitly prepared from Go will be traced. This is unlike SQLite, but it is the only way to make pointer identity/equality work, as long as Go does not have weak references. Traces about statements that weren't prepared from Go are simply ignored (this means Execed statements, but also statements executed by native virtual tables, like FTS5).

So far, I haven't exposed sqlite3_next_stmt (I'd rather expose a Go 1.23 sequence of statements), nor sqlite3_sql (I'd probably rather keep the Go string around than rematerialize it every time), nor sqlite3_expanded_sql. Right now, TRACE_STMT allocs a copy of the SQL string every time.

Until Go has some form of interning (for strings, and objects) or weak references, which both seem unlikely (package unique is no replacement) this is unlikely to change. The only alternative I see is to make sqlite3.Stmt a value, not a pointer, but that's bad too (because Close clears the handle).

@ncruces ncruces force-pushed the more branch 2 times, most recently from 2efc75e to 3e12f37 Compare July 31, 2024 08:53
@ncruces ncruces marked this pull request as ready for review July 31, 2024 08:53
@ncruces ncruces merged commit 3bb1898 into main Jul 31, 2024
11 checks passed
@ncruces ncruces deleted the more branch July 31, 2024 11:52
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.

2 participants