Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Jauslin <jauslin@ias.edu>2017-05-02 20:20:48 +0000
committerIan Jauslin <jauslin@ias.edu>2017-05-02 21:38:33 +0000
commit1366aa391af0ec4e6fcef3a10d8345ad2d32e340 (patch)
treeefcc637d71f5f490c15580e13f4e3bf8bd7f3a27 /engines/sqlite.sh
Initial commit
Diffstat (limited to 'engines/sqlite.sh')
-rw-r--r--engines/sqlite.sh115
1 files changed, 115 insertions, 0 deletions
diff --git a/engines/sqlite.sh b/engines/sqlite.sh
new file mode 100644
index 0000000..c14f30c
--- /dev/null
+++ b/engines/sqlite.sh
@@ -0,0 +1,115 @@
+base_SQL="SELECT title,author,journal,year,token,doi,arxiv,citeref,prauth FROM bibliography"
+base_SQL_noprauth="SELECT title,author,journal,year,token,doi,arxiv,citeref FROM bibliography"
+
+# add quotes
+function SQL_addquotes {
+ while read -r line; do
+ # add quotes and escape string
+ if [ -n "$line" ]; then
+ line=$(escape_string "$line")
+ line="${line/%=/= }"
+ line="${line/ = /=\"}"
+ line="${line/%/\"}"
+ fi
+ echo "$line"
+ done
+}
+
+# SQL command for alphabetical ordering
+function generate_SQL_alpha {
+ echo -n "$base_SQL WHERE citeref='"
+
+ # whether there is a citeref
+ exists_citeref=0
+
+ # sift through aux file
+ grep -h "$aux_cmd" $aux | while read -r citeref; do
+ eval "citeref=\${citeref#$aux_cmd}"
+ citeref="${citeref%\}}"
+
+ # replace the citeref with a ref_map if there is any
+ if [ -n "$ref_map" ]; then
+ citeref=$(map_citeref "$citeref")
+ fi
+
+ # Only query the db if there is no matching extra entry
+ foundit=0
+ if [ ${#extra} -gt 0 ]; then
+ for entry in "${extra[@]}"; do
+ ref="${entry#*:*:}"
+ ref="${ref%%:*}"
+ if [ "$ref" = "$citeref" ]; then
+ foundit=1
+ break
+ fi
+ done
+ fi
+
+ if [ "$foundit" = 0 ]; then
+ echo -n "$citeref' OR citeref='"
+ exists_citeref=1
+ fi
+ done
+
+ # if there are no citerefs close '
+ [ $exists_citeref = 0 ] && echo -n "'"
+}
+
+# fetch entries by alphabetical order
+function fetch_BBlog_entries_alpha {
+ SQL="$(generate_SQL_alpha)"
+ SQL="${SQL% OR citeref=\'} ORDER BY prauth,year"
+ sqlite3 -line "$db" "$SQL" | SQL_addquotes
+ # add an empty line
+ echo ""
+}
+
+# fetch entries by order of appearance
+function fetch_BBlog_entries_appearance {
+ # keep track of citerefs to avoid repetitions
+ citeref_list=""
+
+ # sift through aux file
+ grep -h "$aux_cmd" $aux | while read -r citeref; do
+ eval "citeref=\${citeref#$aux_cmd}"
+ citeref="${citeref%\}}"
+
+ # replace the citeref with a ref_map if there is any
+ if [ -n "$ref_map" ]; then
+ citeref=$(map_citeref "$citeref")
+ fi
+
+ # check whether the reference was already cited
+ citeref_list="$citeref_list;"
+ if $(echo "$citeref_list" | grep -q ";$citeref;"); then
+ # remove trailing ';'
+ citeref_list="${citeref_list%;}"
+ else
+ citeref_list="$citeref_list$citeref"
+
+ # Only query the db if there is no matching extra entry
+ foundit=0
+ if [ ${#extra} -gt 0 ]; then
+ for entry in "${extra[@]}"; do
+ ref="${entry#*:}"
+ ref="${ref%%:*}"
+ if [ "$ref" = "$citeref" ]; then
+ foundit=1
+ break
+ fi
+ done
+ fi
+
+ if [ "$foundit" = 0 ]; then
+ SQL="$base_SQL_noprauth WHERE citeref='$citeref'"
+ sqlite3 -line "$db" "$SQL" | SQL_addquotes
+ else
+ echo "citeref=$citeref"
+ fi
+
+ # add an empty line
+ echo ""
+ fi
+ done
+}
+