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