1
|
|
|
# MIT License |
2
|
|
|
# |
3
|
|
|
# Copyright (c) 2017 Matt Boyer |
4
|
|
|
# |
5
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy |
6
|
|
|
# of this software and associated documentation files (the "Software"), to deal |
7
|
|
|
# in the Software without restriction, including without limitation the rights |
8
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9
|
|
|
# copies of the Software, and to permit persons to whom the Software is |
10
|
|
|
# furnished to do so, subject to the following conditions: |
11
|
|
|
# |
12
|
|
|
# The above copyright notice and this permission notice shall be included in |
13
|
|
|
# all copies or substantial portions of the Software. |
14
|
|
|
# |
15
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21
|
|
|
# SOFTWARE. |
22
|
|
|
|
23
|
|
|
import collections |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
SQLite_header = collections.namedtuple('SQLite_header', ( |
27
|
|
|
'magic', |
28
|
|
|
'page_size', |
29
|
|
|
'write_format', |
30
|
|
|
'read_format', |
31
|
|
|
'reserved_length', |
32
|
|
|
'max_payload_fraction', |
33
|
|
|
'min_payload_fraction', |
34
|
|
|
'leaf_payload_fraction', |
35
|
|
|
'file_change_counter', |
36
|
|
|
'size_in_pages', |
37
|
|
|
'first_freelist_trunk', |
38
|
|
|
'freelist_pages', |
39
|
|
|
'schema_cookie', |
40
|
|
|
'schema_format', |
41
|
|
|
'default_page_cache_size', |
42
|
|
|
'largest_btree_page', |
43
|
|
|
'text_encoding', |
44
|
|
|
'user_version', |
45
|
|
|
'incremental_vacuum', |
46
|
|
|
'application_id', |
47
|
|
|
'version_valid', |
48
|
|
|
'sqlite_version', |
49
|
|
|
)) |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
SQLite_btree_page_header = collections.namedtuple('SQLite_btree_page_header', ( |
53
|
|
|
'page_type', |
54
|
|
|
'first_freeblock_offset', |
55
|
|
|
'num_cells', |
56
|
|
|
'cell_content_offset', |
57
|
|
|
'num_fragmented_free_bytes', |
58
|
|
|
'right_most_page_idx', |
59
|
|
|
)) |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
SQLite_ptrmap_info = collections.namedtuple('SQLite_ptrmap_info', ( |
63
|
|
|
'page_idx', |
64
|
|
|
'page_type', |
65
|
|
|
'page_ptr', |
66
|
|
|
)) |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
SQLite_record_field = collections.namedtuple('SQLite_record_field', ( |
70
|
|
|
'col_type', |
71
|
|
|
'col_type_descr', |
72
|
|
|
'field_length', |
73
|
|
|
'field_bytes', |
74
|
|
|
)) |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
SQLite_master_record = collections.namedtuple('SQLite_master_record', ( |
78
|
|
|
'type', |
79
|
|
|
'name', |
80
|
|
|
'tbl_name', |
81
|
|
|
'rootpage', |
82
|
|
|
'sql', |
83
|
|
|
)) |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
type_specs = { |
87
|
|
|
'INTEGER': int, |
88
|
|
|
'TEXT': str, |
89
|
|
|
'VARCHAR': str, |
90
|
|
|
'LONGVARCHAR': str, |
91
|
|
|
'REAL': float, |
92
|
|
|
'FLOAT': float, |
93
|
|
|
'LONG': int, |
94
|
|
|
'BLOB': bytes, |
95
|
|
|
} |
96
|
|
|
|