28 "CREATE TABLE refs (hash TEXT, type INTEGER, "
30 "CONSTRAINT pk_refs PRIMARY KEY (hash));")
55 #define DB_FIELDS_V1R0 "hash, type, timestamp"
56 #define DB_PLACEHOLDERS ":hash, :type, :timestamp"
58 #define MAKE_STATEMENT(STMT_TMPL, REV) \
59 static const std::string REV = ReplaceAll( \
60 ReplaceAll(STMT_TMPL, "@DB_FIELDS@", DB_FIELDS_##REV), \
61 "@DB_PLACEHOLDERS@", DB_PLACEHOLDERS)
63 #define MAKE_STATEMENTS(STMT_TMPL) MAKE_STATEMENT(STMT_TMPL, V1R0)
65 #define DEFERRED_INIT(DB, REV) DeferredInit((DB)->sqlite_db(), (REV).c_str())
67 #define DEFERRED_INITS(DB) DEFERRED_INIT((DB), V1R0)
81 assert(
false &&
"unknown reference type");
91 "VALUES (@DB_PLACEHOLDERS@);");
98 &&
BindInt64(2, static_cast<uint64_t>(type))
99 &&
BindInt64(3, static_cast<uint64_t>(time(NULL)));
120 "WHERE type = :type AND "
121 "timestamp < :timestamp "
122 "ORDER BY timestamp DESC;");
126 return BindInt64(1, static_cast<uint64_t>(type));
130 int64_t sqlite_timestamp =
static_cast<uint64_t
>(timestamp);
131 if (sqlite_timestamp < 0) {
132 sqlite_timestamp = std::numeric_limits<int64_t>::max();
149 "AND type = :type;");
155 &&
BindInt64(2, static_cast<uint64_t>(type));
164 "WHERE type = :type "
165 " AND hash = :hash");
170 return BindInt64(1, static_cast<uint64_t>(type))
176 assert(count == 0 || count == 1);
186 "WHERE type = :type "
187 " AND hash = :hash");
192 return BindInt64(1, static_cast<uint64_t>(type))
bool CheckSchemaCompatibility()
bool BindOlderThan(const uint64_t timestamp)
bool BindTextTransient(const int index, const std::string &value)
uint64_t RetrieveTimestamp()
static const std::string kFqrnKey
shash::Any RetrieveHash() const
SqlListReferences(const ReflogDatabase *database)
SqlGetTimestamp(const ReflogDatabase *database)
const char kSuffixCertificate
std::string ToString(const bool with_suffix=false) const
bool BindType(const ReferenceType type)
bool BindReference(const shash::Any &reference_hash, const ReferenceType type)
assert((mem||(size==0))&&"Out Of Memory")
float schema_version() const
#define MAKE_STATEMENTS(STMT_TMPL)
bool BindReference(const shash::Any &reference_hash, const ReferenceType type)
unsigned schema_revision() const
bool LiveSchemaUpgradeIfNecessary()
static const float kLatestSupportedSchema
void DeferredInit(const sqlite3 *database, const char *statement)
static const float kLatestSchema
SqlContainsReference(const ReflogDatabase *database)
bool BindReference(const shash::Any &reference_hash, const ReferenceType type)
const char kSuffixCatalog
SqlCountReferences(const ReflogDatabase *database)
sqlite3_int64 RetrieveInt64(const int idx_column) const
const char kSuffixMetainfo
sqlite3 * sqlite_db() const
bool BindInt64(const int index, const sqlite3_int64 value)
const char kSuffixHistory
bool SetProperty(const std::string &key, const T value)
SqlRemoveReference(const ReflogDatabase *database)
bool InsertInitialValues(const std::string &repo_name)
static const unsigned kLatestSchemaRevision
bool IsEqualSchema(const float value, const float compare) const
#define DEFERRED_INITS(DB)
std::string RetrieveString(const int idx_column) const
bool CreateEmptyDatabase()
Any MkFromHexPtr(const HexPtr hex, const char suffix)
bool BindReference(const shash::Any &reference_hash, const ReferenceType type)
SqlInsertReference(const ReflogDatabase *database)
static shash::Suffix ToSuffix(const ReferenceType type)