-
Notifications
You must be signed in to change notification settings - Fork 333
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 get the field type for a null field? #494
Comments
I'm not sure this makes sense. NULL values in SQLite don't have a type besides NULL. SQLite's type system can be a bit strange, so you might want to read over https://www.sqlite.org/datatype3.html. |
Yeah, I know. But the field have: CREATE TABLE config (
config_id INTEGER PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
value TEXT
); Now If I do: SELECT * FROM config; I need to know that BTW: And the rest of the info too, like if is PK, Unique, etc... |
Currently, there is no helper to access metadata: |
In |
Yes, that is what is expected. |
Return Columns name and type. (rusqlite#494)
Fixed by 0.18 release. |
Is it currently possible to get more metadata, such as which columns are nullable? |
If you want such information, you have to use:
sqlite> SELECT "notnull" FROM <db_name>.pragma_table_info('<tbl_name>') WHERE name like '<col_name>'; Currently, there is no such feature in |
So is it just impossible right now (without directly using the ffi)? I've been trying to use queries but it looks like they basically only return rows. I can't figure out how to run something like |
Thanks for the help, I basically got it working: fn get_nullable_stats(self: Self) -> Result<Vec<i64>, Error> {
let conn = self.connect()?;
let mut table_info =
conn.prepare(r#"SELECT "notnull" FROM books.pragma_table_info("books")"#)?;
let mut columns = Vec::new();
let mut rows = table_info.query(NO_PARAMS)?;
dbg!(rows.columns());
while let Some(row) = rows.next()? {
let row = row;
let column: i64 = row.get(0)?;
columns.push(column);
}
Ok(columns)
} |
@billop You can also return booleans: fn get_nullable_stats(self: Self) -> Result<Vec<bool>, Error> {
...
let column: bool = row.get(0)?; |
Related to https://github.com/jgallagher/rusqlite/issues/372.
I can query a
Value
for the type, but if the field allow null, and the data return null, the original type is lost.I can get the column names, but not the types.
The text was updated successfully, but these errors were encountered: