-
-#ifdef MAPDB_SQLITE
- if(SQLITE_OK != (sqlite3_open(_curr_repo->db_filename,
- &(_curr_repo->db)))
- /* Open worked. Now create tables, failing if they already exist.*/
- || (sqlite3_exec(_curr_repo->db,
- "create table maps ("
- "zoom integer, "
- "tilex integer, "
- "tiley integer, "
- "pixbuf blob, "
- "primary key (zoom, tilex, tiley))"
- ";"
- "create table dups ("
- "hash integer primary key, "
- "uses integer, "
- "pixbuf blob)",
- NULL, NULL, NULL), FALSE) /* !! Comma operator !! */
- /* Prepare select map statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "select pixbuf from maps "
- "where zoom = ? and tilex = ? and tiley = ?",
- -1, &_curr_repo->stmt_map_select, NULL)
- /* Prepare exists map statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "select count(*) from maps "
- "where zoom = ? and tilex = ? and tiley = ?",
- -1, &_curr_repo->stmt_map_exists, NULL)
- /* Prepare insert map statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "insert into maps (pixbuf, zoom, tilex, tiley)"
- " values (?, ?, ?, ?)",
- -1, &_curr_repo->stmt_map_insert, NULL)
- /* Prepare update map statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "update maps set pixbuf = ? "
- "where zoom = ? and tilex = ? and tiley = ?",
- -1, &_curr_repo->stmt_map_update, NULL)
- /* Prepare delete map statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "delete from maps "
- "where zoom = ? and tilex = ? and tiley = ?",
- -1, &_curr_repo->stmt_map_delete, NULL)
-
- /* Prepare select-by-map dup statement. */
- /* Prepare select-by-hash dup statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "select pixbuf from dups "
- "where hash = ?",
- -1, &_curr_repo->stmt_dup_select, NULL)
- /* Prepare exists map statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "select count(*) from dups "
- "where hash = ?",
- -1, &_curr_repo->stmt_dup_exists, NULL)
- /* Prepare insert dup statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "insert into dups (hash, pixbuf, uses) "
- "values (?, ?, 1)",
- -1, &_curr_repo->stmt_dup_insert, NULL)
- /* Prepare increment dup statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "update dups "
- "set uses = uses + 1 "
- "where hash = ?",
- -1, &_curr_repo->stmt_dup_increm, NULL)
- /* Prepare decrement dup statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "update dups "
- "set uses = uses - 1 "
- "where hash = ? ",
- -1, &_curr_repo->stmt_dup_decrem, NULL)
- /* Prepare delete dup statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "delete from dups "
- "where hash = ? and uses <= 0",
- -1, &_curr_repo->stmt_dup_delete, NULL)
-
- /* Prepare begin-transaction statement. */
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "begin transaction",
- -1, &_curr_repo->stmt_trans_begin, NULL)
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "commit transaction",
- -1, &_curr_repo->stmt_trans_commit, NULL)
- || SQLITE_OK != sqlite3_prepare(_curr_repo->db,
- "rollback transaction", -1,
- &_curr_repo->stmt_trans_rollback, NULL))