mirror of
https://github.com/ankitects/anki.git
synced 2025-09-20 06:52:21 -04:00
reformat .sql files
This commit is contained in:
parent
f452d56e02
commit
56e4e2d518
60 changed files with 505 additions and 583 deletions
|
@ -1,10 +1,13 @@
|
||||||
create table media (
|
CREATE TABLE media (
|
||||||
fname text not null primary key,
|
fname text NOT NULL PRIMARY KEY,
|
||||||
csum text, -- null indicates deleted file
|
csum text,
|
||||||
mtime int not null, -- zero if deleted
|
-- null indicates deleted file
|
||||||
dirty int not null
|
mtime int NOT NULL,
|
||||||
|
-- zero if deleted
|
||||||
|
dirty int NOT NULL
|
||||||
) without rowid;
|
) without rowid;
|
||||||
|
CREATE INDEX idx_media_dirty ON media (dirty)
|
||||||
create index idx_media_dirty on media (dirty) where dirty=1;
|
WHERE dirty = 1;
|
||||||
|
CREATE TABLE meta (dirMod int, lastUsn int);
|
||||||
create table meta (dirMod int, lastUsn int); insert into meta values (0, 0);
|
INSERT INTO meta
|
||||||
|
VALUES (0, 0);
|
|
@ -1,11 +1,9 @@
|
||||||
drop table if exists sort_order;
|
DROP TABLE IF EXISTS sort_order;
|
||||||
create temporary table sort_order (
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
pos integer primary key,
|
pos integer PRIMARY KEY,
|
||||||
did integer not null unique
|
did integer NOT NULL UNIQUE
|
||||||
);
|
);
|
||||||
insert into sort_order (did)
|
INSERT INTO sort_order (did)
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM decks
|
||||||
from decks
|
ORDER BY name;
|
||||||
order by
|
|
||||||
name;
|
|
|
@ -1,11 +1,9 @@
|
||||||
drop table if exists sort_order;
|
DROP TABLE IF EXISTS sort_order;
|
||||||
create temporary table sort_order (
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
pos integer primary key,
|
pos integer PRIMARY KEY,
|
||||||
ntid integer not null unique
|
ntid integer NOT NULL UNIQUE
|
||||||
);
|
);
|
||||||
insert into sort_order (ntid)
|
INSERT INTO sort_order (ntid)
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM notetypes
|
||||||
from notetypes
|
ORDER BY name;
|
||||||
order by
|
|
||||||
name;
|
|
|
@ -1,14 +1,12 @@
|
||||||
drop table if exists sort_order;
|
DROP TABLE IF EXISTS sort_order;
|
||||||
create temporary table sort_order (
|
CREATE TEMPORARY TABLE sort_order (
|
||||||
pos integer primary key,
|
pos integer PRIMARY KEY,
|
||||||
ntid integer not null,
|
ntid integer NOT NULL,
|
||||||
ord integer not null,
|
ord integer NOT NULL,
|
||||||
unique(ntid, ord)
|
UNIQUE(ntid, ord)
|
||||||
);
|
);
|
||||||
insert into sort_order (ntid, ord)
|
INSERT INTO sort_order (ntid, ord)
|
||||||
select
|
SELECT ntid,
|
||||||
ntid,
|
|
||||||
ord
|
ord
|
||||||
from templates
|
FROM templates
|
||||||
order by
|
ORDER BY name
|
||||||
name
|
|
|
@ -1,4 +1,4 @@
|
||||||
insert into cards (
|
INSERT INTO cards (
|
||||||
id,
|
id,
|
||||||
nid,
|
nid,
|
||||||
did,
|
did,
|
||||||
|
@ -18,21 +18,18 @@ insert into cards (
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM cards
|
||||||
from cards
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM cards
|
||||||
max(id) + 1
|
|
||||||
from cards
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into cards (
|
OR REPLACE INTO cards (
|
||||||
id,
|
id,
|
||||||
nid,
|
nid,
|
||||||
did,
|
did,
|
||||||
|
@ -19,8 +19,7 @@ insert
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert into search_cids
|
INSERT INTO search_cids
|
||||||
select id
|
SELECT id
|
||||||
from cards
|
FROM cards
|
||||||
where due >= ?
|
WHERE due >= ?
|
||||||
and type = ?
|
AND type = ?
|
|
@ -1,28 +1,28 @@
|
||||||
select coalesce(
|
SELECT coalesce(
|
||||||
sum(
|
sum(
|
||||||
queue in (:review_queue, :day_learn_queue)
|
queue IN (:review_queue, :day_learn_queue)
|
||||||
and due <= :today
|
AND due <= :today
|
||||||
),
|
),
|
||||||
0
|
0
|
||||||
) as review_count,
|
) AS review_count,
|
||||||
coalesce(sum(queue = :new_queue), 0) as new_count,
|
coalesce(sum(queue = :new_queue), 0) AS new_count,
|
||||||
coalesce(sum(queue = :sched_buried_queue), 0) as sched_buried,
|
coalesce(sum(queue = :sched_buried_queue), 0) AS sched_buried,
|
||||||
coalesce(sum(queue = :user_buried_queue), 0) as user_buried,
|
coalesce(sum(queue = :user_buried_queue), 0) AS user_buried,
|
||||||
coalesce(sum(queue = :learn_queue), 0) as learn_count,
|
coalesce(sum(queue = :learn_queue), 0) AS learn_count,
|
||||||
max(
|
max(
|
||||||
0,
|
0,
|
||||||
coalesce(
|
coalesce(
|
||||||
min(
|
min(
|
||||||
case
|
CASE
|
||||||
when queue = :learn_queue then due
|
WHEN queue = :learn_queue THEN due
|
||||||
else null
|
ELSE NULL
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
0
|
0
|
||||||
)
|
|
||||||
) as first_learn_due
|
|
||||||
from cards
|
|
||||||
where did in (
|
|
||||||
select id
|
|
||||||
from active_decks
|
|
||||||
)
|
)
|
||||||
|
) AS first_learn_due
|
||||||
|
FROM cards
|
||||||
|
WHERE did IN (
|
||||||
|
SELECT id
|
||||||
|
FROM active_decks
|
||||||
|
)
|
|
@ -1,20 +1,18 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET due = (
|
||||||
due = (
|
CASE
|
||||||
case
|
WHEN type = 0
|
||||||
when type = 0
|
AND queue != 4 THEN 1000000 + due % 1000000
|
||||||
and queue != 4 then 1000000 + due % 1000000
|
ELSE due
|
||||||
else due
|
END
|
||||||
end
|
|
||||||
),
|
),
|
||||||
mod = ?1,
|
mod = ?1,
|
||||||
usn = ?2
|
usn = ?2
|
||||||
where
|
WHERE due != (
|
||||||
due != (
|
CASE
|
||||||
case
|
WHEN type = 0
|
||||||
when type = 0
|
AND queue != 4 THEN 1000000 + due % 1000000
|
||||||
and queue != 4 then 1000000 + due % 1000000
|
ELSE due
|
||||||
else due
|
END
|
||||||
end
|
|
||||||
)
|
)
|
||||||
and due >= 1000000;
|
AND due >= 1000000;
|
|
@ -1,19 +1,17 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET due = (
|
||||||
due = (
|
CASE
|
||||||
case
|
WHEN queue = 2
|
||||||
when queue = 2
|
AND due > 100000 THEN ?1
|
||||||
and due > 100000 then ?1
|
ELSE min(max(round(due), -2147483648), 2147483647)
|
||||||
else min(max(round(due), -2147483648), 2147483647)
|
END
|
||||||
end
|
|
||||||
),
|
),
|
||||||
mod = ?2,
|
mod = ?2,
|
||||||
usn = ?3
|
usn = ?3
|
||||||
where
|
WHERE due != (
|
||||||
due != (
|
CASE
|
||||||
case
|
WHEN queue = 2
|
||||||
when queue = 2
|
AND due > 100000 THEN ?1
|
||||||
and due > 100000 then ?1
|
ELSE min(max(round(due), -2147483648), 2147483647)
|
||||||
else min(max(round(due), -2147483648), 2147483647)
|
END
|
||||||
end
|
|
||||||
);
|
);
|
|
@ -1,7 +1,5 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET ivl = min(max(round(ivl), 0), 2147483647),
|
||||||
ivl = min(max(round(ivl), 0), 2147483647),
|
|
||||||
mod = ?1,
|
mod = ?1,
|
||||||
usn = ?2
|
usn = ?2
|
||||||
where
|
WHERE ivl != min(max(round(ivl), 0), 2147483647)
|
||||||
ivl != min(max(round(ivl), 0), 2147483647)
|
|
|
@ -1,10 +1,10 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set factor = 2500,
|
SET factor = 2500,
|
||||||
usn = ?,
|
usn = ?,
|
||||||
mod = ?
|
mod = ?
|
||||||
where factor != 0
|
WHERE factor != 0
|
||||||
and factor <= 2000
|
AND factor <= 2000
|
||||||
and (
|
AND (
|
||||||
did in DECK_IDS
|
did IN DECK_IDS
|
||||||
or odid in DECK_IDS
|
OR odid IN DECK_IDS
|
||||||
)
|
)
|
|
@ -1,27 +1,25 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET odue = (
|
||||||
odue = (
|
CASE
|
||||||
case
|
WHEN odue > 0
|
||||||
when odue > 0
|
AND (
|
||||||
and (
|
|
||||||
type = 1
|
type = 1
|
||||||
or queue = 2
|
OR queue = 2
|
||||||
)
|
)
|
||||||
and not odid then 0
|
AND NOT odid THEN 0
|
||||||
else min(max(round(odue), -2147483648), 2147483647)
|
ELSE min(max(round(odue), -2147483648), 2147483647)
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
mod = ?1,
|
mod = ?1,
|
||||||
usn = ?2
|
usn = ?2
|
||||||
where
|
WHERE odue != (
|
||||||
odue != (
|
CASE
|
||||||
case
|
WHEN odue > 0
|
||||||
when odue > 0
|
AND (
|
||||||
and (
|
|
||||||
type = 1
|
type = 1
|
||||||
or queue = 2
|
OR queue = 2
|
||||||
)
|
)
|
||||||
and not odid then 0
|
AND NOT odid THEN 0
|
||||||
else min(max(round(odue), -2147483648), 2147483647)
|
ELSE min(max(round(odue), -2147483648), 2147483647)
|
||||||
end
|
END
|
||||||
);
|
);
|
|
@ -1,14 +1,13 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
nid,
|
nid,
|
||||||
did,
|
did,
|
||||||
ord,
|
ord,
|
||||||
cast(mod as integer),
|
cast(mod AS integer),
|
||||||
usn,
|
usn,
|
||||||
type,
|
type,
|
||||||
queue,
|
queue,
|
||||||
due,
|
due,
|
||||||
cast(ivl as integer),
|
cast(ivl AS integer),
|
||||||
factor,
|
factor,
|
||||||
reps,
|
reps,
|
||||||
lapses,
|
lapses,
|
||||||
|
@ -17,4 +16,4 @@ select
|
||||||
odid,
|
odid,
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
from cards
|
FROM cards
|
|
@ -1,2 +1,2 @@
|
||||||
drop table if exists search_cids;
|
DROP TABLE IF EXISTS search_cids;
|
||||||
create temporary table search_cids (cid integer primary key not null);
|
CREATE TEMPORARY TABLE search_cids (cid integer PRIMARY KEY NOT NULL);
|
|
@ -1,2 +1,2 @@
|
||||||
drop table if exists search_cids;
|
DROP TABLE IF EXISTS search_cids;
|
||||||
create temporary table search_cids (cid integer not null);
|
CREATE TEMPORARY TABLE search_cids (cid integer NOT NULL);
|
|
@ -1,6 +1,5 @@
|
||||||
update cards
|
UPDATE cards
|
||||||
set
|
SET nid = ?,
|
||||||
nid = ?,
|
|
||||||
did = ?,
|
did = ?,
|
||||||
ord = ?,
|
ord = ?,
|
||||||
mod = ?,
|
mod = ?,
|
||||||
|
@ -17,5 +16,4 @@ set
|
||||||
odid = ?,
|
odid = ?,
|
||||||
flags = ?,
|
flags = ?,
|
||||||
data = ?
|
data = ?
|
||||||
where
|
WHERE id = ?
|
||||||
id = ?
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into config (key, usn, mtime_secs, val)
|
OR REPLACE INTO config (KEY, usn, mtime_secs, val)
|
||||||
values
|
VALUES (?, ?, ?, ?)
|
||||||
(?, ?, ?, ?)
|
|
|
@ -1,5 +1,3 @@
|
||||||
select
|
SELECT val
|
||||||
val
|
FROM config
|
||||||
from config
|
WHERE KEY = ?
|
||||||
where
|
|
||||||
key = ?
|
|
|
@ -1,13 +1,10 @@
|
||||||
select
|
SELECT CASE
|
||||||
case
|
WHEN ?1 IN (
|
||||||
when ?1 in (
|
SELECT id
|
||||||
select
|
FROM decks
|
||||||
id
|
) THEN (
|
||||||
from decks
|
SELECT max(id) + 1
|
||||||
) then (
|
FROM decks
|
||||||
select
|
|
||||||
max(id) + 1
|
|
||||||
from decks
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end;
|
END;
|
|
@ -1,9 +1,7 @@
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM cards
|
||||||
from cards
|
WHERE did = ?1
|
||||||
where
|
OR (
|
||||||
did = ?1
|
|
||||||
or (
|
|
||||||
odid != 0
|
odid != 0
|
||||||
and odid = ?1
|
AND odid = ?1
|
||||||
)
|
)
|
|
@ -1,41 +1,41 @@
|
||||||
select did,
|
SELECT did,
|
||||||
sum(queue = :new_queue),
|
sum(queue = :new_queue),
|
||||||
sum(
|
sum(
|
||||||
queue = :review_queue
|
queue = :review_queue
|
||||||
and due <= :day_cutoff
|
AND due <= :day_cutoff
|
||||||
),
|
),
|
||||||
-- learning
|
-- learning
|
||||||
sum(
|
sum(
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
:sched_ver
|
:sched_ver
|
||||||
when 2 then (
|
WHEN 2 THEN (
|
||||||
-- v2 scheduler
|
-- v2 scheduler
|
||||||
(
|
(
|
||||||
queue = :learn_queue
|
queue = :learn_queue
|
||||||
and due < :learn_cutoff
|
AND due < :learn_cutoff
|
||||||
)
|
)
|
||||||
or (
|
OR (
|
||||||
queue = :daylearn_queue
|
queue = :daylearn_queue
|
||||||
and due <= :day_cutoff
|
AND due <= :day_cutoff
|
||||||
)
|
)
|
||||||
or (
|
OR (
|
||||||
queue = :preview_queue
|
queue = :preview_queue
|
||||||
and due <= :learn_cutoff
|
AND due <= :learn_cutoff
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else (
|
ELSE (
|
||||||
-- v1 scheduler
|
-- v1 scheduler
|
||||||
case
|
CASE
|
||||||
when queue = :learn_queue
|
WHEN queue = :learn_queue
|
||||||
and due < :learn_cutoff then left / 1000
|
AND due < :learn_cutoff THEN left / 1000
|
||||||
when queue = :daylearn_queue
|
WHEN queue = :daylearn_queue
|
||||||
and due <= :day_cutoff then 1
|
AND due <= :day_cutoff THEN 1
|
||||||
else 0
|
ELSE 0
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
from cards
|
FROM cards
|
||||||
where queue >= 0
|
WHERE queue >= 0
|
|
@ -1,8 +1,7 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
common,
|
common,
|
||||||
kind
|
kind
|
||||||
from decks
|
FROM decks
|
|
@ -1,9 +1,6 @@
|
||||||
select
|
SELECT DISTINCT did
|
||||||
distinct did
|
FROM cards
|
||||||
from cards
|
WHERE did NOT IN (
|
||||||
where
|
SELECT id
|
||||||
did not in (
|
FROM decks
|
||||||
select
|
|
||||||
id
|
|
||||||
from decks
|
|
||||||
);
|
);
|
|
@ -1,8 +1,8 @@
|
||||||
insert into active_decks
|
INSERT INTO active_decks
|
||||||
select id
|
SELECT id
|
||||||
from decks
|
FROM decks
|
||||||
where name = ?
|
WHERE name = ?
|
||||||
or (
|
OR (
|
||||||
name >= ?
|
name >= ?
|
||||||
and name < ?
|
AND name < ?
|
||||||
)
|
)
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into decks (id, name, mtime_secs, usn, common, kind)
|
OR REPLACE INTO decks (id, name, mtime_secs, usn, common, kind)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
(?, ?, ?, ?, ?, ?)
|
|
|
@ -1,19 +1,16 @@
|
||||||
insert into deck_config (id, name, mtime_secs, usn, config)
|
INSERT INTO deck_config (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM deck_config
|
||||||
from deck_config
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM deck_config
|
||||||
max(id) + 1
|
|
||||||
from deck_config
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into deck_config (id, name, mtime_secs, usn, config)
|
OR REPLACE INTO deck_config (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?);
|
||||||
(?, ?, ?, ?, ?);
|
|
|
@ -1,7 +1,6 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
config
|
config
|
||||||
from deck_config
|
FROM deck_config
|
|
@ -1,8 +1,6 @@
|
||||||
update deck_config
|
UPDATE deck_config
|
||||||
set
|
SET name = ?,
|
||||||
name = ?,
|
|
||||||
mtime_secs = ?,
|
mtime_secs = ?,
|
||||||
usn = ?,
|
usn = ?,
|
||||||
config = ?
|
config = ?
|
||||||
where
|
WHERE id = ?;
|
||||||
id = ?;
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or ignore into graves (usn, oid, type)
|
OR IGNORE INTO graves (usn, oid, type)
|
||||||
values
|
VALUES (?, ?, ?)
|
||||||
(?, ?, ?)
|
|
|
@ -1,4 +1,4 @@
|
||||||
insert into notes (
|
INSERT INTO notes (
|
||||||
id,
|
id,
|
||||||
guid,
|
guid,
|
||||||
mid,
|
mid,
|
||||||
|
@ -11,21 +11,18 @@ insert into notes (
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM notes
|
||||||
from notes
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM notes
|
||||||
max(id) + 1
|
|
||||||
from notes
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notes (
|
OR REPLACE INTO notes (
|
||||||
id,
|
id,
|
||||||
guid,
|
guid,
|
||||||
mid,
|
mid,
|
||||||
|
@ -12,8 +12,7 @@ insert
|
||||||
flags,
|
flags,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
guid,
|
guid,
|
||||||
mid,
|
mid,
|
||||||
mod,
|
mod,
|
||||||
usn,
|
usn,
|
||||||
tags,
|
tags,
|
||||||
flds
|
flds
|
||||||
from notes
|
FROM notes
|
|
@ -1,5 +1,3 @@
|
||||||
select
|
SELECT COUNT(id) = 0
|
||||||
count(id) = 0
|
FROM cards
|
||||||
from cards
|
WHERE nid = ?;
|
||||||
where
|
|
||||||
nid = ?;
|
|
|
@ -1,6 +1,5 @@
|
||||||
update notes
|
UPDATE notes
|
||||||
set
|
SET guid = ?,
|
||||||
guid = ?,
|
|
||||||
mid = ?,
|
mid = ?,
|
||||||
mod = ?,
|
mod = ?,
|
||||||
usn = ?,
|
usn = ?,
|
||||||
|
@ -8,5 +7,4 @@ set
|
||||||
flds = ?,
|
flds = ?,
|
||||||
sfld = ?,
|
sfld = ?,
|
||||||
csum = ?
|
csum = ?
|
||||||
where
|
WHERE id = ?
|
||||||
id = ?
|
|
|
@ -1,19 +1,16 @@
|
||||||
insert into notetypes (id, name, mtime_secs, usn, config)
|
INSERT INTO notetypes (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (
|
||||||
(
|
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select
|
SELECT id
|
||||||
id
|
FROM notetypes
|
||||||
from notetypes
|
) THEN (
|
||||||
) then (
|
SELECT max(id) + 1
|
||||||
select
|
FROM notetypes
|
||||||
max(id) + 1
|
|
||||||
from notetypes
|
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notetypes (id, name, mtime_secs, usn, config)
|
OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?);
|
||||||
(?, ?, ?, ?, ?);
|
|
|
@ -1,10 +1,7 @@
|
||||||
delete from cards
|
DELETE FROM cards
|
||||||
where
|
WHERE nid IN (
|
||||||
nid in (
|
SELECT id
|
||||||
select
|
FROM notes
|
||||||
id
|
WHERE mid = ?
|
||||||
from notes
|
|
||||||
where
|
|
||||||
mid = ?
|
|
||||||
)
|
)
|
||||||
and ord = ?;
|
AND ord = ?;
|
|
@ -1,27 +1,26 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
nid,
|
nid,
|
||||||
ord,
|
ord,
|
||||||
-- original deck
|
-- original deck
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
odid
|
odid
|
||||||
when 0 then did
|
WHEN 0 THEN did
|
||||||
else odid
|
ELSE odid
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
-- new position if card is empty
|
-- new position if card is empty
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
type
|
type
|
||||||
when 0 then (
|
WHEN 0 THEN (
|
||||||
case
|
CASE
|
||||||
odue
|
odue
|
||||||
when 0 then max(0, due)
|
WHEN 0 THEN max(0, due)
|
||||||
else max(odue, 0)
|
ELSE max(odue, 0)
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
else null
|
ELSE NULL
|
||||||
end
|
END
|
||||||
)
|
)
|
||||||
from cards c
|
FROM cards c
|
|
@ -1,10 +1,6 @@
|
||||||
select
|
SELECT DISTINCT name
|
||||||
distinct name
|
FROM FIELDS
|
||||||
from fields
|
WHERE ntid IN (
|
||||||
where
|
SELECT mid
|
||||||
ntid in (
|
FROM notes
|
||||||
select
|
WHERE id IN
|
||||||
mid
|
|
||||||
from notes
|
|
||||||
where
|
|
||||||
id in
|
|
|
@ -1,9 +1,6 @@
|
||||||
select
|
SELECT ord,
|
||||||
ord,
|
|
||||||
name,
|
name,
|
||||||
config
|
config
|
||||||
from fields
|
FROM FIELDS
|
||||||
where
|
WHERE ntid = ?
|
||||||
ntid = ?
|
ORDER BY ord
|
||||||
order by
|
|
||||||
ord
|
|
|
@ -1,7 +1,6 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
config
|
config
|
||||||
from notetypes
|
FROM notetypes
|
|
@ -1,4 +1,3 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
name
|
name
|
||||||
from notetypes
|
FROM notetypes
|
|
@ -1,11 +1,8 @@
|
||||||
select
|
SELECT ord,
|
||||||
ord,
|
|
||||||
name,
|
name,
|
||||||
mtime_secs,
|
mtime_secs,
|
||||||
usn,
|
usn,
|
||||||
config
|
config
|
||||||
from templates
|
FROM templates
|
||||||
where
|
WHERE ntid = ?
|
||||||
ntid = ?
|
ORDER BY ord
|
||||||
order by
|
|
||||||
ord
|
|
|
@ -1,13 +1,9 @@
|
||||||
select
|
SELECT nt.id,
|
||||||
nt.id,
|
|
||||||
nt.name,
|
nt.name,
|
||||||
(
|
(
|
||||||
select
|
SELECT COUNT(*)
|
||||||
count(*)
|
FROM notes n
|
||||||
from notes n
|
WHERE nt.id = n.mid
|
||||||
where
|
|
||||||
nt.id = n.mid
|
|
||||||
)
|
)
|
||||||
from notetypes nt
|
FROM notetypes nt
|
||||||
order by
|
ORDER BY nt.name
|
||||||
nt.name
|
|
|
@ -1,7 +1,7 @@
|
||||||
select coalesce(max(ord), 0)
|
SELECT coalesce(max(ord), 0)
|
||||||
from cards
|
FROM cards
|
||||||
where nid in (
|
WHERE nid IN (
|
||||||
select id
|
SELECT id
|
||||||
from notes
|
FROM notes
|
||||||
where mid = ?
|
WHERE mid = ?
|
||||||
)
|
)
|
|
@ -1,3 +1,2 @@
|
||||||
insert into fields (ntid, ord, name, config)
|
INSERT INTO FIELDS (ntid, ord, name, config)
|
||||||
values
|
VALUES (?, ?, ?, ?);
|
||||||
(?, ?, ?, ?);
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notetype_config (ntid, config)
|
OR REPLACE INTO notetype_config (ntid, config)
|
||||||
values
|
VALUES (?, ?)
|
||||||
(?, ?)
|
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or replace into notetypes (id, name, mtime_secs, usn, config)
|
OR REPLACE INTO notetypes (id, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?)
|
||||||
(?, ?, ?, ?, ?)
|
|
|
@ -1,3 +1,2 @@
|
||||||
insert into templates (ntid, ord, name, mtime_secs, usn, config)
|
INSERT INTO templates (ntid, ord, name, mtime_secs, usn, config)
|
||||||
values
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
(?, ?, ?, ?, ?, ?)
|
|
|
@ -1,5 +1,5 @@
|
||||||
insert
|
INSERT
|
||||||
or ignore into revlog (
|
OR IGNORE INTO revlog (
|
||||||
id,
|
id,
|
||||||
cid,
|
cid,
|
||||||
usn,
|
usn,
|
||||||
|
@ -10,18 +10,18 @@ insert
|
||||||
time,
|
time,
|
||||||
type
|
type
|
||||||
)
|
)
|
||||||
values (
|
VALUES (
|
||||||
(
|
(
|
||||||
case
|
CASE
|
||||||
when ?1 in (
|
WHEN ?1 IN (
|
||||||
select id
|
SELECT id
|
||||||
from revlog
|
FROM revlog
|
||||||
) then (
|
) THEN (
|
||||||
select max(id) + 1
|
SELECT max(id) + 1
|
||||||
from revlog
|
FROM revlog
|
||||||
)
|
)
|
||||||
else ?1
|
ELSE ?1
|
||||||
end
|
END
|
||||||
),
|
),
|
||||||
?,
|
?,
|
||||||
?,
|
?,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
update revlog
|
UPDATE revlog
|
||||||
set ivl = min(max(round(ivl), -2147483648), 2147483647),
|
SET ivl = min(max(round(ivl), -2147483648), 2147483647),
|
||||||
lastIvl = min(max(round(lastIvl), -2147483648), 2147483647),
|
lastIvl = min(max(round(lastIvl), -2147483648), 2147483647),
|
||||||
time = min(max(round(time), 0), 2147483647)
|
time = min(max(round(time), 0), 2147483647)
|
||||||
where ivl != min(max(round(ivl), -2147483648), 2147483647)
|
WHERE ivl != min(max(round(ivl), -2147483648), 2147483647)
|
||||||
or lastIvl != min(max(round(lastIvl), -2147483648), 2147483647)
|
OR lastIvl != min(max(round(lastIvl), -2147483648), 2147483647)
|
||||||
or time != min(max(round(time), 0), 2147483647)
|
OR time != min(max(round(time), 0), 2147483647)
|
|
@ -1,5 +1,4 @@
|
||||||
select
|
SELECT id,
|
||||||
id,
|
|
||||||
cid,
|
cid,
|
||||||
usn,
|
usn,
|
||||||
ease,
|
ease,
|
||||||
|
@ -8,4 +7,4 @@ select
|
||||||
factor,
|
factor,
|
||||||
time,
|
time,
|
||||||
type
|
type
|
||||||
from revlog
|
FROM revlog
|
|
@ -1,5 +1,5 @@
|
||||||
select count(),
|
SELECT COUNT(),
|
||||||
coalesce(sum(time) / 1000.0, 0.0)
|
coalesce(sum(time) / 1000.0, 0.0)
|
||||||
from revlog
|
FROM revlog
|
||||||
where id > ?
|
WHERE id > ?
|
||||||
and type != ?
|
AND type != ?
|
|
@ -1,88 +1,92 @@
|
||||||
create table col
|
CREATE TABLE col (
|
||||||
(
|
id integer PRIMARY KEY,
|
||||||
id integer primary key,
|
crt integer NOT NULL,
|
||||||
crt integer not null,
|
mod integer NOT NULL,
|
||||||
mod integer not null,
|
scm integer NOT NULL,
|
||||||
scm integer not null,
|
ver integer NOT NULL,
|
||||||
ver integer not null,
|
dty integer NOT NULL,
|
||||||
dty integer not null,
|
usn integer NOT NULL,
|
||||||
usn integer not null,
|
ls integer NOT NULL,
|
||||||
ls integer not null,
|
conf text NOT NULL,
|
||||||
conf text not null,
|
models text NOT NULL,
|
||||||
models text not null,
|
decks text NOT NULL,
|
||||||
decks text not null,
|
dconf text NOT NULL,
|
||||||
dconf text not null,
|
tags text NOT NULL
|
||||||
tags text not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE notes (
|
||||||
create table notes
|
id integer PRIMARY KEY,
|
||||||
(
|
guid text NOT NULL,
|
||||||
id integer primary key,
|
mid integer NOT NULL,
|
||||||
guid text not null,
|
mod integer NOT NULL,
|
||||||
mid integer not null,
|
usn integer NOT NULL,
|
||||||
mod integer not null,
|
tags text NOT NULL,
|
||||||
usn integer not null,
|
flds text NOT NULL,
|
||||||
tags text not null,
|
sfld integer NOT NULL,
|
||||||
flds text not null,
|
csum integer NOT NULL,
|
||||||
sfld integer not null,
|
flags integer NOT NULL,
|
||||||
csum integer not null,
|
data text NOT NULL
|
||||||
flags integer not null,
|
|
||||||
data text not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE cards (
|
||||||
create table cards
|
id integer PRIMARY KEY,
|
||||||
(
|
nid integer NOT NULL,
|
||||||
id integer primary key,
|
did integer NOT NULL,
|
||||||
nid integer not null,
|
ord integer NOT NULL,
|
||||||
did integer not null,
|
mod integer NOT NULL,
|
||||||
ord integer not null,
|
usn integer NOT NULL,
|
||||||
mod integer not null,
|
type integer NOT NULL,
|
||||||
usn integer not null,
|
queue integer NOT NULL,
|
||||||
type integer not null,
|
due integer NOT NULL,
|
||||||
queue integer not null,
|
ivl integer NOT NULL,
|
||||||
due integer not null,
|
factor integer NOT NULL,
|
||||||
ivl integer not null,
|
reps integer NOT NULL,
|
||||||
factor integer not null,
|
lapses integer NOT NULL,
|
||||||
reps integer not null,
|
left integer NOT NULL,
|
||||||
lapses integer not null,
|
odue integer NOT NULL,
|
||||||
left integer not null,
|
odid integer NOT NULL,
|
||||||
odue integer not null,
|
flags integer NOT NULL,
|
||||||
odid integer not null,
|
data text NOT NULL
|
||||||
flags integer not null,
|
|
||||||
data text not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE revlog (
|
||||||
create table revlog
|
id integer PRIMARY KEY,
|
||||||
(
|
cid integer NOT NULL,
|
||||||
id integer primary key,
|
usn integer NOT NULL,
|
||||||
cid integer not null,
|
ease integer NOT NULL,
|
||||||
usn integer not null,
|
ivl integer NOT NULL,
|
||||||
ease integer not null,
|
lastIvl integer NOT NULL,
|
||||||
ivl integer not null,
|
factor integer NOT NULL,
|
||||||
lastIvl integer not null,
|
time integer NOT NULL,
|
||||||
factor integer not null,
|
type integer NOT NULL
|
||||||
time integer not null,
|
|
||||||
type integer not null
|
|
||||||
);
|
);
|
||||||
|
CREATE TABLE graves (
|
||||||
create table graves
|
usn integer NOT NULL,
|
||||||
(
|
oid integer NOT NULL,
|
||||||
usn integer not null,
|
type integer NOT NULL
|
||||||
oid integer not null,
|
|
||||||
type integer not null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
-- syncing
|
-- syncing
|
||||||
create index ix_notes_usn on notes (usn);
|
CREATE INDEX ix_notes_usn ON notes (usn);
|
||||||
create index ix_cards_usn on cards (usn);
|
CREATE INDEX ix_cards_usn ON cards (usn);
|
||||||
create index ix_revlog_usn on revlog (usn);
|
CREATE INDEX ix_revlog_usn ON revlog (usn);
|
||||||
-- card spacing, etc
|
-- card spacing, etc
|
||||||
create index ix_cards_nid on cards (nid);
|
CREATE INDEX ix_cards_nid ON cards (nid);
|
||||||
-- scheduling and deck limiting
|
-- scheduling and deck limiting
|
||||||
create index ix_cards_sched on cards (did, queue, due);
|
CREATE INDEX ix_cards_sched ON cards (did, queue, due);
|
||||||
-- revlog by card
|
-- revlog by card
|
||||||
create index ix_revlog_cid on revlog (cid);
|
CREATE INDEX ix_revlog_cid ON revlog (cid);
|
||||||
-- field uniqueness
|
-- field uniqueness
|
||||||
create index ix_notes_csum on notes (csum);
|
CREATE INDEX ix_notes_csum ON notes (csum);
|
||||||
|
INSERT INTO col
|
||||||
insert into col values (1,0,0,0,0,0,0,0,'{}','{}','{}','{}','{}');
|
VALUES (
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
'{}',
|
||||||
|
'{}',
|
||||||
|
'{}',
|
||||||
|
'{}',
|
||||||
|
'{}'
|
||||||
|
);
|
|
@ -1,4 +1,3 @@
|
||||||
insert
|
INSERT
|
||||||
or ignore into tags (tag, usn)
|
OR IGNORE INTO tags (tag, usn)
|
||||||
values
|
VALUES (?, ?)
|
||||||
(?, ?)
|
|
|
@ -1,12 +1,11 @@
|
||||||
drop table config;
|
DROP TABLE config;
|
||||||
drop table deck_config;
|
DROP TABLE deck_config;
|
||||||
drop table tags;
|
DROP TABLE tags;
|
||||||
drop table fields;
|
DROP TABLE FIELDS;
|
||||||
drop table templates;
|
DROP TABLE templates;
|
||||||
drop table notetypes;
|
DROP TABLE notetypes;
|
||||||
drop table decks;
|
DROP TABLE decks;
|
||||||
drop index idx_cards_odid;
|
DROP INDEX idx_cards_odid;
|
||||||
drop index idx_notes_mid;
|
DROP INDEX idx_notes_mid;
|
||||||
update col
|
UPDATE col
|
||||||
set
|
SET ver = 11;
|
||||||
ver = 11;
|
|
|
@ -1,20 +1,19 @@
|
||||||
create table deck_config (
|
CREATE TABLE deck_config (
|
||||||
id integer primary key not null,
|
id integer PRIMARY KEY NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
config blob not null
|
config blob NOT NULL
|
||||||
);
|
);
|
||||||
create table config (
|
CREATE TABLE config (
|
||||||
key text not null primary key,
|
KEY text NOT NULL PRIMARY KEY,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
val blob not null
|
val blob NOT NULL
|
||||||
) without rowid;
|
) without rowid;
|
||||||
create table tags (
|
CREATE TABLE tags (
|
||||||
tag text not null primary key collate unicase,
|
tag text NOT NULL PRIMARY KEY COLLATE unicase,
|
||||||
usn integer not null
|
usn integer NOT NULL
|
||||||
) without rowid;
|
) without rowid;
|
||||||
update col
|
UPDATE col
|
||||||
set
|
SET ver = 14;
|
||||||
ver = 14;
|
|
|
@ -1,45 +1,43 @@
|
||||||
create table fields (
|
CREATE TABLE FIELDS (
|
||||||
ntid integer not null,
|
ntid integer NOT NULL,
|
||||||
ord integer not null,
|
ord integer NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
config blob not null,
|
config blob NOT NULL,
|
||||||
primary key (ntid, ord)
|
PRIMARY KEY (ntid, ord)
|
||||||
) without rowid;
|
) without rowid;
|
||||||
create unique index idx_fields_name_ntid on fields (name, ntid);
|
CREATE UNIQUE INDEX idx_fields_name_ntid ON FIELDS (name, ntid);
|
||||||
create table templates (
|
CREATE TABLE templates (
|
||||||
ntid integer not null,
|
ntid integer NOT NULL,
|
||||||
ord integer not null,
|
ord integer NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
config blob not null,
|
config blob NOT NULL,
|
||||||
primary key (ntid, ord)
|
PRIMARY KEY (ntid, ord)
|
||||||
) without rowid;
|
) without rowid;
|
||||||
create unique index idx_templates_name_ntid on templates (name, ntid);
|
CREATE UNIQUE INDEX idx_templates_name_ntid ON templates (name, ntid);
|
||||||
create index idx_templates_usn on templates (usn);
|
CREATE INDEX idx_templates_usn ON templates (usn);
|
||||||
create table notetypes (
|
CREATE TABLE notetypes (
|
||||||
id integer not null primary key,
|
id integer NOT NULL PRIMARY KEY,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
config blob not null
|
config blob NOT NULL
|
||||||
);
|
);
|
||||||
create unique index idx_notetypes_name on notetypes (name);
|
CREATE UNIQUE INDEX idx_notetypes_name ON notetypes (name);
|
||||||
create index idx_notetypes_usn on notetypes (usn);
|
CREATE INDEX idx_notetypes_usn ON notetypes (usn);
|
||||||
create table decks (
|
CREATE TABLE decks (
|
||||||
id integer primary key not null,
|
id integer PRIMARY KEY NOT NULL,
|
||||||
name text not null collate unicase,
|
name text NOT NULL COLLATE unicase,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer NOT NULL,
|
||||||
usn integer not null,
|
usn integer NOT NULL,
|
||||||
common blob not null,
|
common blob NOT NULL,
|
||||||
kind blob not null
|
kind blob NOT NULL
|
||||||
);
|
);
|
||||||
create unique index idx_decks_name on decks (name);
|
CREATE UNIQUE INDEX idx_decks_name ON decks (name);
|
||||||
create index idx_notes_mid on notes (mid);
|
CREATE INDEX idx_notes_mid ON notes (mid);
|
||||||
create index idx_cards_odid on cards (odid)
|
CREATE INDEX idx_cards_odid ON cards (odid)
|
||||||
where
|
WHERE odid != 0;
|
||||||
odid != 0;
|
UPDATE col
|
||||||
update col
|
SET ver = 15;
|
||||||
set
|
ANALYZE;
|
||||||
ver = 15;
|
|
||||||
analyze;
|
|
Loading…
Reference in a new issue