Ejemplo n.º 1
0
    void Transaction::Begin()
    {
      if (isOpen_) 
      {
        throw OrthancSQLiteException("SQLite: Beginning a transaction twice!");
      }

      isOpen_ = connection_.BeginTransaction();
      if (!isOpen_)
      {
        throw OrthancSQLiteException("SQLite: Unable to create a transaction");
      }
    }
Ejemplo n.º 2
0
 void Statement::CheckOk(int err) const 
 {
   if (err == SQLITE_RANGE)
   {
     // Binding to a non-existent variable is evidence of a serious error.
     throw OrthancSQLiteException("Bind value out of range");
   }
   else if (err != SQLITE_OK)
   {
     char buffer[128];
     snprintf(buffer, sizeof(buffer) - 1, "SQLite error code %d", err);
     throw OrthancSQLiteException(buffer);
   }
 }
Ejemplo n.º 3
0
    void Transaction::Commit() 
    {
      if (!isOpen_) 
      {
        throw OrthancSQLiteException("SQLite: Attempting to roll back a nonexistent transaction. "
                                     "Did you remember to call Begin()?");
      }

      isOpen_ = false;

      if (!connection_.CommitTransaction())
      {
        throw OrthancSQLiteException("SQLite: Failure when committing the transaction");
      }
    }
Ejemplo n.º 4
0
 void FunctionContext::CheckIndex(unsigned int index) const
 {
   if (index >= argc_)
   {
     throw OrthancSQLiteException(ErrorCode_ParameterOutOfRange);
   }
 }
Ejemplo n.º 5
0
    void Statement::CheckOk(int err, ErrorCode code) const 
    {
      if (err == SQLITE_RANGE)
      {
        // Binding to a non-existent variable is evidence of a serious error.
        throw OrthancSQLiteException(ErrorCode_SQLiteBindOutOfRange);
      }
      else if (err != SQLITE_OK)
      {
#if ORTHANC_SQLITE_STANDALONE != 1
        char buffer[128];
        snprintf(buffer, sizeof(buffer) - 1, "SQLite error code %d", err);
        LOG(ERROR) << buffer;
#endif

        throw OrthancSQLiteException(code);
      }
    }
Ejemplo n.º 6
0
    int Statement::CheckError(int err) const
    {
      bool succeeded = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE);
      if (!succeeded)
      {
        char buffer[128];
        snprintf(buffer, sizeof(buffer) - 1, "SQLite error code %d", err);
        throw OrthancSQLiteException(buffer);
      }

      return err;
    }
Ejemplo n.º 7
0
    void Transaction::Rollback() 
    {
      if (!isOpen_) 
      {
        throw OrthancSQLiteException("SQLite: Attempting to roll back a nonexistent transaction. "
                                     "Did you remember to call Begin()?");
      }

      isOpen_ = false;

      connection_.RollbackTransaction();
    }
Ejemplo n.º 8
0
    StatementReference::StatementReference(sqlite3* database,
                                           const char* sql)
    {
      if (database == NULL || sql == NULL)
      {
        throw OrthancSQLiteException(ErrorCode_ParameterOutOfRange);
      }

      root_ = NULL;
      refCount_ = 0;

      int error = sqlite3_prepare_v2(database, sql, -1, &statement_, NULL);
      if (error != SQLITE_OK)
      {
#if ORTHANC_SQLITE_STANDALONE != 1
        LOG(ERROR) << "SQLite: " << sqlite3_errmsg(database);
#endif

        throw OrthancSQLiteException(ErrorCode_SQLitePrepareStatement);
      }

      assert(IsRoot());
    }
Ejemplo n.º 9
0
    int Statement::CheckError(int err, ErrorCode code) const
    {
      bool succeeded = (err == SQLITE_OK || err == SQLITE_ROW || err == SQLITE_DONE);
      if (!succeeded)
      {
#if ORTHANC_SQLITE_STANDALONE != 1
        char buffer[128];
        snprintf(buffer, sizeof(buffer) - 1, "SQLite error code %d", err);
        LOG(ERROR) << buffer;
#endif

        throw OrthancSQLiteException(code);
      }

      return err;
    }