static CS_RETCODE hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data) { CS_DATAFMT meta = { "" }; CS_INT length = 5; CS_INT row = 0; if (CS_SUCCEED != ct_cancel(con, NULL, CS_CANCEL_ALL)) return CS_FAIL; if (CS_SUCCEED != blk_init(blk, CS_BLK_IN, table, CS_NULLTERM)) return CS_FAIL; meta.count = 1; meta.datatype = CS_CHAR_TYPE; meta.format = CS_FMT_PADBLANK; meta.maxlength = 5; if (CS_SUCCEED != blk_bind(blk, (int) 1, &meta, data, &length, NULL)) return CS_FAIL; if (CS_SUCCEED != blk_rowxfer(blk)) return CS_FAIL; if (CS_SUCCEED != blk_done(blk, CS_BLK_ALL, &row)) return CS_FAIL; return CS_SUCCEED; }
static PyObject *CS_COMMAND_ct_cancel(CS_COMMANDObj *self, PyObject *args) { int type; CS_RETCODE status; if (!PyArg_ParseTuple(args, "i", &type)) return NULL; if (self->cmd == NULL) { PyErr_SetString(PyExc_TypeError, "CS_COMMAND has been dropped"); return NULL; } /* PyErr_Clear(); */ SY_CONN_BEGIN_THREADS(self->conn); status = ct_cancel(NULL, self->cmd, type); SY_CONN_END_THREADS(self->conn); if (self->debug) debug_msg("ct_cancel(NULL, cmd%d, %s) -> %s\n", self->serial, value_str(VAL_CANCEL, type), value_str(VAL_STATUS, status)); if (PyErr_Occurred()) return NULL; return PyInt_FromLong(status); }
int main(int argc, char **argv) { CS_CONTEXT *ctx; CS_CONNECTION *conn; int ret = 1; read_login_info(); if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) { fprintf(stderr, "Context Alloc failed!\n"); return ret; } if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) { fprintf(stderr, "Library Init failed!\n"); return ret; } if (ct_con_alloc(ctx, &conn) != CS_SUCCEED) { fprintf(stderr, "Connect Alloc failed!\n"); return ret; } if (ct_con_props(conn, CS_SET, CS_USERNAME, (CS_VOID*) "sa", CS_NULLTERM, NULL) != CS_SUCCEED) { fprintf(stderr, "ct_con_props() SET USERNAME failed!\n"); return ret; } if (ct_con_props(conn, CS_SET, CS_PASSWORD, (CS_VOID*) "invalid", CS_NULLTERM, NULL) != CS_SUCCEED) { fprintf(stderr, "ct_con_props() SET PASSWORD failed!\n"); return ret; } if (ct_connect(conn, SERVER, CS_NULLTERM) != CS_FAIL) { fprintf(stderr, "Connection succeeded??\n"); return ret; } if (ct_cancel(conn, NULL, CS_CANCEL_ALL) != CS_SUCCEED) { fprintf(stderr, "ct_cancel() failed!\n"); return ret; } if (ct_close(conn, CS_UNUSED) != CS_SUCCEED) { fprintf(stderr, "ct_close() failed!\n"); return ret; } if (ct_con_drop(conn) != CS_SUCCEED) { fprintf(stderr, "ct_con_drop() failed!\n"); return ret; } if (ct_exit(ctx, CS_UNUSED) != CS_SUCCEED) { fprintf(stderr, "ct_exit() failed!\n"); return ret; } if (cs_ctx_drop(ctx) != CS_SUCCEED) { fprintf(stderr, "cs_ctx_drop() failed!\n"); return ret; } fprintf(stdout, "Test succeeded\n"); return 0; }
//------------------------------------------------------------------------------ command::~command() { if (!m_cmd) return; // cancel only unfinished, not already canceled command if (lastRes != RES_CANCELED && lastRes != RES_END) { if (ct_cancel(0, m_cmd, CS_CANCEL_ALL) != CS_SUCCEED) { throw ss::Error("DBI-EXEC-EXCEPTION", "ct_cancel failed"); } } ct_cmd_drop(m_cmd); }
void catch_alrm(int sig_num) { signal(SIGALRM, catch_alrm); fprintf(stdout, "- SIGALRM\n"); /* Cancel current command */ if (g_cmd) ct_cancel(NULL, (CS_COMMAND *) g_cmd, CS_CANCEL_ATTN); fflush(stdout); }
CS_RETCODE try_ctlogout(CS_CONTEXT * ctx, CS_CONNECTION * conn, CS_COMMAND * cmd, int verbose) { CS_RETCODE ret; ret = ct_cancel(conn, NULL, CS_CANCEL_ALL); if (ret != CS_SUCCEED) { if (verbose) { fprintf(stderr, "ct_cancel() failed!\n"); } return ret; } ct_cmd_drop(cmd); ct_close(conn, CS_UNUSED); ct_con_drop(conn); ct_exit(ctx, CS_UNUSED); cs_ctx_drop(ctx); return CS_SUCCEED; }
void CTL_RowResult::Close(void) { if (x_GetSybaseCmd()) { if (m_EOR || IsDead()) { return; } switch (Check(ct_cancel(NULL, x_GetSybaseCmd(), CS_CANCEL_CURRENT))) { case CS_SUCCEED: case CS_CANCELED: break; default: CS_INT err_code = 130007; Check(ct_cmd_props(x_GetSybaseCmd(), CS_SET, CS_USERDATA, &err_code, (CS_INT) sizeof(err_code), 0)); } m_Cmd = NULL; } }
/** * @brief read data from sybase ASE server TBL_DataUpdateFlag * * @return */ int CSybClient::read_DataUpdateFlag(int connId, char* tablename, int flagid, stDataUpdateTime* pData) { CS_CONNECTION *connection = getConnection(connId); if(NULL == connection || NULL == tablename) return -1; CLEAR_ALL_MESSAGE(connection); CS_RETCODE retcode; CS_COMMAND *cmd; CS_INT res_type; /* result type from ct_results */ CS_INT row_count = 0; /* ** Use the dbname database */ //CS_CHAR usetable[64] = {0}; //sprintf(usetable, "use %s\n", dbname); //if(execNoReplyCmd(connection, usetable) < 0) //{ // return -1; //} /* ** Allocate a command handle to send the query with */ if ((retcode = ct_cmd_alloc(connection, &cmd)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); return -1; } /* ** Define a language command. */ CS_CHAR select[256] = {0}; sprintf(select, "select UpdateTime, UpdateFlag from %s where UpdateIndex=%d", tablename, flagid); retcode = ct_command(cmd, CS_LANG_CMD, select, CS_NULLTERM, CS_UNUSED); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } /* ** Send the command to the server */ if (ct_send(cmd) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } /* ** Process the results. Loop while ct_results() returns CS_SUCCEED. */ while ((retcode = ct_results(cmd, &res_type)) == CS_SUCCEED) { switch ((int)res_type) { case CS_CMD_SUCCEED: /* ** This means no rows were returned. */ break; case CS_CMD_DONE: /* ** This means we're done with one result set. */ break; case CS_CMD_FAIL: /* ** This means that the server encountered an error ** while processing our command. */ DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; case CS_ROW_RESULT: { #define FIELD_UpdateTime 1 //ÒÔselect Óï¾äΪ׼ #define FIELD_UpdateFlag 2 CS_DATETIME updateTime; CS_TINYINT updateFlag; CS_INT i; CS_INT rows_read; CS_DATAFMT dfmt; /* ** Bind to column */ dfmt.datatype = CS_DATETIME_TYPE; dfmt.maxlength = CS_SIZEOF(CS_DATETIME); dfmt.format = CS_FMT_UNUSED; dfmt.count = 0; dfmt.locale = NULL; retcode = ct_bind(cmd, FIELD_UpdateTime, &dfmt, &updateTime, NULL, NULL); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cmd_drop(cmd); return -1; } // dfmt.datatype = CS_TINYINT_TYPE; dfmt.maxlength= CS_SIZEOF(CS_TINYINT); retcode = ct_bind(cmd, FIELD_UpdateFlag, &dfmt, &updateFlag, NULL, NULL); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cmd_drop(cmd); return -1; } CS_DATEREC userdatetime; /* ** Fetch the rows. Loop while ct_fetch() returns CS_SUCCEED or ** CS_ROW_FAIL */ while (((retcode = ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read)) == CS_SUCCEED) || (retcode == CS_ROW_FAIL)) { /* ** Increment our row count by the number of rows just fetched. */ row_count = row_count + rows_read; /* ** Check if we hit a recoverable error. */ if (retcode == CS_ROW_FAIL) { } /* ** We have a row. Loop through the columns displaying the ** column values. */ //printf("%ld rows read from TBL_DataUpdateFlag\n", (long)rows_read); for (i = 0; i < rows_read; i++) { if(cs_dt_crack(context, CS_DATETIME_TYPE, &updateTime, &userdatetime) == CS_SUCCEED) { sprintf(pData->UpdateTime, "%04d-%02d-%02d %02d:%02d:%02d", userdatetime.dateyear, userdatetime.datemonth+1, userdatetime.datedmonth, userdatetime.datehour, userdatetime.dateminute, userdatetime.datesecond); pData->UpdateIndex = flagid; pData->UpdateFlag = updateFlag; } } } /* ** We're done processing rows. Let's check the final return ** value of ct_fetch(). */ switch ((int)retcode) { case CS_END_DATA: /* ** Everything went fine. */ retcode = CS_SUCCEED; break; case CS_FAIL: /* ** Something terrible happened. */ break; default: /* ** We got an unexpected return value. */ break; } } /////////////////////// if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cmd_drop(cmd); return -1; } break; default: /* ** We got an unexpected result type. */ DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } } /* ** We're done processing results. Let's check the ** return value of ct_results() to see if everything ** went ok. */ switch ((int)retcode) { case CS_END_RESULTS: /* ** Everything went fine. */ break; case CS_FAIL: /* ** Something went wrong. */ DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cmd_drop(cmd); return -1; default: /* ** We got an unexpected return value. */ DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cmd_drop(cmd); return -1; } /* ** Drop our command structure */ if ((retcode = ct_cmd_drop(cmd)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); return -1; } return retcode == CS_SUCCEED ? row_count : -1; }
int CSybClient::write_ImsiMsisdn(int connId, char* tablename, stImsiMsisdn* pNum) { CS_CONNECTION *connection = getConnection(connId); if(NULL == connection || NULL == tablename) return -1; if(NULL == pNum) return -1; CLEAR_ALL_MESSAGE(connection); // CS_RETCODE retcode; CS_INT restype; CS_COMMAND *cmd = NULL; CS_RETCODE query_code; /* ** Get a command handle, store the command string in it, and ** send it to the server. */ if ((retcode = ct_cmd_alloc(connection, &cmd)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); return -1; } // CS_CHAR cmdstring[1024] = {0}; char strimsi[32] = {0}; memcpy(strimsi, pNum->strImsi, MINIX(sizeof(strimsi) - 1, pNum->ImsiLen)); sprintf(cmdstring, "insert into %s (IMSI, MSISDN, UpdateTime, AreaCode, SARNumber, ExchangeHouse) values (\"%s\", \"%s\", getdate(), \"%s\", %hhu, %hhu)", tablename, strimsi, pNum->strMsisdn, pNum->strAreaCode, pNum->admCenter, pNum->switchCenter); if ((retcode = ct_command(cmd, CS_LANG_CMD, cmdstring, CS_NULLTERM, CS_UNUSED)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } if ((retcode = ct_send(cmd)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } /* ** Examine the results coming back. If any errors are seen, the query ** result code (which we will return from this function) will be ** set to FAIL. */ query_code = CS_SUCCEED; while ((retcode = ct_results(cmd, &restype)) == CS_SUCCEED) { switch((int)restype) { case CS_CMD_SUCCEED: case CS_CMD_DONE: break; case CS_CMD_FAIL: query_code = CS_FAIL; break; case CS_STATUS_RESULT: retcode = ct_cancel(NULL, cmd, CS_CANCEL_CURRENT); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); query_code = CS_FAIL; } break; default: /* ** Unexpected result type. */ query_code = CS_FAIL; break; } if (query_code == CS_FAIL) { /* ** Terminate results processing and break out of ** the results loop */ retcode = ct_cancel(NULL, cmd, CS_CANCEL_ALL); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); } break; } } /* ** Clean up the command handle used */ if (retcode == CS_END_RESULTS) { retcode = ct_cmd_drop(cmd); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); query_code = CS_FAIL; } } else { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); (void)ct_cmd_drop(cmd); query_code = CS_FAIL; } return query_code == CS_SUCCEED ? 0 : -1; }
int CSybClient::delMsisdnImsiByMsisdn(int connId, char* tablename, stImsiMsisdn* pmsisdn) { CS_CONNECTION *connection = getConnection(connId); if(NULL == connection || NULL == tablename) return -1; if(NULL == pmsisdn) return -1; CLEAR_ALL_MESSAGE(connection); // CS_RETCODE retcode; CS_INT restype; CS_COMMAND *cmd = NULL; CS_RETCODE query_code; /* ** Get a command handle, store the command string in it, and ** send it to the server. */ if ((retcode = ct_cmd_alloc(connection, &cmd)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); return -1; } // CS_CHAR cmdstring[1024] = {0}; sprintf(cmdstring, "delete from %s where MSISDN='%s'", tablename, pmsisdn->strMsisdn); if ((retcode = ct_command(cmd, CS_LANG_CMD, cmdstring, CS_NULLTERM, CS_UNUSED)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } if ((retcode = ct_send(cmd)) != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); ct_cancel(NULL, cmd, CS_CANCEL_ALL); ct_cmd_drop(cmd); return -1; } /* ** Examine the results coming back. If any errors are seen, the query ** result code (which we will return from this function) will be ** set to FAIL. */ query_code = CS_SUCCEED; while ((retcode = ct_results(cmd, &restype)) == CS_SUCCEED) { switch((int)restype) { case CS_CMD_SUCCEED: case CS_CMD_DONE: break; case CS_CMD_FAIL: query_code = CS_FAIL; break; case CS_STATUS_RESULT: retcode = ct_cancel(NULL, cmd, CS_CANCEL_CURRENT); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); query_code = CS_FAIL; } break; default: /* ** Unexpected result type. */ query_code = CS_FAIL; break; } if (query_code == CS_FAIL) { /* ** Terminate results processing and break out of ** the results loop */ retcode = ct_cancel(NULL, cmd, CS_CANCEL_ALL); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); } break; } } /* ** Clean up the command handle used */ if (retcode == CS_END_RESULTS) { retcode = ct_cmd_drop(cmd); if (retcode != CS_SUCCEED) { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); query_code = CS_FAIL; } } else { DIAG_CLIENT_MESSAGE(connection); DIAG_SERVER_MESSAGE(connection); (void)ct_cmd_drop(cmd); query_code = CS_FAIL; } return query_code == CS_SUCCEED ? 0 : -1; }