/*
 * DO NOT EDIT DIRECTLY.
 *
 * This file was generated automatically by sqlite-helper-gen
 * from ovsqlite/sql-main.sql.
 *
 * DO NOT EDIT DIRECTLY.
 */


#include "sql-main.h"

#ifdef HAVE_SQLITE3

sqlite_helper_t const sql_main_helper =
{
    37,

    "pragma foreign_keys = 1;\n"
    "\n"
    "pragma journal_mode = 'PERSIST';\n"
    "\n"
    "pragma busy_timeout = 999999999;\n"
    "create temporary table expireart(\n"
    "  artnum integer\n"
    "    primary key);\n"
    "\000"
    "random\000"
    "select randomblob(?1);\n"
    "\000"
    "getmisc\000"
    "select value from misc\n"
    "  where key=?1;\n"
    "\000"
    "setmisc\000"
    "insert or replace into misc (key, value)\n"
    "  values (?1, ?2);\n"
    "\000"
    "unsetmisc\000"
    "delete from misc\n"
    "  where key=?1;\n"
    "\000"
    "begin\000"
    "begin immediate transaction;\n"
    "\000"
    "commit\000"
    "commit transaction;\n"
    "\000"
    "rollback\000"
    "rollback transaction;\n"
    "\000"
    "savepoint\000"
    "savepoint article_group;\n"
    "\000"
    "release_savepoint\000"
    "release savepoint article_group;\n"
    "\000"
    "rollback_savepoint\000"
    "rollback to savepoint article_group;\n"
    "\000"
    "delete_journal\000"
    "pragma journal_mode = 'DELETE';\n"
    "\000"
    "add_group\000"
    "insert into groupinfo (groupname, flag_alias, low, high)\n"
    "  values(?1, ?2, ?3, ?4);\n"
    "\000"
    "get_groupinfo\000"
    "select low, high, \"count\", flag_alias from groupinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1;\n"
    "\000"
    "update_groupinfo_flag_alias\000"
    "update groupinfo\n"
    "  set flag_alias = ?2\n"
    "  where groupid=?1\n"
    "    and flag_alias!=?2;\n"
    "\000"
    "set_group_deleted\000"
    "update groupinfo\n"
    "  set deleted = (select max(deleted) from groupinfo)+1\n"
    "  where deleted=0\n"
    "    and groupname=?1;\n"
    "\000"
    "lookup_groupinfo\000"
    "select groupid, low, high, \"count\" from groupinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1;\n"
    "\000"
    "list_groups\000"
    "select groupid, groupname, low, high, \"count\", flag_alias from groupinfo\n"
    "  where deleted=0\n"
    "    and groupid>?1\n"
    "  order by groupid;\n"
    "\000"
    "add_article\000"
    "insert into artinfo (groupid, artnum, arrived, expires, token, overview)\n"
    "  values(?1, ?2, ?3, ?4, ?5, ?6);\n"
    "\000"
    "update_groupinfo_add\000"
    "update groupinfo\n"
    "  set low = case when \"count\" then min(low, ?2) else ?2 end,\n"
    "    high = case when \"count\" then max(high, ?2) else ?2 end,\n"
    "    \"count\" = \"count\"+1\n"
    "  where groupid=?1;\n"
    "\000"
    "get_artinfo\000"
    "select token\n"
    "  from groupinfo\n"
    "    natural join artinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1\n"
    "    and artnum=?2;\n"
    "\000"
    "delete_article\000"
    "delete from artinfo\n"
    "  where groupid=?1\n"
    "    and artnum=?2;\n"
    "\000"
    "update_groupinfo_delete_all\000"
    "update groupinfo\n"
    "  set low = max(high, 1),\n"
    "    high = max(high-1, 0),\n"
    "    \"count\" = ?2*0\n"
    "  where groupid=?1;\n"
    "\000"
    "update_groupinfo_delete_low\000"
    "update groupinfo\n"
    "  set low = (select min(artnum) from artinfo\n"
    "          where artinfo.groupid=groupinfo.groupid),\n"
    "    \"count\" = \"count\"-?2\n"
    "  where groupid=?1;\n"
    "\000"
    "update_groupinfo_delete_middle\000"
    "update groupinfo\n"
    "  set \"count\" = \"count\"-?2\n"
    "  where groupid=?1;\n"
    "\000"
    "start_expire_group\000"
    "update groupinfo\n"
    "  set expired = ?2\n"
    "    where deleted=0\n"
    "      and groupname=?1;\n"
    "\000"
    "add_expireart\000"
    "insert or ignore into expireart (artnum)\n"
    "  values(?1);\n"
    "\000"
    "fill_expireart\000"
    "insert or ignore into expireart (artnum)\n"
    "  select artnum from artinfo\n"
    "    where groupid=?1\n"
    "    order by artnum\n"
    "    limit ?2;\n"
    "\000"
    "expire_articles\000"
    "delete from artinfo\n"
    "  where groupid=?1\n"
    "    and artnum in expireart;\n"
    "\000"
    "clear_expireart\000"
    "delete from expireart;\n"
    "\000"
    "set_forgotten_deleted\000"
    "update groupinfo\n"
    "  set deleted = (select max(deleted) from groupinfo)+1\n"
    "  where deleted=0\n"
    "    and expired<?1;\n"
    "\000"
    "delete_empty_groups\000"
    "delete from groupinfo\n"
    "  where deleted>0\n"
    "    and not exists\n"
    "      (select * from artinfo\n"
    "        where artinfo.groupid=groupinfo.groupid);\n"
    "\000"
    "get_deleted_groupid\000"
    "select groupid from groupinfo\n"
    "  where deleted>0\n"
    "  order by deleted\n"
    "  limit 1;\n"
    "\000"
    "delete_group\000"
    "delete from groupinfo\n"
    "  where groupid=?1;\n"
    "\000"
    "list_articles\000"
    "select artnum, arrived, expires, token\n"
    "  from groupinfo\n"
    "    natural join artinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1\n"
    "    and artnum>=?2\n"
    "  order by artnum;\n"
    "\000"
    "list_articles_overview\000"
    "select artnum, arrived, expires, token, overview\n"
    "  from groupinfo\n"
    "    natural join artinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1\n"
    "    and artnum>=?2\n"
    "  order by artnum;\n"
    "\000"
    "list_articles_high\000"
    "select artnum, arrived, expires, token\n"
    "  from groupinfo\n"
    "    natural join artinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1\n"
    "    and artnum>=?2\n"
    "    and artnum<=?3\n"
    "  order by artnum;\n"
    "\000"
    "list_articles_high_overview\000"
    "select artnum, arrived, expires, token, overview\n"
    "  from groupinfo\n"
    "    natural join artinfo\n"
    "  where deleted=0\n"
    "    and groupname=?1\n"
    "    and artnum>=?2\n"
    "    and artnum<=?3\n"
    "  order by artnum;\n"
    "\000"
};

#endif /* HAVE_SQLITE3 */

