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

Add some example code? #5

Open
justinclift opened this issue Nov 23, 2016 · 8 comments
Open

Add some example code? #5

justinclift opened this issue Nov 23, 2016 · 8 comments

Comments

@justinclift
Copy link
Collaborator

justinclift commented Nov 23, 2016

Going to try out the SQLite3 driver in this repo, as mattn's one doesn't seem to cope with SQLite's dynamic type system.

But... no example code for beginners to look at. ☹️

The reference info on godoc.org seems useful, but targeted to a more experienced audience.

Any chance of adding example code to this repo? Hopefully something that shows off the things useful here which aren't present in the commonly used driver (mattn's). 😄

@gwenn
Copy link
Owner

gwenn commented Nov 24, 2016

Hello,
I suggest you use the mattn's driver because it is widely used, SQLite C library is bundled and mattn is working on this.
I apologise for the lack of documentation.
And in case you don't already know, it is also the database/sql/driver API that doesn't cope with SQLite's dynamic type system (for example, here).

@justinclift
Copy link
Collaborator Author

justinclift commented Nov 24, 2016

Ahhh, I wasn't able to get things working with mattn's driver, but I did manage to make it work with yours.

@justinclift
Copy link
Collaborator Author

You've moved focus from Go to Rust?

@gwenn
Copy link
Owner

gwenn commented Nov 25, 2016

Ok, I see that you are using the low-level API (not the standard database/sql API). And do the same for Postgresql with pgx!
You are trying to retrieve some data from a table without knowing its content, no ?
Have you tried using the standard Scan method instead ?

If an argument has type *interface{}, Scan copies the value provided by the underlying driver without conversion.

And yes, for me, Rust is more rewarding than Go.

@justinclift
Copy link
Collaborator Author

justinclift commented Nov 26, 2016

Yeah, in this particular application (similar to a web based database viewer) the database(s) are user supplied. Example screenshot to give the idea:

DBHub.io Database page

When I first tried the standard Scan method - using mattn's driver through database/sql - I just kept getting conversion errors, even using *interface{}.

There didn't seem to be a way to determine the correct concrete type to use for the cells in a result set. Looking at the mattn's driver docs on godoc.org, there's a DeclTypes() function which seems like it should serve that purpose, which I didn't try last time.

@justinclift
Copy link
Collaborator Author

justinclift commented Nov 26, 2016

Looking at DeclTypes() in mattn's driver, it uses "sqlite3_column_decltype", which doesn't seem fit for this purpose. The docs for that say it only returns the column type defined in the table schema.

With ColumnType() in your driver, that uses sqlite3_column_type which seems to do things correctly. At least, it's working here with database containing mixed data types in columns. (eg binary data in fields declared as text)

I guess for now I'll need to keep using your driver, and/or look at switching if something turns out to break further on which I can't fix. 😄

If I'm getting this wrong somehow, I'm definitely open to doing things differently. Still very early in my Golang learning.

@gwenn
Copy link
Owner

gwenn commented Nov 26, 2016

I suggest that:

  • you use database/sql,
    I think you can already/temporary do it with my driver.
    You may need to deactivate the ScanNumericalAsTime flag with a custom Register.
  • you ask mattn to make possible to disable the DeclTypes() usage in Next.
    It seems feasible with a DynamicType flag at the connection level and a custom Register.

I once tried to describe the problem related to SQLite dynamic type and propose a solution here.

@justinclift
Copy link
Collaborator Author

@gwenn Thanks. Yeah, getting this fixed in mattn's driver is on our list. Just not right now though. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants