#include <stdio.h>
#include <string.h>
#include "libshun.h"
/* ダイレクトアクセスを使って更新します */
int main()
{
/* ハンドル変数群 */
SHUNHCON connectionHandle;
SHUNHSTMT statementHandle;
/* 作業用変数群 */
int status;
int i;
/* 入力パラメータ群 */
char *hostName;
int portNo;
char *ShunFileName;
char *returnForm;
char *keyName;
SHUNKEY keyInfo[1];
SHUNDATA dataInfo[1];
/* エラー用変数群 */
SHUNHANDLE errorHandle;
int errorLevel;
char *errorMessage;
/* 変数の初期化 */
connectionHandle = NULL;
statementHandle = NULL;
/* コネクションハンドルの割当て */
status = ShunAllocHandle( NULL, &connectionHandle );
if ( status != SHUN_SUCCESS ) {
errorHandle = connectionHandle;
goto ErrorEnd;
}
/* ホスト名・ポート番号、Shunsakuファイル名を指定してコネクションを確立 */
hostName = "DirSvr1";
portNo = 33101;
ShunFileName = "shunsakuFile1";
status = ShunConnect( connectionHandle, hostName, portNo, ShunFileName );
if ( status != SHUN_SUCCESS ) {
errorHandle = (SHUNHANDLE)connectionHandle;
goto ErrorEnd;
}
/* データ操作ハンドルの割当て */
status = ShunAllocHandle( connectionHandle, &statementHandle );
if ( status != SHUN_SUCCESS ) {
errorHandle = (SHUNHANDLE)connectionHandle;
goto ErrorEnd;
}
/* ダイレクトアクセスキーの設定 */
keyName = "key";
keyInfo[0].Key = "0001";
keyInfo[0].Key_Len = strlen( keyInfo[0].Key );
/* 更新データ */
dataInfo[0].Data =
"<course>"
" <id>0001</id>"
" <name>Business negotiation</name>"
" <instructor>"
" <first-name>Max</first-name>"
" <last-name>cameron</last-name>"
" </instructor>"
" <capacity>40</capacity>"
" <current-auditors>31</current-auditors>"
"</course>";
dataInfo[0].Data_Len = strlen( dataInfo[0].Data );
/* API呼出し ダイレクト更新 */
status = ShunUpdateKey( statementHandle,
keyName,
SHUN_KEY_COMPLETE_MATCH,
1,
keyInfo,
dataInfo );
if ( status != SHUN_SUCCESS ) {
errorHandle = (SHUNHANDLE)statementHandle;
goto ErrorEnd;
}
printf( "更新終了\n" );
/* データ操作ハンドルの解放 */
status = ShunFreeHandle( statementHandle );
if ( status != SHUN_SUCCESS ) {
errorHandle = (SHUNHANDLE)connectionHandle;
goto ErrorEnd;
}
/* コネクションの切断 */
status = ShunDisconnect( connectionHandle );
if ( status != SHUN_SUCCESS ) {
errorHandle = (SHUNHANDLE)connectionHandle;
goto ErrorEnd;
}
/* コネクションハンドルの解放 */
status = ShunFreeHandle( connectionHandle );
if ( status != SHUN_SUCCESS ) {
errorHandle = NULL;
goto ErrorEnd;
}
return 0;
ErrorEnd: /* エラーが発生した際のエラー処理 */
/* エラー情報の取得 */
status = ShunGetErrorMessage(errorHandle,
&errorLevel, &errorMessage);
if ( status == SHUN_SUCCESS ) {
switch ( errorLevel ) {
case SHUN_ERROR_CONNECTION:
printf("エラーレベル = SHUN_ERROR_CONNECTION\n");
break;
case SHUN_ERROR_DATA:
printf("エラーレベル = SHUN_ERROR_DATA\n");
break;
}
printf("エラーメッセージ = %s\n", errorMessage);
}
else {
printf("エラーメッセージ取得エラー : %d\n", status);
}
/* データ操作ハンドルの解放 */
if ( statementHandle != NULL ) {
status = ShunFreeHandle( statementHandle );
if ( status != SHUN_SUCCESS ) {
printf("データ操作ハンドル解放エラー : %d\n", status);
}
}
/* コネクションの切断 */
if ( connectionHandle != NULL) {
status = ShunDisconnect( connectionHandle );
if ( status != SHUN_SUCCESS ) {
printf("コネクション切断エラー : %d\n", status);
}
}
/* コネクションハンドルの解放 */
if ( connectionHandle != NULL) {
status = ShunFreeHandle( connectionHandle );
if ( status != SHUN_SUCCESS ) {
printf("コネクションハンドル解放エラー : %d\n", status);
}
}
return 1;
} |