aboutsummaryrefslogtreecommitdiff
GNU Guix consists of Scheme code that implements the deployment model
of the Nix package management tool.  In fact, it currently talks to a
build daemon whose code comes from Nix (see the manual for details.)

Nix was initially written by Eelco Dolstra; other people have been
contributing to it.  See `nix/AUTHORS' for details.

The list of GNU Guix contributors is now generated from the output of
'git log' and written to this file, as can be seen in release tarballs.
sec = (random() % 100) * 1000 * 1000; /* <= 0.1s */ nanosleep(&t, 0); #else sleep(1); #endif throw SQLiteBusy(format("%1%: %2%") % f.str() % sqlite3_errmsg(db)); } else throw SQLiteError(format("%1%: %2%") % f.str() % sqlite3_errmsg(db)); } SQLite::~SQLite() { try { if (db && sqlite3_close(db) != SQLITE_OK) throwSQLiteError(db, "closing database"); } catch (...) { ignoreException(); } } void SQLiteStmt::create(sqlite3 * db, const string & s) { checkInterrupt(); assert(!stmt); if (sqlite3_prepare_v2(db, s.c_str(), -1, &stmt, 0) != SQLITE_OK) throwSQLiteError(db, "creating statement"); this->db = db; } SQLiteStmt::~SQLiteStmt() { try { if (stmt && sqlite3_finalize(stmt) != SQLITE_OK) throwSQLiteError(db, "finalizing statement"); } catch (...) { ignoreException(); } } SQLiteStmt::Use::Use(SQLiteStmt & stmt) : stmt(stmt) { assert(stmt.stmt); /* Note: sqlite3_reset() returns the error code for the most recent call to sqlite3_step(). So ignore it. */ sqlite3_reset(stmt); } SQLiteStmt::Use::~Use() { sqlite3_reset(stmt); } SQLiteStmt::Use & SQLiteStmt::Use::operator () (const std::string & value, bool notNull) { if (notNull) { if (sqlite3_bind_text(stmt, curArg++, value.c_str(), -1, SQLITE_TRANSIENT) != SQLITE_OK) throwSQLiteError(stmt.db, "binding argument"); } else bind(); return *this; } SQLiteStmt::Use & SQLiteStmt::Use::operator () (int64_t value, bool notNull) { if (notNull) { if (sqlite3_bind_int64(stmt, curArg++, value) != SQLITE_OK) throwSQLiteError(stmt.db, "binding argument"); } else bind(); return *this; } SQLiteStmt::Use & SQLiteStmt::Use::bind() { if (sqlite3_bind_null(stmt, curArg++) != SQLITE_OK) throwSQLiteError(stmt.db, "binding argument"); return *this; } int SQLiteStmt::Use::step() { return sqlite3_step(stmt); } void SQLiteStmt::Use::exec() { int r = step(); assert(r != SQLITE_ROW); if (r != SQLITE_DONE) throwSQLiteError(stmt.db, "executing SQLite statement"); } bool SQLiteStmt::Use::next() { int r = step(); if (r != SQLITE_DONE && r != SQLITE_ROW) throwSQLiteError(stmt.db, "executing SQLite query"); return r == SQLITE_ROW; } std::string SQLiteStmt::Use::getStr(int col) { auto s = (const char *) sqlite3_column_text(stmt, col); assert(s); return s; } int64_t SQLiteStmt::Use::getInt(int col) { // FIXME: detect nulls? return sqlite3_column_int64(stmt, col); } SQLiteTxn::SQLiteTxn(sqlite3 * db) { this->db = db; if (sqlite3_exec(db, "begin;", 0, 0, 0) != SQLITE_OK) throwSQLiteError(db, "starting transaction"); active = true; } void SQLiteTxn::commit() { if (sqlite3_exec(db, "commit;", 0, 0, 0) != SQLITE_OK) throwSQLiteError(db, "committing transaction"); active = false; } SQLiteTxn::~SQLiteTxn() { try { if (active && sqlite3_exec(db, "rollback;", 0, 0, 0) != SQLITE_OK) throwSQLiteError(db, "aborting transaction"); } catch (...) { ignoreException(); } } }