Closed adamdecaf closed 6 years ago
Your use-case is very similar to mine, which is reading browser cookies. Wanting to avoid the heavyweight C-linked sqlite libraries is exactly why I started contributing to this project. For now, I just punted on column names completely, and trusted that I could rely on the number and order of column data, and the type information attached to it. Here's the code in question: https://github.com/zellyn/kooky/blob/master/chrome.go#L26
Your code (and the existing comma-splitting code to count columns) will sort-of work, at least for simple table definitions. However, for more complex definitions, it will break down: you can see that table-constraint
clauses are comma-separated here: https://www.sqlite.org/lang_createtable.html.
I was planning on writing a simple-as-possible parser that could handle the full sqlite create table
syntax, and using that to extract structured information about the table. But then, you know, my cookie-reading code started working perfectly, and … well ¯\_(ツ)_/¯
one could perhaps tap into a more robust SQL parser e.g.
Yeah, I thought of that. But cznic/ql doesn't seem to support the full range of create table syntax, vitess is mysql-alike, and cockroach's parser is postgres-based (originally).
Your code (and the existing comma-splitting code to count columns) will sort-of work, at least for simple table definitions.
@zellyn yea. I figured strings.Split
was too easy..
@sbinet Thanks. I'm gonna check those out (and the zellyn/kooky
link).
Well, splitting on commas is (a) better than nothing, and (b) completely consistent with the existing code. @sbinet may have opinions, but I say merge it on in :-)
Works for me!
I agree: getting something to start playing with is at least something :)
lgtm. @sbinet I don't think I have merge permission…
LGTM too.
@adamdecaf could you send another PR adding yourself to the list of AUTHORS
and CONTRIBUTORS
?
I'll accept it and then this one.
Sure thing! https://github.com/go-sqlite/sqlite3/pull/20
thanks and welcome to the pod :)
Cool project. I want to read browser (firefox, chrome, etc) history sqlite databases and don't want to import a cgo library for the simple read. (It'll also complicate my build process)
To get my feet wet I found out a way to read column names, but I'm unsure if this works well enough.
My use case doesn't need to be "fast" and I only need one column's data from one table in these files.
I'm willing to help read tables/column data more.