Skip to content

Commit

Permalink
Fixed sql query errors, adjusted db schema slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenldl committed Dec 29, 2024
1 parent 12c92f6 commit b5287e9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bin/docfd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ let document_store_of_document_src ~env ~interactive pool (document_src : Docume
use_db (fun db ->
with_stmt db
{|
SELECT 0 FROM doc_info WHERE doc_hash = @doc_hash
SELECT 0 FROM doc_info WHERE hash = @doc_hash
|}
(fun stmt ->
List.partition (fun (_, _, doc_hash) ->
Expand Down
17 changes: 8 additions & 9 deletions lib/index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ let doc_id_of_doc_hash : Sqlite3.db -> string -> int64 =
{|
SELECT id
FROM doc_info
WHERE doc_hash = @doc_hash
WHERE hash = @doc_hash
|}
~names:[ ("@doc_hash", TEXT doc_hash) ]
(fun stmt ->
Expand All @@ -278,7 +278,7 @@ let load_raw_into_db db ~doc_hash (x : Raw.t) : unit =
step_stmt db
{|
INSERT INTO doc_info
(id, doc_hash, page_count, global_line_count, max_pos)
(id, hash, page_count, global_line_count, max_pos)
VALUES
(NULL, @doc_hash, @page_count, @global_line_count, @max_pos)
|}
Expand Down Expand Up @@ -377,7 +377,7 @@ let global_line_count =
step_stmt db
{|
SELECT global_line_count FROM doc_info
WHERE doc_hash = @doc_hash
WHERE hash = @doc_hash
|}
~names:[ ("@doc_hash", TEXT doc_hash) ]
(fun stmt ->
Expand All @@ -388,13 +388,12 @@ let global_line_count =

let page_count db ~doc_hash =
let open Sqlite3_utils in
let doc_id = doc_id_of_doc_hash db doc_hash in
step_stmt db
{|
SELECT page_count FROM doc_info
WHERE doc_id = @doc_id
WHERE hash = @doc_hash
|}
~names:[("@doc_id", INT doc_id)]
~names:[("@doc_hash", TEXT doc_hash)]
(fun stmt ->
column_int stmt 0
)
Expand All @@ -413,7 +412,7 @@ let is_indexed db ~doc_hash =
{|
SELECT 0
FROM doc_info
WHERE doc_hash = @doc_hash
WHERE hash = @doc_hash
|}
~names:[ ("@doc_hash", TEXT doc_hash) ]
(fun stmt ->
Expand Down Expand Up @@ -536,10 +535,10 @@ let words_of_global_line_num : Sqlite3.db -> doc_hash:string -> int -> string Dy

let words_of_page_num db ~doc_hash x : string Dynarray.t =
let open Sqlite3_utils in
let doc_id = doc_id_of_doc_hash db doc_hash in
if x >= page_count db ~doc_hash then (
invalid_arg "Index.words_of_page_num: page_num out of range"
) else (
let doc_id = doc_id_of_doc_hash db doc_hash in
let start, end_inc =
step_stmt db
{|
Expand Down Expand Up @@ -616,7 +615,7 @@ let max_pos db ~doc_hash =
{|
SELECT max_pos
FROM doc_info
WHERE doc_hash = @doc_hash
WHERE hash = @doc_hash
|}
~names:[ ("@doc_hash", TEXT doc_hash) ]
(fun stmt ->
Expand Down
4 changes: 2 additions & 2 deletions lib/params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ CREATE INDEX IF NOT EXISTS page_info_index_1 ON page_info (doc_id);

CREATE TABLE IF NOT EXISTS doc_info (
id integer PRIMARY KEY AUTOINCREMENT,
doc_hash varchar(500),
hash varchar(500),
page_count integer,
global_line_count integer,
max_pos integer
);

CREATE INDEX IF NOT EXISTS doc_info_index_1 ON doc_info (doc_hash);
CREATE INDEX IF NOT EXISTS doc_info_index_1 ON doc_info (hash);

CREATE TABLE IF NOT EXISTS word (
id integer,
Expand Down

0 comments on commit b5287e9

Please sign in to comment.