📄 ctxact.c
字号:
}
}
if (retcode != CS_END_RESULTS)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Free the command buffer */
if (ct_cmd_drop(cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
return ((p_result == 0) ? CS_SUCCEED : CS_FAIL);
}
/*
** abort_xact()
**
** Purpose:
** Mark this transaction as aborted in the commit table so any
** subsequent call to probe_xact() for this commid will return
** 'abort'.
**
** Parameters
** conn The CS_CONNECTION used to communicate
** commid id used to identify xact to service
**
** Returns
** CS_SUCCEED or CS_FAIL
**
**
** Side Effects
** Changes commit table.
**
*/
CS_RETCODE
abort_xact(conn, commid)
CS_CONNECTION *conn;
CS_INT commid;
{
CS_INT ret;
CS_DATAFMT fmt;
CS_COMMAND *cmd;
/* Initialization */
(CS_VOID)memset((char *)&fmt, 0, sizeof(CS_DATAFMT));
/* Allocate a command handle */
if (ct_cmd_alloc(conn, &cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
if (ct_command(cmd, CS_RPC_CMD, "sp_abort_xact", CS_NULLTERM,
CS_UNUSED) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Prepare the count parameter */
strcpy(fmt.name, "@commid");
fmt.namelen = strlen(fmt.name);
fmt.datatype = CS_INT_TYPE;
fmt.maxlength = CS_SIZEOF(CS_INT);
fmt.status = CS_INPUTVALUE;
if (ct_param(cmd, &fmt, (CS_VOID *)&commid, CS_UNUSED, 0) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Send to server */
if (ct_send(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
ret = handle_results(cmd);
/* Free the command buffer */
if (ct_cmd_drop(cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
return (ret);
}
/*
** remove_xact()
**
** Purpose:
** Decrement the count of sites participating in the transaction by N.
** Delete the commit table entry entirely if the count reaches zero.
**
** Parameters
** conn The CS_CONNECTION used to communicate
** commid id used to identify xact to service
** n Number of sites to remove
**
** Returns
** CS_SUCCEED or CS_FAIL
**
**
** Side Effects
** Changes commit table.
**
*/
CS_RETCODE
remove_xact(conn, commid, n)
CS_CONNECTION *conn;
CS_INT commid;
CS_INT n;
{
CS_INT ret;
CS_DATAFMT fmt;
CS_COMMAND *cmd;
/* Initialization */
(CS_VOID)memset((char *)&fmt, 0, sizeof(CS_DATAFMT));
/* Allocate a command handle */
if (ct_cmd_alloc(conn, &cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
if (ct_command(cmd, CS_RPC_CMD, "sp_remove_xact", CS_NULLTERM,
CS_UNUSED) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Prepare the count parameter */
strcpy(fmt.name, "@commid");
fmt.namelen = strlen(fmt.name);
fmt.datatype = CS_INT_TYPE;
fmt.maxlength = CS_SIZEOF(CS_INT);
fmt.status = CS_INPUTVALUE;
if (ct_param(cmd, &fmt, (CS_VOID *)&commid, CS_UNUSED, 0) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Prepare the count parameter */
strcpy(fmt.name, "@count");
fmt.namelen = strlen(fmt.name);
fmt.datatype = CS_INT_TYPE;
fmt.maxlength = CS_SIZEOF(CS_INT);
fmt.status = CS_INPUTVALUE;
if (ct_param(cmd, &fmt, (CS_VOID *)&n, CS_UNUSED, 0) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Send to server */
if (ct_send(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Process the results/status (no rows expected) */
ret = handle_results(cmd);
/* Free the command buffer */
if (ct_cmd_drop(cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
return (ret);
}
/*
** scan_xact()
**
** Purpose:
** Scan_xact is a debugging routine used to retrieve the commit
** service row for a given commid. If commid is -1, scan_xact
** can be called repeatedly (while scan_xact(..))
** to return all entries in the commit service.
**
** Parameters
** conn The CS_CONNECTION used to communicate
** commid id used to identify xact to service
**
**
** Returns
** CS_SUCCEED or CS_FAIL
**
**
** Side Effects
**
*/
CS_RETCODE
scan_xact(conn, commid)
CS_CONNECTION *conn;
CS_INT commid;
{
CS_INT ret;
CS_RETCODE retcode;
CS_DATAFMT fmt;
CS_COMMAND *cmd;
/* Initialization */
(CS_VOID)memset((char *)&fmt, 0, sizeof(CS_DATAFMT));
/* Allocate a command handle */
if (ct_cmd_alloc(conn, &cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
if (ct_command(cmd, CS_RPC_CMD, "sp_scan_xact", CS_NULLTERM,
CS_UNUSED) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Prepare the count parameter */
strcpy(fmt.name, "@commid");
fmt.namelen = strlen(fmt.name);
fmt.datatype = CS_INT_TYPE;
fmt.maxlength = CS_SIZEOF(CS_INT);
fmt.status = CS_INPUTVALUE;
if (ct_param(cmd, &fmt, (CS_VOID *)&commid, CS_UNUSED, 0) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Send to server */
if (ct_send(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
while ((retcode = ct_results(cmd, &ret)) == CS_SUCCEED)
{
switch ((int)ret)
{
case CS_ROW_RESULT:
case CS_COMPUTE_RESULT:
if (pr_head(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
if (pr_line(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
if (pr_row(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
break;
case CS_STATUS_RESULT:
while ((retcode = ct_fetch(cmd, CS_UNUSED, CS_UNUSED,
CS_UNUSED, NULL)) == CS_SUCCEED)
{
continue;
}
if (retcode != CS_END_DATA)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
break;
case CS_CMD_FAIL:
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd,
CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
default:
break;
}
}
if (retcode != CS_END_RESULTS)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Free the command buffer */
if (ct_cmd_drop(cmd) != CS_SUCCEED)
{
return (CS_FAIL);
}
return (CS_SUCCEED);
}
/*
** stat_xact()
**
** Purpose:
** Stat_xact returns the status of the transaction identified by 'commid'.
**
** Parameters
** conn The connection to use.
** commid id used to indentify the transaction.
**
** Returns
** 'a' (abort), 'b' (begin), 'c' (commit), 'u' (unknown), or -1 (fail).
**
**
** Side Effects
**
*/
CS_INT
stat_xact(conn, commid)
CS_CONNECTION *conn;
CS_INT commid;
{
CS_INT ret;
CS_RETCODE retcode;
CS_CHAR commitchar;
CS_DATAFMT fmt;
CS_COMMAND *cmd;
/* Initialization */
commitchar = (CS_CHAR)-1;
/* Allocate a command handle */
if (ct_cmd_alloc(conn, &cmd) != CS_SUCCEED)
{
return (-1);
}
if (ct_command(cmd, CS_RPC_CMD, "sp_stat_xact", CS_NULLTERM,
CS_UNUSED) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (-1);
}
/* Prepare the count parameter */
strcpy(fmt.name, "@commid");
fmt.namelen = strlen(fmt.name);
fmt.datatype = CS_INT_TYPE;
fmt.maxlength = CS_SIZEOF(CS_INT);
fmt.status = CS_INPUTVALUE;
if (ct_param(cmd, &fmt, (CS_VOID *)&commid, CS_UNUSED, 0) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Send to server */
if (ct_send(cmd) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (-1);
}
/* Process the result from the commit */
while ((retcode = ct_results(cmd, &ret)) == CS_SUCCEED)
{
switch ((int)ret)
{
case CS_ROW_RESULT:
/*
** Could do a ct_describe() to ensure proper
** data type/num columns being returned.
*/
fmt.namelen = 0;
fmt.datatype = CS_CHAR_TYPE;
fmt.maxlength = 1;
fmt.status = 0;
if (ct_bind(cmd, 1, &fmt, (CS_VOID *)&commitchar,
(CS_INT *)NULL, (CS_SMALLINT *)NULL)
!= CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
while ((retcode = ct_fetch(cmd, CS_UNUSED, CS_UNUSED,
CS_UNUSED, NULL)) == CS_SUCCEED)
{
continue;
}
if (retcode != CS_END_DATA)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
break;
case CS_CMD_FAIL:
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
case CS_STATUS_RESULT:
default:
if (ct_cancel((CS_CONNECTION *)NULL, cmd,
CS_CANCEL_CURRENT) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
break;
}
}
if (retcode != CS_END_RESULTS)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
(CS_VOID)ct_cmd_drop(cmd);
return (CS_FAIL);
}
/* Free the command buffer */
if (ct_cmd_drop(cmd) != CS_SUCCEED)
{
return (-1);
}
return ((CS_INT)commitchar);
}
/*
** handle_results()
**
** Purpose:
** Process the results of a command. No results are expected.
**
** Parameters
** cmd The CS_COMMAND used to communicate
**
** Returns
** CS_SUCCEED or CS_FAIL
**
** Side Effects
** none.
*/
CS_STATIC CS_RETCODE
handle_results(cmd)
CS_COMMAND *cmd;
{
CS_INT ret;
CS_RETCODE retcode;
while ((retcode = ct_results(cmd, &ret)) == CS_SUCCEED)
{
switch ((int)ret)
{
case CS_CMD_FAIL:
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd,
CS_CANCEL_ALL);
return (CS_FAIL);
case CS_ROW_RESULT:
case CS_STATUS_RESULT:
default:
if (ct_cancel((CS_CONNECTION *)NULL, cmd,
CS_CANCEL_CURRENT) != CS_SUCCEED)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL,
cmd, CS_CANCEL_ALL);
return (CS_FAIL);
}
break;
}
}
if (retcode != CS_END_RESULTS)
{
(CS_VOID)ct_cancel((CS_CONNECTION *)NULL, cmd, CS_CANCEL_ALL);
return (CS_FAIL);
}
return (CS_SUCCEED);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -