Skip to content

columns_with_metadata: access column metadata from prepared statement#1672

Merged
gwenn merged 7 commits intorusqlite:masterfrom
jgbyrne:column_metadata
Apr 17, 2025
Merged

columns_with_metadata: access column metadata from prepared statement#1672
gwenn merged 7 commits intorusqlite:masterfrom
jgbyrne:column_metadata

Conversation

@jgbyrne
Copy link
Contributor

@jgbyrne jgbyrne commented Apr 15, 2025

A simple binding for the column metadata functions:

sqlite3_column_database_name
sqlite3_column_table_name
sqlite3_column_origin_name

No docs or tests but I am happy to add them if you are interested in the PR.

Cheers,
Jack

@gwenn
Copy link
Collaborator

gwenn commented Apr 15, 2025

http://sqlite.org/c3ref/column_database_name.html

These APIs are only available if the library was compiled with the SQLITE_ENABLE_COLUMN_METADATA C-preprocessor symbol.

@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 15, 2025

Yeah this was the reason I gated the impl behind column_metadata just like is done for column_decltype

@gwenn
Copy link
Collaborator

gwenn commented Apr 15, 2025

Yeah this was the reason I gated the impl behind column_metadata just like is done for column_decltype

http://sqlite.org/c3ref/column_decltype.html
https://sqlite.org/compile.html#_options_to_omit_features

SQLITE_OMIT_DECLTYPE

This option causes SQLite to omit support for the sqlite3_column_decltype() and sqlite3_column_decltype16() interfaces.

=> sqlite3_column_decltype is supported by default...

@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 15, 2025

I'm pretty sure most (all?) major distros build with this flag on even if it's technically an optional extra.

@gwenn
Copy link
Collaborator

gwenn commented Apr 15, 2025

I'm pretty sure most (all?) major distros build with this flag on even if it's technically an optional extra.

https://github.com/gwenn/sqlite-jna/actions/runs/14461947474/job/40556051685

Error looking up function 'sqlite3_column_table_name': The specified procedure could not be found.

using https://github.com/gwenn/sqlite-jna/blob/e0d6e3a4249e4f71244649db29693381386ebfd3/.github/workflows/maven.yml#L19

vcpkg install sqlite3:x64-windows

@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 15, 2025

If you don't want to merge it that's fine :p

@gwenn
Copy link
Collaborator

gwenn commented Apr 15, 2025

If you don't want to merge it that's fine :p

if you don't want to make it mergeable that's funny :p

@gwenn gwenn added the invalid label Apr 15, 2025
@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 15, 2025

Sorry I'm not trying to be glib, I just don't see what you want me to do here. Dynamically check whether the methods are present in the sqlite binary?

@gwenn
Copy link
Collaborator

gwenn commented Apr 16, 2025

You need to activate the SQLITE_ENABLE_COLUMN_METADATA flag:
Like here:

unlock_notify = ["libsqlite3-sys/unlock_notify"]

unlock_notify = []

if cfg!(feature = "unlock_notify") {
cfg.flag("-DSQLITE_ENABLE_UNLOCK_NOTIFY");
}

@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 16, 2025

Ok I have given it a go, had a bit of trouble determining if it was working as expected though, perhaps you can review?

@gwenn gwenn removed the invalid label Apr 16, 2025
@codecov
Copy link

codecov bot commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 96.55172% with 3 lines in your changes missing coverage. Please review.

Project coverage is 86.86%. Comparing base (755bfa3) to head (3f492d9).
Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
src/column.rs 95.23% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1672      +/-   ##
==========================================
+ Coverage   86.79%   86.86%   +0.07%     
==========================================
  Files          58       58              
  Lines       11001    11088      +87     
==========================================
+ Hits         9548     9632      +84     
- Misses       1453     1456       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gwenn
Copy link
Collaborator

gwenn commented Apr 16, 2025

We might be able to have better coverage by using accessors instead of field.
And maybe by adding a dummy column like:

SELECT *, 1 FROM sqlite_schema;

(any expression should work)

@gwenn
Copy link
Collaborator

gwenn commented Apr 16, 2025

And, if possible, some minimal doc.

@gwenn
Copy link
Collaborator

gwenn commented Apr 17, 2025

Thanks.

@gwenn gwenn merged commit 0586571 into rusqlite:master Apr 17, 2025
16 checks passed
@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 17, 2025

Thank you for your help.

@gwenn
Copy link
Collaborator

gwenn commented Apr 17, 2025

Oops: ColumnMetadata is not public (outside the crate) !
(Sorry, I forgot to check that)

@jgbyrne
Copy link
Contributor Author

jgbyrne commented Apr 17, 2025

#1675 1675

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