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

How does SQLite accommodate various data types? #1275

Open
imranimtiaz opened this issue Sep 12, 2024 · 1 comment
Open

How does SQLite accommodate various data types? #1275

imranimtiaz opened this issue Sep 12, 2024 · 1 comment

Comments

@imranimtiaz
Copy link

It seems that with the current state of the go-sqlite3 driver, there's no built-in way to retrieve the data type of each result row dynamically. This becomes an issue when the actual data in a column doesn't match the data type defined by the table schema. For instance, if a column is declared as an integer but contains a string in some rows, attempting to retrieve that row can cause errors.

The problem seems to be related to the use of the sqlite3_column_decltype() function in the DeclTypes() method, which only returns the type declared at the schema level, rather than the actual data type of each individual row.

I've found that gwenn's SQLite driver for Go, while not as widely used anymore (since they’ve shifted focus to Rust), does offer a feature that lets you retrieve the actual type for each row of a result set. You can check it out in the code linked here: gosqlite stmt.go L550-L555.

Given go-sqlite3’s broader usage, I think it would be worth considering adding a similar feature to dynamically retrieve row-level data types in your driver. It would be particularly useful for scenarios where user-generated SQLite databases are involved, such as this one: DB4S download stats.

I also opened an issue a while back with more context on this in gwenn's repository (issue gwenn/gosqlite#5), in case that’s helpful.

What are your thoughts on adding this functionality? 😄

@rittneje
Copy link
Collaborator

I'm not entirely sure what you are intending to do, but have you tried just scanning into values of type any?

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

No branches or pull requests

2 participants