// *****************************************************************************
// *                                                                           *
// * Function: PrivMgrMDTable::update                                          *
// *                                                                           *
// *    This method updates rows in table based on a SET clause.               *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <setClause>                    const std::string &              In       *
// *    is the SET clause (including the keyword SET).                         *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// * Returns: PrivStatus                                                       *
// *                                                                           *
// *  STATUS_GOOD: Statement executed successfully.                            *
// * STATUS_ERROR: Execution failed. A CLI error is put into the diags area.   *
// *                                                                           *
// *****************************************************************************
PrivStatus PrivMgrMDTable::update(const std::string &setClause)
{

std::string updateStmt ("UPDATE ");

   updateStmt += tableName_;
   updateStmt += " ";
   updateStmt += setClause;
   
//TODO: support a WHERE clause?
  
   return CLIImmediate(updateStmt);
  
}
// *****************************************************************************
// *                                                                           *
// * Function: PrivMgrMDTable::updateWhere                                     *
// *                                                                           *
// *    This method updates rows in table based on a SET an d WHERE clause.    *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// *  Parameters:                                                              *
// *                                                                           *
// *  <setClause>                    const std::string &              In       *
// *    is the SET clause (including the keyword SET).                         *
// *                                                                           *
// *  <whereClause>                  const std::string &              In       *
// *    is the WHERE clause (including the keyword WHERE).                     *
// *                                                                           *
// *****************************************************************************
// *                                                                           *
// * Returns: PrivStatus                                                       *
// *                                                                           *
// * STATUS_ERROR: Execution failed. A CLI error is put into the diags area.   *
// * STATUS_GOOD: Statement executed successfully.                             *
// * STATUS_NOTFOUND: No row found that match WHERE clause.                    *
// * STATUS_WARNING: Statement executed to completion but with a warning.  See *
// *                 the CLI diags area.                                       *
// *                                                                           *
// *****************************************************************************
PrivStatus PrivMgrMDTable::updateWhere(
   const std::string & setClause,
   const std::string & whereClause)
   
{

std::string updateStmt("UPDATE ");

   updateStmt += tableName_;
   updateStmt += " ";
   updateStmt += setClause;
   updateStmt += " ";
   updateStmt += whereClause;

// set pointer in diags area
int32_t diagsMark = pDiags_->mark();

ExeCliInterface cliInterface(STMTHEAP,NULL,NULL, 
                             CmpCommon::context()->sqlSession()->getParentQid());
                             
int32_t cliRC = cliInterface.executeImmediate(updateStmt.c_str());

   if (cliRC < 0)
   {
      cliInterface.retrieveSQLDiagnostics(pDiags_);
      return STATUS_ERROR;
   }

   if (cliRC == 100) // did not find any rows
   {
      pDiags_->rewind(diagsMark);
      return STATUS_NOTFOUND;
   }

   if (cliRC > 0)
      return STATUS_WARNING;

   return STATUS_GOOD;
   
}
Ejemplo n.º 3
0
Status MobileRecordStore::updateRecord(OperationContext* opCtx,
                                       const RecordId& recId,
                                       const char* data,
                                       int len) {
    MobileSession* session = MobileRecoveryUnit::get(opCtx)->getSession(opCtx, false);

    SqliteStatement dataSizeStmt(
        *session, "SELECT IFNULL(LENGTH(data), 0) FROM \"", _ident, "\" WHERE rec_id = ?;");
    dataSizeStmt.bindInt(0, recId.repr());
    dataSizeStmt.step(SQLITE_ROW);

    int64_t dataSizeBefore = dataSizeStmt.getColInt(0);
    _changeDataSize(opCtx, -dataSizeBefore + len);

    SqliteStatement updateStmt(
        *session, "UPDATE \"", _ident, "\" SET data = ? ", "WHERE rec_id = ?;");
    updateStmt.bindBlob(0, data, len);
    updateStmt.bindInt(1, recId.repr());
    updateStmt.step(SQLITE_DONE);

    return Status::OK();
}