1/* rep-cache-db.sql -- schema for use in rep-caching 2 * This is intended for use with SQLite 3 3 * 4 * ==================================================================== 5 * Licensed to the Apache Software Foundation (ASF) under one 6 * or more contributor license agreements. See the NOTICE file 7 * distributed with this work for additional information 8 * regarding copyright ownership. The ASF licenses this file 9 * to you under the Apache License, Version 2.0 (the 10 * "License"); you may not use this file except in compliance 11 * with the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, 16 * software distributed under the License is distributed on an 17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18 * KIND, either express or implied. See the License for the 19 * specific language governing permissions and limitations 20 * under the License. 21 * ==================================================================== 22 */ 23 24-- STMT_CREATE_SCHEMA 25PRAGMA PAGE_SIZE = 4096; 26 27/* A table mapping representation hashes to locations in a rev file. */ 28CREATE TABLE rep_cache ( 29 hash TEXT NOT NULL PRIMARY KEY, 30 revision INTEGER NOT NULL, 31 offset INTEGER NOT NULL, 32 size INTEGER NOT NULL, 33 expanded_size INTEGER NOT NULL 34 ); 35 36PRAGMA USER_VERSION = 1; 37 38 39-- STMT_GET_REP 40SELECT revision, offset, size, expanded_size 41FROM rep_cache 42WHERE hash = ?1 43 44-- STMT_SET_REP 45INSERT OR FAIL INTO rep_cache (hash, revision, offset, size, expanded_size) 46VALUES (?1, ?2, ?3, ?4, ?5) 47 48-- STMT_GET_REPS_FOR_RANGE 49SELECT hash, revision, offset, size, expanded_size 50FROM rep_cache 51WHERE revision >= ?1 AND revision <= ?2 52 53-- STMT_GET_MAX_REV 54SELECT MAX(revision) 55FROM rep_cache 56 57-- STMT_DEL_REPS_YOUNGER_THAN_REV 58DELETE FROM rep_cache 59WHERE revision > ?1 60 61/* An INSERT takes an SQLite reserved lock that prevents other writes 62 but doesn't block reads. The incomplete transaction means that no 63 permanent change is made to the database and the transaction is 64 removed when the database is closed. */ 65-- STMT_LOCK_REP 66BEGIN TRANSACTION; 67INSERT INTO rep_cache VALUES ('dummy', 0, 0, 0, 0) 68 69-- STMT_UNLOCK_REP 70ROLLBACK TRANSACTION; 71