Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
* vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
3
* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef __nsPlacesTables_h__
8
#define __nsPlacesTables_h__
9
10
#define CREATE_MOZ_PLACES \
11
NS_LITERAL_CSTRING( \
12
"CREATE TABLE moz_places ( " \
13
" id INTEGER PRIMARY KEY" \
14
", url LONGVARCHAR" \
15
", title LONGVARCHAR" \
16
", rev_host LONGVARCHAR" \
17
", visit_count INTEGER DEFAULT 0" \
18
", hidden INTEGER DEFAULT 0 NOT NULL" \
19
", typed INTEGER DEFAULT 0 NOT NULL" \
20
", frecency INTEGER DEFAULT -1 NOT NULL" \
21
", last_visit_date INTEGER " \
22
", guid TEXT" \
23
", foreign_count INTEGER DEFAULT 0 NOT NULL" \
24
", url_hash INTEGER DEFAULT 0 NOT NULL " \
25
", description TEXT" \
26
", preview_image_url TEXT" \
27
", origin_id INTEGER REFERENCES moz_origins(id)" \
28
")")
29
30
#define CREATE_MOZ_HISTORYVISITS \
31
NS_LITERAL_CSTRING( \
32
"CREATE TABLE moz_historyvisits (" \
33
" id INTEGER PRIMARY KEY" \
34
", from_visit INTEGER" \
35
", place_id INTEGER" \
36
", visit_date INTEGER" \
37
", visit_type INTEGER" \
38
", session INTEGER" \
39
")")
40
41
#define CREATE_MOZ_INPUTHISTORY \
42
NS_LITERAL_CSTRING( \
43
"CREATE TABLE moz_inputhistory (" \
44
" place_id INTEGER NOT NULL" \
45
", input LONGVARCHAR NOT NULL" \
46
", use_count INTEGER" \
47
", PRIMARY KEY (place_id, input)" \
48
")")
49
50
// Note: flags, expiration, type, dateAdded and lastModified should be
51
// considered deprecated but are kept to ease backwards compatibility.
52
#define CREATE_MOZ_ANNOS \
53
NS_LITERAL_CSTRING( \
54
"CREATE TABLE moz_annos (" \
55
" id INTEGER PRIMARY KEY" \
56
", place_id INTEGER NOT NULL" \
57
", anno_attribute_id INTEGER" \
58
", content LONGVARCHAR" \
59
", flags INTEGER DEFAULT 0" \
60
", expiration INTEGER DEFAULT 0" \
61
", type INTEGER DEFAULT 0" \
62
", dateAdded INTEGER DEFAULT 0" \
63
", lastModified INTEGER DEFAULT 0" \
64
")")
65
66
#define CREATE_MOZ_ANNO_ATTRIBUTES \
67
NS_LITERAL_CSTRING( \
68
"CREATE TABLE moz_anno_attributes (" \
69
" id INTEGER PRIMARY KEY" \
70
", name VARCHAR(32) UNIQUE NOT NULL" \
71
")")
72
73
#define CREATE_MOZ_ITEMS_ANNOS \
74
NS_LITERAL_CSTRING( \
75
"CREATE TABLE moz_items_annos (" \
76
" id INTEGER PRIMARY KEY" \
77
", item_id INTEGER NOT NULL" \
78
", anno_attribute_id INTEGER" \
79
", content LONGVARCHAR" \
80
", flags INTEGER DEFAULT 0" \
81
", expiration INTEGER DEFAULT 0" \
82
", type INTEGER DEFAULT 0" \
83
", dateAdded INTEGER DEFAULT 0" \
84
", lastModified INTEGER DEFAULT 0" \
85
")")
86
87
#define CREATE_MOZ_BOOKMARKS \
88
NS_LITERAL_CSTRING( \
89
"CREATE TABLE moz_bookmarks (" \
90
" id INTEGER PRIMARY KEY" \
91
", type INTEGER" \
92
", fk INTEGER DEFAULT NULL" /* place_id */ \
93
", parent INTEGER" \
94
", position INTEGER" \
95
", title LONGVARCHAR" \
96
", keyword_id INTEGER" \
97
", folder_type TEXT" \
98
", dateAdded INTEGER" \
99
", lastModified INTEGER" \
100
", guid TEXT" /* The sync status is determined from the change source. \
101
We set this to SYNC_STATUS_NEW = 1 for new local \
102
bookmarks, and SYNC_STATUS_NORMAL = 2 for bookmarks \
103
from other devices. Uploading a local bookmark for the \
104
first time changes its status to SYNC_STATUS_NORMAL. \
105
For bookmarks restored from a backup, we set \
106
SYNC_STATUS_UNKNOWN = 0, indicating that Sync should \
107
reconcile them with bookmarks on the server. If Sync is \
108
disconnected or never set up, all bookmarks will stay \
109
in SYNC_STATUS_NEW. \
110
*/ \
111
", syncStatus INTEGER NOT NULL DEFAULT 0" /* This field is incremented \
112
for every bookmark change \
113
that should trigger a sync. \
114
It's a counter instead of a \
115
Boolean so that we can \
116
track changes made during a \
117
sync, and queue them for \
118
the next sync. Changes made \
119
by Sync don't bump the \
120
counter, to avoid sync \
121
loops. If Sync is \
122
disconnected, we'll reset \
123
the counter to 1 for all \
124
bookmarks. \
125
*/ \
126
", syncChangeCounter INTEGER NOT NULL DEFAULT 1" \
127
")")
128
129
// This table stores tombstones for bookmarks with SYNC_STATUS_NORMAL. We
130
// upload tombstones during a sync, and delete them from this table on success.
131
// If Sync is disconnected, we'll delete all stored tombstones. If Sync is
132
// never set up, we'll never write new tombstones, since all bookmarks will stay
133
// in SYNC_STATUS_NEW.
134
#define CREATE_MOZ_BOOKMARKS_DELETED \
135
NS_LITERAL_CSTRING( \
136
"CREATE TABLE moz_bookmarks_deleted (" \
137
" guid TEXT PRIMARY KEY" \
138
", dateRemoved INTEGER NOT NULL DEFAULT 0" \
139
")")
140
141
#define CREATE_MOZ_KEYWORDS \
142
NS_LITERAL_CSTRING( \
143
"CREATE TABLE moz_keywords (" \
144
" id INTEGER PRIMARY KEY AUTOINCREMENT" \
145
", keyword TEXT UNIQUE" \
146
", place_id INTEGER" \
147
", post_data TEXT" \
148
")")
149
150
#define CREATE_MOZ_ORIGINS \
151
NS_LITERAL_CSTRING( \
152
"CREATE TABLE moz_origins ( " \
153
"id INTEGER PRIMARY KEY, " \
154
"prefix TEXT NOT NULL, " \
155
"host TEXT NOT NULL, " \
156
"frecency INTEGER NOT NULL, " \
157
"UNIQUE (prefix, host) " \
158
")")
159
160
// Note: this should be kept up-to-date with the definition in
161
// nsPlacesAutoComplete.js.
162
#define CREATE_MOZ_OPENPAGES_TEMP \
163
NS_LITERAL_CSTRING( \
164
"CREATE TEMP TABLE moz_openpages_temp (" \
165
" url TEXT" \
166
", userContextId INTEGER" \
167
", open_count INTEGER" \
168
", PRIMARY KEY (url, userContextId)" \
169
")")
170
171
// This table is used, along with moz_places_afterinsert_trigger, to update
172
// origins after places removals. During an INSERT into moz_places, origins are
173
// accumulated in this table, then a DELETE FROM moz_updateoriginsinsert_temp
174
// will take care of updating the moz_origins table for every new origin. See
175
// CREATE_PLACES_AFTERINSERT_TRIGGER in nsPlacestriggers.h for details.
176
#define CREATE_UPDATEORIGINSINSERT_TEMP \
177
NS_LITERAL_CSTRING( \
178
"CREATE TEMP TABLE moz_updateoriginsinsert_temp ( " \
179
"place_id INTEGER PRIMARY KEY, " \
180
"prefix TEXT NOT NULL, " \
181
"host TEXT NOT NULL, " \
182
"frecency INTEGER NOT NULL " \
183
") ")
184
185
// This table is used in a similar way to moz_updateoriginsinsert_temp, but for
186
// deletes, and triggered via moz_places_afterdelete_trigger.
187
//
188
// When rows are added to this table, moz_places.origin_id may be null. That's
189
// why this table uses prefix + host as its primary key, not origin_id.
190
#define CREATE_UPDATEORIGINSDELETE_TEMP \
191
NS_LITERAL_CSTRING( \
192
"CREATE TEMP TABLE moz_updateoriginsdelete_temp ( " \
193
"prefix TEXT NOT NULL, " \
194
"host TEXT NOT NULL, " \
195
"frecency_delta INTEGER NOT NULL, " \
196
"PRIMARY KEY (prefix, host) " \
197
") WITHOUT ROWID ")
198
199
// This table is used in a similar way to moz_updateoriginsinsert_temp, but for
200
// updates to places' frecencies, and triggered via
201
// moz_places_afterupdate_frecency_trigger.
202
//
203
// When rows are added to this table, moz_places.origin_id may be null. That's
204
// why this table uses prefix + host as its primary key, not origin_id.
205
#define CREATE_UPDATEORIGINSUPDATE_TEMP \
206
NS_LITERAL_CSTRING( \
207
"CREATE TEMP TABLE moz_updateoriginsupdate_temp ( " \
208
"prefix TEXT NOT NULL, " \
209
"host TEXT NOT NULL, " \
210
"frecency_delta INTEGER NOT NULL, " \
211
"PRIMARY KEY (prefix, host) " \
212
") WITHOUT ROWID ")
213
214
// This table would not be strictly needed for functionality since it's just
215
// mimicking moz_places, though it's great for database portability.
216
// With this we don't have to take care into account a bunch of database
217
// mismatch cases, where places.sqlite could be mixed up with a favicons.sqlite
218
// created with a different places.sqlite (not just in case of a user messing
219
// up with the profile, but also in case of corruption).
220
#define CREATE_MOZ_PAGES_W_ICONS \
221
NS_LITERAL_CSTRING( \
222
"CREATE TABLE moz_pages_w_icons ( " \
223
"id INTEGER PRIMARY KEY, " \
224
"page_url TEXT NOT NULL, " \
225
"page_url_hash INTEGER NOT NULL " \
226
") ")
227
228
// This table retains the icons data. The hashes url is "fixed" (thus the scheme
229
// and www are trimmed in most cases) so we can quickly query for root icon urls
230
// like "domain/favicon.ico".
231
// We are considering squared icons for simplicity, so storing only one size.
232
// For svg payloads, width will be set to 65535 (UINT16_MAX).
233
#define CREATE_MOZ_ICONS \
234
NS_LITERAL_CSTRING( \
235
"CREATE TABLE moz_icons ( " \
236
"id INTEGER PRIMARY KEY, " \
237
"icon_url TEXT NOT NULL, " \
238
"fixed_icon_url_hash INTEGER NOT NULL, " \
239
"width INTEGER NOT NULL DEFAULT 0, " \
240
"root INTEGER NOT NULL DEFAULT 0, " \
241
"color INTEGER, " \
242
"expire_ms INTEGER NOT NULL DEFAULT 0, " \
243
"data BLOB " \
244
") ")
245
246
// This table maintains relations between icons and pages.
247
// Each page can have multiple icons, and each icon can be used by multiple
248
// pages.
249
#define CREATE_MOZ_ICONS_TO_PAGES \
250
NS_LITERAL_CSTRING( \
251
"CREATE TABLE moz_icons_to_pages ( " \
252
"page_id INTEGER NOT NULL, " \
253
"icon_id INTEGER NOT NULL, " \
254
"PRIMARY KEY (page_id, icon_id), " \
255
"FOREIGN KEY (page_id) REFERENCES moz_pages_w_icons ON DELETE CASCADE, " \
256
"FOREIGN KEY (icon_id) REFERENCES moz_icons ON DELETE CASCADE " \
257
") WITHOUT ROWID ")
258
259
// This table holds key-value metadata for Places and its consumers. Sync stores
260
// the sync IDs for the bookmarks and history collections in this table, and the
261
// last sync time for history.
262
#define CREATE_MOZ_META \
263
NS_LITERAL_CSTRING( \
264
"CREATE TABLE moz_meta (" \
265
"key TEXT PRIMARY KEY, " \
266
"value NOT NULL" \
267
") WITHOUT ROWID ")
268
269
// Keys in the moz_meta table.
270
#define MOZ_META_KEY_ORIGIN_FRECENCY_COUNT "origin_frecency_count"
271
#define MOZ_META_KEY_ORIGIN_FRECENCY_SUM "origin_frecency_sum"
272
#define MOZ_META_KEY_ORIGIN_FRECENCY_SUM_OF_SQUARES \
273
"origin_frecency_sum_of_squares"
274
275
#endif // __nsPlacesTables_h__