go-sqlite / sqlite3

pure-Go sqlite3 file reader
BSD 3-Clause "New" or "Revised" License
140 stars 19 forks source link

don't let UNIQUE and PRIMARY KEY be seen as column names, skip internal sqlite tables #18

Closed adamdecaf closed 6 years ago

adamdecaf commented 6 years ago

These are useful as they're slightly more complex (and real-world) sqlite dbs.

Here's the tables and data contained. Both are from a fresh install of the browser.

Chrome ``` $ sqlite3 browser/chrome/testdata/History SQLite version 3.19.3 2017-06-27 16:48:08 Enter ".help" for usage hints. sqlite> .tables downloads meta urls downloads_slices segment_usage visit_source downloads_url_chains segments visits keyword_search_terms typed_url_sync_metadata sqlite> select count(*) from downloads; 0 sqlite> select count(*) from downloads_slices; 0 sqlite> select count(*) from downloads_url_chains; 0 sqlite> select count(*) from keyword_search_terms; 0 sqlite> select count(*) from meta; 3 sqlite> select * from meta; mmap_status|-1 version|36 last_compatible_version|16 sqlite> select * from segment_usage; 1|1|13156408800000000|1 sqlite> select * from segments; 1|http://google.com/|1 sqlite> select * from typed_url_sync_metadata; sqlite> select * from urls; 1|http://google.com/|Google|1|1|13156455493534189|0 2|http://www.google.com/|Google|1|0|13156455493534189|0 3|https://www.google.com/|Google|1|0|13156455493534189|0 sqlite> select * from visit_source; sqlite> select * from visits; 1|1|13156455493534189|0|268435457|1|0 2|2|13156455493534189|1|2147483649|0|0 3|3|13156455493534189|2|2684354561|0|1039690 ```
Firefox ``` $ sqlite3 browser/firefox/testdata/places.sqlite SQLite version 3.19.3 2017-06-27 16:48:08 Enter ".help" for usage hints. sqlite> .tables moz_anno_attributes moz_historyvisits moz_keywords moz_annos moz_hosts moz_places moz_bookmarks moz_inputhistory moz_bookmarks_deleted moz_items_annos sqlite> select * from moz_anno_attributes; 1|mobile/bookmarksRoot 2|bookmarkProperties/description 3|Places/SmartBookmark sqlite> select * from moz_annos; sqlite> select * from moz_bookmarks; 1|2||0|0||||1511549555759000|1511549555976000|root________|1|1 2|2||1|0|Bookmarks Menu|||1511549555759000|1511549555976000|menu________|1|5 3|2||1|1|Bookmarks Toolbar|||1511549555759000|1511549555923000|toolbar_____|1|5 4|2||1|2|Tags|||1511549555759000|1511549555759000|tags________|1|1 5|2||1|3|Other Bookmarks|||1511549555759000|1511549555894000|unfiled_____|1|2 6|2||1|4|mobile|||1511549555759000|1511549555759000|mobile______|1|1 7|1|2|3|1|Getting Started|||1511549555897000|1511549555900000|vaOSWVBus5Xb|0|2 8|2||2|2|Mozilla Firefox|||1511549555900000|1511549555905000|mbH-q0s0dRck|0|5 9|1|3|8|0|Help and Tutorials|||1511549555901000|1511549555902000|Yk4kmW0ggs-g|0|2 10|1|4|8|1|Customize Firefox|||1511549555902000|1511549555903000|2Tqd-7CX_4IK|0|2 11|1|5|8|2|Get Involved|||1511549555904000|1511549555905000|PZ5ryma0-vic|0|2 12|1|6|8|3|About Us|||1511549555905000|1511549555906000|IrZIt1HsbFEl|0|2 13|1|7|3|0|Most Visited|||1511549555923000|1511549555955000|lWpPgrVeRjwD|1|2 14|1|8|2|0|Recent Tags|||1511549555955000|1511549555969000|Gyq4voQ9v5Wk|1|2 15|3||2|1||||1511549555976000|1511549555976000|oZKWNKmvfGcz|1|1 sqlite> select * from moz_bookmarks_deleted; sqlite> select * from moz_historyvisits; 1|0|1|1511549555740045|1|0 2|0|9|1511549555969726|1|0 3|2|10|1511549556034053|5|0 sqlite> select * from moz_hosts; 1|mozilla.org|140|0| 2|support.mozilla.org|140|0| sqlite> select * from moz_inputhistory; sqlite> select * from moz_items_annos; 1|6|1|1|0|4|1|240441240|240441240 2|3|2|Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar|0|4|3|1511549555896000|1511549555896000 3|13|3|MostVisited|0|4|3|1511549555955000|1511549555955000 4|14|3|RecentTags|0|4|3|1511549555969000|1511549555969000 sqlite> select * from moz_keywords; sqlite> select * from moz_places; 1|https://www.mozilla.org/en-US/firefox/57.0/firstrun/|Welcome to Firefox|gro.allizom.www.|1|0|0|100|1511549555740045|lPFu5Q-5WggG|0|47357702733362|| 2|https://www.mozilla.org/en-US/firefox/central/||gro.allizom.www.|0|0|0|140||7wnKOlnK7xYW|1|47356370932282|| 3|https://support.mozilla.org/en-US/products/firefox||gro.allizom.troppus.|0|0|0|140||WJEEUKJR5m_Q|1|47357795150914|| 4|https://www.mozilla.org/en-US/firefox/customize/||gro.allizom.www.|0|0|0|140||GbNOnfHsBSSJ|1|47357014640010|| 5|https://www.mozilla.org/en-US/contribute/||gro.allizom.www.|0|0|0|140||lwa0vuxLvxXt|1|47358034485371|| 6|https://www.mozilla.org/en-US/about/||gro.allizom.www.|0|0|0|140||OtK7Z4Q-wSTR|1|47358774953055|| 7|place:sort=8&maxResults=10||.|0|1|0|0||myMb14BJnvGi|1|268505095842199|| 8|place:type=6&sort=14&maxResults=10||.|0|1|0|0||mMjnLa6WCX_C|1|268505606444332|| 9|https://www.mozilla.org/privacy/firefox/||gro.allizom.www.|1|1|0|25|1511549555969726|lxnNte7gemMe|0|47356411089529|| 10|https://www.mozilla.org/en-US/privacy/firefox/||gro.allizom.www.|1|0|0|100|1511549556034053|KA8U_nxp9AfC|0|47358032558425|| ```
adamdecaf commented 6 years ago

The column name checks can be added to these after https://github.com/go-sqlite/sqlite3/pull/17

zellyn commented 6 years ago

lgtm

adamdecaf commented 6 years ago

Files are renamed. :)

sbinet commented 6 years ago

ah... I didn't notice at first, but the tests are failing. seems real and related to the new files that trigger an invalid index (=-1) for column name extraction...

adamdecaf commented 6 years ago

Dang. It looks like #17 was too simple of a fix.

adamdecaf commented 6 years ago

Alright, this parses the tables now. I'm not too familiar with sqlite's sql dialect, but are there other statements which would appear?

The tests panic, because of https://github.com/go-sqlite/sqlite3/commit/b57e325f545db253ce37589fdb7073a2f1dcd545#r26970773

Would y'all want the full schema for chrome and firefox laid out in this test? It'll make the file pretty long.

zellyn commented 6 years ago

Don't need full schemas laid out in the test… just make sure the test that loads those example tables tries to parse the full table definitions. That way it'll catch errors if it's broken.

adamdecaf commented 6 years ago

https://github.com/go-sqlite/sqlite3/pull/18/commits/99dceb84f5fa8361dfaa53a0b4fe503d7ee9d208 checks the parsed table counts.