39 if (!sql_foreign_keys.
Execute())
51 "CREATE TABLE tags (name TEXT, hash TEXT, revision INTEGER, "
52 " timestamp INTEGER, channel INTEGER, description TEXT, size INTEGER, "
53 " branch TEXT, CONSTRAINT pk_tags PRIMARY KEY (name), "
54 " FOREIGN KEY (branch) REFERENCES branches (branch));").
Execute();
61 "CREATE TABLE recycle_bin (hash TEXT, flags INTEGER, "
62 " CONSTRAINT pk_hash PRIMARY KEY (hash))").
Execute();
70 "CREATE TABLE branches (branch TEXT, parent TEXT, initial_revision INTEGER,"
71 " CONSTRAINT pk_branch PRIMARY KEY (branch), "
72 " FOREIGN KEY (parent) REFERENCES branches (branch), "
73 " CHECK ((branch <> '') OR (parent IS NULL)), "
74 " CHECK ((branch = '') OR (parent IS NOT NULL)));");
75 bool retval = sql_create.
Execute();
80 "INSERT INTO branches (branch, parent, initial_revision) "
81 "VALUES ('', NULL, 0);");
109 if (!sql_foreign_keys.
Execute())
116 "%.2f (Rev: %d) to %.2f (Rev: %d)",
170 "ALTER TABLE tags ADD branch TEXT REFERENCES branches (branch);");
196 #define DB_FIELDS_V1R0 "name, hash, revision, timestamp, channel, " \
198 #define DB_FIELDS_V1R1 "name, hash, revision, timestamp, channel, " \
199 "description, size, ''"
200 #define DB_FIELDS_V1R3 "name, hash, revision, timestamp, channel, " \
201 "description, size, branch"
202 #define DB_PLACEHOLDERS ":name, :hash, :revision, :timestamp, :channel, " \
203 ":description, :size, :branch"
204 #define ROLLBACK_COND "(revision > :target_rev OR " \
205 " name = :target_name) " \
208 #define MAKE_STATEMENT(STMT_TMPL, REV) \
209 static const std::string REV = \
212 ReplaceAll(STMT_TMPL, \
213 "@DB_FIELDS@", DB_FIELDS_ ## REV), \
214 "@DB_PLACEHOLDERS@", DB_PLACEHOLDERS), \
215 "@ROLLBACK_COND@", ROLLBACK_COND)
217 #define MAKE_STATEMENTS(STMT_TMPL) \
218 MAKE_STATEMENT(STMT_TMPL, V1R0); \
219 MAKE_STATEMENT(STMT_TMPL, V1R1); \
220 MAKE_STATEMENT(STMT_TMPL, V1R3)
222 #define DEFERRED_INIT(DB, REV) \
223 DeferredInit((DB)->sqlite_db(), (REV).c_str())
225 #define DEFERRED_INITS(DB) \
226 if ((DB)->IsEqualSchema((DB)->schema_version(), 1.0f) && \
227 (DB)->schema_revision() == 0) { \
228 DEFERRED_INIT((DB), V1R0); \
229 } else if ((DB)->schema_revision() < 3) { \
230 DEFERRED_INIT((DB), V1R1); \
232 DEFERRED_INIT((DB), V1R3); \
236 MAKE_STATEMENTS(
"INSERT INTO tags (@DB_FIELDS@) VALUES (@DB_PLACEHOLDERS@);");
292 "WHERE (branch = '') AND (timestamp <= :timestamp) "
293 "ORDER BY revision DESC LIMIT 1;");
309 "WHERE (branch = :branch) "
310 "ORDER BY revision DESC LIMIT 1;");
329 return static_cast<uint64_t
>(count);
338 "SELECT @DB_FIELDS@ FROM tags ORDER BY timestamp DESC, revision DESC;");
348 "ORDER BY timestamp, revision ASC");
371 "WHERE @ROLLBACK_COND@ "
372 "ORDER BY revision DESC;");
385 "SELECT branch, parent, initial_revision FROM branches;");
403 "INSERT INTO branches (branch, parent, initial_revision) "
404 "VALUES (:branch, :parent, :initial_revision);");
bool BindTimestamp(const time_t timestamp)
static const float kLatestSchema
bool BindTextTransient(const int index, const std::string &value)
unsigned RetrieveCount() const
SqlFindTag(const HistoryDatabase *database)
bool CreateEmptyDatabase()
bool BindText(const int index, const std::string &value)
bool CheckSchema(const HistoryDatabase *database) const
static const float kLatestSupportedSchema
bool CheckSchemaCompatibility()
bool CreateRecycleBinTable()
std::string ToString(const bool with_suffix=false) const
SqlFindTagByDate(const HistoryDatabase *database)
const history::History * history() const
shash::Any RetrieveHash() const
assert((mem||(size==0))&&"Out Of Memory")
SqlInsertTag(const HistoryDatabase *database)
bool UpgradeSchemaRevision_10_1()
float schema_version() const
SqlCountTags(const HistoryDatabase *database)
SqlListRollbackTags(const HistoryDatabase *database)
void set_schema_revision(const unsigned rev)
unsigned schema_revision() const
SqlFindBranchHead(const HistoryDatabase *database)
bool InsertInitialValues(const std::string &repository_name)
bool BindBranchName(const std::string &branch_name)
void DeferredInit(const sqlite3 *database, const char *statement)
SqlRecycleBinFlush(const HistoryDatabase *database)
static const float kSchemaEpsilon
static const unsigned int kFlagCatalog
bool BindName(const std::string &name)
const char kSuffixCatalog
bool BindTag(const History::Tag &tag)
SqlListTags(const HistoryDatabase *database)
sqlite3_int64 RetrieveInt64(const int idx_column) const
#define MAKE_STATEMENTS(STMT_TMPL)
sqlite3 * sqlite_db() const
bool BindBranch(const History::Branch &branch)
bool BindInt64(const int index, const sqlite3_int64 value)
bool SetProperty(const std::string &key, const T value)
SqlInsertBranch(const HistoryDatabase *database)
static const unsigned kLatestSchemaRevision
shash::Any RetrieveHash()
bool LiveSchemaUpgradeIfNecessary()
bool IsEqualSchema(const float value, const float compare) const
SqlGetHashes(const HistoryDatabase *database)
std::string RetrieveString(const int idx_column) const
static const std::string kFqrnKey
bool BindName(const std::string &name)
int RetrieveType(const int idx_column) const
bool UpgradeSchemaRevision_10_2()
uint64_t initial_revision
Any MkFromHexPtr(const HexPtr hex, const char suffix)
SqlRemoveTag(const HistoryDatabase *database)
bool ContainsRecycleBin() const
#define DEFERRED_INITS(DB)
bool CreateBranchesTable()
bool StoreSchemaRevision()
History::Branch RetrieveBranch() const
SqlRecycleBinList(const HistoryDatabase *database)
SqlRollbackTag(const HistoryDatabase *database)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
bool UpgradeSchemaRevision_10_3()
SqlListBranches(const HistoryDatabase *database)