22 #include "ns3/abort.h"
24 #include "ns3/nstime.h"
32 int rc = sqlite3_open (name.c_str (), &
m_db);
40 rc = sqlite3_close_v2 (
m_db);
48 SpinExec (
"PRAGMA journal_mode = MEMORY");
101 return sqlite3_column_int (stmt, pos);
109 return static_cast<uint32_t
> (sqlite3_column_int (stmt, pos));
117 return sqlite3_column_double (stmt, pos);
122 SQLiteOutput::Bind ([[maybe_unused]] sqlite3_stmt *stmt, [[maybe_unused]]
int pos, [[maybe_unused]]
const T &value)
const
133 if (sqlite3_bind_double (stmt, pos, value.GetSeconds ()) == SQLITE_OK)
145 if (sqlite3_bind_double (stmt, pos, value) == SQLITE_OK)
157 if (sqlite3_bind_int (stmt, pos,
static_cast<int> (value)) == SQLITE_OK)
169 if (sqlite3_bind_int64 (stmt, pos, value) == SQLITE_OK)
181 if (sqlite3_bind_int64 (stmt, pos, value) == SQLITE_OK)
193 if (sqlite3_bind_int (stmt, pos,
static_cast<int> (value)) == SQLITE_OK)
205 if (sqlite3_bind_int (stmt, pos,
static_cast<int> (value)) == SQLITE_OK)
217 if (sqlite3_bind_int (stmt, pos, value) == SQLITE_OK)
229 if (sqlite3_bind_text (stmt, pos, value.c_str (), -1, SQLITE_STATIC) == SQLITE_OK)
242 std::unique_lock lock {
m_mutex};
244 rc = sqlite3_prepare_v2 (db,
cmd.c_str (),
245 static_cast<int> (
cmd.size ()),
264 rc = sqlite3_prepare_v2 (db,
cmd.c_str (),
265 static_cast<int> (
cmd.size ()),
268 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
278 rc = sqlite3_step (stmt);
280 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
291 rc = sqlite3_finalize (stmt);
293 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
304 rc = sqlite3_reset (stmt);
306 while (rc == SQLITE_BUSY || rc == SQLITE_LOCKED);
321 if (rc != SQLITE_OK && rc != SQLITE_DONE)
329 std::cerr << sqlite3_errmsg (db) << std::endl;
381 int rc = SQLITE_ERROR;
383 std::unique_lock lock {
m_mutex};
403 int rc = SQLITE_ERROR;
405 std::unique_lock lock {
m_mutex};
sqlite3 * m_db
Database pointer.
bool SpinExec(const std::string &cmd) const
Execute a command until the return value is OK or an ERROR.
static bool CheckError(sqlite3 *db, int rc, const std::string &cmd, bool hardExit)
Check any error in the db.
~SQLiteOutput()
Destructor.
static int SpinStep(sqlite3_stmt *stmt)
Execute a step operation on a statement until the result is ok or an error.
void SetJournalInMemory()
Instruct SQLite to store the journal in memory.
T RetrieveColumn(sqlite3_stmt *stmt, int pos) const
Retrieve a value from an executed statement.
bool Bind(sqlite3_stmt *stmt, int pos, const T &value) const
Bind a value to a sqlite statement.
static int SpinReset(sqlite3_stmt *stmt)
Reset a statement until the result is ok or an error.
static int SpinFinalize(sqlite3_stmt *stmt)
Finalize a statement until the result is ok or an error.
bool WaitExec(const std::string &cmd) const
Execute a command, waiting on a mutex.
static void Error(sqlite3 *db, const std::string &cmd)
Fail, printing an error message from sqlite.
bool SpinPrepare(sqlite3_stmt **stmt, const std::string &cmd) const
Prepare a statement.
SQLiteOutput(const std::string &name)
SQLiteOutput constructor.
bool WaitPrepare(sqlite3_stmt **stmt, const std::string &cmd) const
Prepare a statement, waiting on a mutex.
Simulation virtual time values and global simulation resolution.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG(msg)
Unconditional abnormal program termination with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.