_Rcommit ()- 確定現行記錄

格式

#include <recio.h>
int _Rcommit(char *cmtid);

語言層次

ILE C 延伸

安全執行緒

工作 CCSID 介面

傳送至此功能的所有字元資料都預期在工作的 CCSID 中。 此函數傳回的所有字元資料都在工作的 CCSID 中。 如需相關資訊,請參閱 瞭解 CCSID 及語言環境

說明

_Rcommit() 功能會完成呼叫它之工作的現行異動,並建立新的確定界限。 自前次確定界限以來所做的所有變更都會成為永久的。 工作中在確定控制下開啟的任何檔案或資源都會受到影響。

cmtid 參數是空值結束的 C 字串,用來識別與確定界限相關聯的變更群組。 它不能超過 4000 個位元組。

_Rcommit() 函數適用於資料庫及 DDM 檔案。

回覆值

如果作業成功,則 _Rcommit() 函數會傳回 1; 如果作業不成功,則會傳回零。 錯誤碼的值可以設為 EIOERROR (發生不可回復的 I/O 錯誤) 或 EIORECERR (發生可回復的 I/O 錯誤)。

如需錯誤碼設定,請參閱 表 1表 1

範例

#include <stdio.h>
#include <recio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void)
{
  char       buf[40];
  int        rc = 1;
  _RFILE     *purf;
  _RFILE     *dailyf;
 
  /* Open purchase display file and daily transaction file          */
  if ( ( purf = _Ropen ( "MYLIB/T1677RD3", "ar+,indicators=y" )) == NULL )
  {
      printf ( "Display file did not open.\n" );
      exit ( 1 );
  }
 
  if ( ( dailyf = _Ropen ( "MYLIB/T1677RDA", "wr,commit=y") ) == NULL )
  {
      printf ( "Daily transaction file did not open.\n" );
      exit ( 2 );
  }
 
  /* Select purchase record format */
  _Rformat ( purf, "PURCHASE" );
 
  /* Invite user to enter a purchase transaction.                   */
  /* The _Rwrite function writes the purchase display.              */
  _Rwrite ( purf, "", 0 );
  _Rreadn ( purf, buf, sizeof(buf), __DFT );
 
  /* Update daily transaction file                                  */
  rc = (( _Rwrite ( dailyf, buf, sizeof(buf) ))->num_bytes );
 
  /* If the databases were updated, then commit the transaction.    */
  /* Otherwise, rollback the transaction and indicate to the        */
  /* user that an error has occurred and end the application.       */
  if ( rc )
    {
        _Rcommit ( "Transaction complete" );
    }
  else
    {
        _Rrollbck ( );
        _Rformat ( purf, "ERROR" );
    }
 
  _Rclose ( purf );
  _Rclose ( dailyf );
}

相關資訊