#pragma once #include #include #include "types.hh" class sqlite3; class sqlite3_stmt; namespace nix { /* RAII wrapper to close a SQLite database automatically. */ struct SQLite { sqlite3 * db; SQLite() { db = 0; } ~SQLite(); operator sqlite3 * () { return db; } }; /* RAII wrapper to create and destroy SQLite prepared statements. */ struct SQLiteStmt { sqlite3 * db = 0; sqlite3_stmt * stmt = 0; SQLiteStmt() { } void create(sqlite3 * db, const std::string & s); ~SQLiteStmt(); operator sqlite3_stmt * () { return stmt; } /* Helper for binding / executing statements. */ class Use { friend struct SQLiteStmt; private: SQLiteStmt & stmt; unsigned int curArg = 1; Use(SQLiteStmt & stmt); public: ~Use(); /* Bind the next parameter. */ Use & operator () (const std::string & value, bool notNull = true); Use & operator () (int64_t value, bool notNull = true); Use & bind(); // null int step(); /* Execute a statement that does not return rows. */ void exec(); /* For statements that return 0 or more rows. Returns true iff a row is available. */ bool next(); std::string getStr(int col); int64_t getInt(int col); }; Use use() { return Use(*this); } }; /* RAII helper that ensures transactions are aborted unless explicitly committed. */ struct SQLiteTxn { bool active = false; sqlite3 * db; SQLiteTxn(sqlite3 * db); void commit(); ~SQLiteTxn(); }; MakeError(SQLiteError, Error); MakeError(SQLiteBusy, SQLiteError); [[noreturn]] void throwSQLiteError(sqlite3 * db, const format & f); /* Convenience function for retrying a SQLite transaction when the database is busy. */ template T retrySQLite(std::function fun) { while (true) { try { return fun(); } catch (SQLiteBusy & e) { } } } } /log/?id=5686da7608ce26c4d1f9cbc71654f9e24736a498'>root/tests/cran.scm
AgeCommit message (Expand)Author
2017-05-13import: cran: Robustify cran-package?....Mathieu Othacehe
2017-03-08tests: Avoid zero-expression 'begin' form....Ludovic Courtès
2016-11-10tests: Adjust 'url-fetch' mocks to TLS changes....Ludovic Courtès
2016-04-03build: Add a Guile custom test driver using SRFI-64....Mathieu Lirzin
2016-01-20tests: Move beatify-description tests to import-tests....Ben Woodcroft
2016-01-20import: Add Bioconductor importer and updater....Ricardo Wurmus
2015-12-11import: cran: Parse DESCRIPTION instead of HTML....Ricardo Wurmus
2015-09-24tests: cran: Use cran-uri in expected output....Ricardo Wurmus
2015-08-31import: Add 'cran' importer....Ricardo Wurmus