本文整理汇总了C++中SQLExecute函数的典型用法代码示例。如果您正苦于以下问题:C++ SQLExecute函数的具体用法?C++ SQLExecute怎么用?C++ SQLExecute使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SQLExecute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TestSQLExecute
/*
---------------------------------------------------------
TestSQLExecute
---------------------------------------------------------
*/
PassFail TestSQLExecute(TestInfo *pTestInfo, int MX_MP_SPECIFIC)
{
TEST_DECLARE;
RETCODE returncode;
SQLHANDLE henv;
SQLHANDLE hdbc;
SQLHANDLE hstmt;
TCHAR *ExecStr[15];
TCHAR *szInput[] = {_T("Inst char"),_T("Inst vchar"),_T("1234.56789"),_T("1234.56789"),_T("1200"),_T("12000"),_T("123.45"),_T("123.45"),_T("123.45"),_T("1993-07-01"),_T("09:45:30"),_T("1993-08-02 08:44:31.001"),_T("120000"),_T("1234567890.56789"),_T("1234567890.456789"),_T("1234567890.456789"),_T("0.01234567890123456789"),_T("1234.56789"),_T("1234567890.56789"),_T("12345678901234567890.0123456789"),_T("Inst char"),_T("Inst vchar")};
SQLLEN cbInput = SQL_NTS;
SQLUSMALLINT i = 0;
SQLSMALLINT Type[] = {SQL_WCHAR,SQL_WVARCHAR,SQL_DECIMAL,SQL_NUMERIC,SQL_SMALLINT,SQL_INTEGER,SQL_REAL,SQL_FLOAT,SQL_DOUBLE,SQL_DATE,SQL_TIME,SQL_TIMESTAMP,SQL_BIGINT,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_NUMERIC,SQL_WCHAR,SQL_WVARCHAR};
SQLUINTEGER ColPrec[] = {254,254,10,10,5,10,7,15,15,10,8,26,19,19,19,128,128,10,18,30,254,254};
SQLSMALLINT ColScale[]= {0,0,5,5,0,0,0,0,0,0,0,0,0,0,6,0,128,5,5,10,0,0};
short CCharOutput1,CCharOutput2;
SQLLEN OutputLen1,OutputLen2;
int actual_insert=0,num_insert=0;
SWORD param = 0;
//===========================================================================================================
var_list_t *var_list;
var_list = load_api_vars(_T("SQLExecute"), charset_file);
if (var_list == NULL) return FAILED;
//print_list(var_list);
ExecStr[0] = var_mapping(_T("SQLExecute_ExecStr_0"), var_list);
ExecStr[1] = var_mapping(_T("SQLExecute_ExecStr_1"), var_list);
ExecStr[2] = var_mapping(_T("SQLExecute_ExecStr_2"), var_list);
ExecStr[3] = var_mapping(_T("SQLExecute_ExecStr_3"), var_list);
ExecStr[4] = var_mapping(_T("SQLExecute_ExecStr_4"), var_list);
ExecStr[5] = var_mapping(_T("SQLExecute_ExecStr_5"), var_list);
ExecStr[6] = var_mapping(_T("SQLExecute_ExecStr_6"), var_list);
ExecStr[7] = var_mapping(_T("SQLExecute_ExecStr_7"), var_list);
ExecStr[8] = var_mapping(_T("SQLExecute_ExecStr_8"), var_list);
ExecStr[9] = var_mapping(_T("SQLExecute_ExecStr_9"), var_list);
ExecStr[10] = var_mapping(_T("SQLExecute_ExecStr_10"), var_list);
ExecStr[11] = var_mapping(_T("SQLExecute_ExecStr_11"), var_list);
ExecStr[12] = var_mapping(_T("SQLExecute_ExecStr_12"), var_list);
ExecStr[13] = var_mapping(_T("SQLExecute_ExecStr_13"), var_list);
ExecStr[14] = var_mapping(_T("SQLExecute_ExecStr_14"), var_list);
//=================================================================================================
LogMsg(LINEBEFORE+SHORTTIMESTAMP,_T("Begin testing API => SQLExecute.\n"));
TEST_INIT;
TESTCASE_BEGIN("Setup for SQLExecute tests\n");
if(!FullConnect(pTestInfo)){
LogMsg(NONE,_T("Unable to connect\n"));
TEST_FAILED;
TEST_RETURN;
}
henv = pTestInfo->henv;
hdbc = pTestInfo->hdbc;
hstmt = (SQLHANDLE)pTestInfo->hstmt;
returncode = SQLAllocStmt((SQLHANDLE)hdbc, &hstmt);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLAllocStmt")){
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[4],SQL_NTS);
returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[5],SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode=SQLExecDirect(hstmt,(SQLTCHAR *)ExecStr[6],SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[7],SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode=SQLExecDirect(hstmt,(SQLTCHAR*)ExecStr[8],SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect")){
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
//.........这里部分代码省略.........
示例2: InsertTest
//*************************************************************************
// FUNCTION FOR INSERTING ROWS IN IT.
int InsertTest(SQLHANDLE env,SQLHANDLE dbc,SQLHANDLE stmt)
{
int ret;
int f1=90; // f1 field
short int f2=20;//f2 field
char f3[50]= "jitendra";
float f4 = 2.5;
float f5 = 10.50;
int f9 = 5;
long long f10 = 15000;
int result;
SQLINTEGER slen = SQL_NTS;
//***********************************
// STRUCTURE FIOR DATE DATATYPE
SQL_DATE_STRUCT date;
char strDate[30];
date.year=2008;
date.month=03;
date.day=18;
// strcpy(strDate,"{d '2008-03-18'}");
//*******************************
// STRUCTURE FOR TIME DATATYPE.
SQL_TIME_STRUCT time;
time.hour = 5;
time.minute = 22;
time.second = 10;
//*****************************
// STRUCTURE FOR TIMESTAMP DATATYPE
SQL_TIMESTAMP_STRUCT timestamp;
timestamp.year = 2008;
timestamp.month = 03;
timestamp.day = 18;
timestamp.hour = 5;
timestamp.minute = 22;
timestamp.second = 10;
timestamp.fraction = 764576;
//******************************
// PREPARE THE STATEMENT.
ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO T1 VALUES(?,?,?,?,?,?,?,?,?,?)",SQL_NTS);
checkrc(ret,__LINE__);
// BIND PARAMETER FOR ALL THE FIELD
ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SSHORT,SQL_SMALLINT,0,0,&f2,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f3,0,&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,4,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_FLOAT,0,0,&f4,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,5,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_REAL,0,0,&f5,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,6,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_DATE,196,0,&date,sizeof(date),&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,7,SQL_PARAM_INPUT,SQL_C_TYPE_TIME,SQL_TYPE_TIME,196,0,&time,sizeof(time),&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,8,SQL_PARAM_INPUT,SQL_C_TYPE_TIMESTAMP,SQL_TYPE_TIMESTAMP,196,0,×tamp,sizeof(timestamp),&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,9,SQL_PARAM_INPUT,SQL_C_TINYINT,SQL_TINYINT,0,0,&f9,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,10,SQL_PARAM_INPUT,SQL_C_SBIGINT,SQL_BIGINT,0,0,&f10,0,NULL);
checkrc(ret,__LINE__);
int i,count=0;
// EXECUTE THE STATEMENT
for(i=0;i<20;i++)
{
f1++;
f2++;
f4++;
ret = SQLExecute(stmt);
checkrc(ret,__LINE__);
ret = SQLTransact(env,dbc,SQL_COMMIT);
checkrc(ret,__LINE__);
count++;
}
printf("Total row inserted=%d\n",count);
return 0;
}
示例3: BatchInsert
void BatchInsert(SQLHANDLE hdbc, SQLHANDLE hstmt, char *TableName, unsigned int SizeOfBatch, unsigned int NumberRecords)
{
SQLRETURN rc;
char Statement[1000];
SQLCHAR FirstName[DESC_LEN];
SQLCHAR LastName[DESC_LEN];
int EmpID = 10000;
SQL_DATE_STRUCT HireDate;
int Salary;
SQLCHAR Dept[DESC_LEN];
int Exempt;
SQLLEN FirstNameInd,
LastNameInd,
EmpIDInd,
HireDateInd,
SalaryInd,
DeptInd,
ExemptInd;
SQLUINTEGER i,
NumRecords,
Loop;
strcpy(Statement, "insert into ");
strcat(Statement, TableName);
strcat(Statement, " (FIRST_NAME, LAST_NAME, EMP_ID, HIRE_DATE, SALARY, DEPT, EXEMPT) ");
strcat(Statement, "values (?, ?, ?, ?, ?, ?, ?)");
// Set AUTOCOMMIT off
rc = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER);
// Bind the parameters in column-wise fashion
rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 20, 0,
FirstName, DESC_LEN, &FirstNameInd);
rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 30, 0,
LastName, DESC_LEN, &LastNameInd);
rc = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 6, 0,
(SQLPOINTER)&EmpID, sizeof(int), &EmpIDInd);
rc = SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TYPE_TIMESTAMP, 19, 0,
&HireDate, 19, &HireDateInd);
rc = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 9, 0,
(SQLPOINTER)&Salary, sizeof(int), &SalaryInd);
rc = SQLBindParameter(hstmt, 6, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 4, 0,
Dept, DESC_LEN, &DeptInd);
rc = SQLBindParameter(hstmt, 7, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 3, 0,
(SQLPOINTER)&Exempt, sizeof(int), &ExemptInd);
rc = SQLPrepare(hstmt, (unsigned char*)Statement, strlen(Statement));
NumRecords = NumberRecords;
i = 0;
while (NumRecords > 0) {
if (NumRecords < SizeOfBatch) {
Loop = NumRecords;
}
else {
Loop = SizeOfBatch;
}
// Set values for insert
for (i = 0; i < Loop; i++) {
strcpy((char *)FirstName, "Gordon");
FirstNameInd = strlen(FirstName);
strcpy((char *)LastName, "Crenshaw");
LastNameInd = strlen(LastName);
EmpID++;
EmpIDInd = 0;
HireDate.year = 1995;
HireDate.month = 9;
HireDate.day = 06;
HireDateInd = 0;
Salary = 1000;
SalaryInd = 0;
strcpy((char *)Dept, "D101");
DeptInd = strlen(Dept);
Exempt = 100;
ExemptInd = 0;
// Execute the statement
rc = SQLExecute(hstmt);
switch (rc) {
case SQL_SUCCESS:
break;
case SQL_SUCCESS_WITH_INFO:
//.........这里部分代码省略.........
示例4: main
int main(int argc, char **argv)
{
SQLRETURN rc;
HSTMT hstmt = SQL_NULL_HSTMT;
char param1[20] = { 1, 2, 3, 4, 5, 6, 7, 8 };
SQLLEN cbParam1;
SQLSMALLINT colcount;
SQLSMALLINT dataType;
SQLULEN paramSize;
SQLSMALLINT decDigits;
SQLSMALLINT nullable;
test_connect();
rc = SQLAllocHandle(SQL_HANDLE_STMT, conn, &hstmt);
if (!SQL_SUCCEEDED(rc))
{
print_diag("failed to allocate stmt handle", SQL_HANDLE_DBC, conn);
exit(1);
}
/**** Query with a bytea param ****/
/* Prepare a statement */
rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT id, t FROM byteatab WHERE t = ?", SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt);
/* bind param */
cbParam1 = 8;
rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_BINARY, /* value type */
SQL_BINARY, /* param type */
20, /* column size */
0, /* dec digits */
param1, /* param value ptr */
0, /* buffer len */
&cbParam1 /* StrLen_or_IndPtr */);
CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt);
/* Test SQLNumResultCols, called before SQLExecute() */
rc = SQLNumResultCols(hstmt, &colcount);
CHECK_STMT_RESULT(rc, "SQLNumResultCols failed", hstmt);
printf("# of result cols: %d\n", colcount);
/* Execute */
rc = SQLExecute(hstmt);
CHECK_STMT_RESULT(rc, "SQLExecute failed", hstmt);
/* Fetch result */
print_result(hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/*** Test SQLBindParameter with SQLExecDirect ***/
printf("\nTesting SQLBindParameter with SQLExecDirect...\n");
/* bind param */
strcpy(param1, "bar");
cbParam1 = SQL_NTS;
rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_CHAR, /* value type */
SQL_CHAR, /* param type */
20, /* column size */
0, /* dec digits */
param1, /* param value ptr */
0, /* buffer len */
&cbParam1 /* StrLen_or_IndPtr */);
CHECK_STMT_RESULT(rc, "SQLBindParameter failed", hstmt);
rc = SQLExecDirect(hstmt, (SQLCHAR *) "SELECT 'foo' UNION ALL SELECT ?", SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLExecDirect failed", hstmt);
print_result(hstmt);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/*** Test SQLDescribeParam ***/
printf("\nTesting SQLDescribeParam...\n");
rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
CHECK_STMT_RESULT(rc, "SQLFreeStmt failed", hstmt);
/* Prepare a statement */
rc = SQLPrepare(hstmt, (SQLCHAR *) "SELECT id, t FROM testtab1 WHERE id = ?", SQL_NTS);
CHECK_STMT_RESULT(rc, "SQLPrepare failed", hstmt);
rc = SQLDescribeParam(hstmt, 1, &dataType, ¶mSize, &decDigits, &nullable);
CHECK_STMT_RESULT(rc, "SQLDescribeParams failed", hstmt);
printf("Param 1: type %s; size %u; dec digits %d; %s\n",
datatype_str(dataType), (unsigned int) paramSize, decDigits, nullable_str(nullable));
/* bind param */
strcpy(param1, "3");
cbParam1 = SQL_NTS;
rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
SQL_C_CHAR, /* value type */
SQL_CHAR, /* param type */
20, /* column size */
0, /* dec digits */
param1, /* param value ptr */
//.........这里部分代码省略.........
示例5: DeleteTest
//.........这里部分代码省略.........
SQLINTEGER slen=SQL_NTS;
char strDate[20];
char strTime[20];
char strTimestamp[30];
SQL_DATE_STRUCT date;
date.year=2008;
date.month=03;
date.day=18;
//**********************************************
SQL_TIME_STRUCT time;
time.hour = 5;
time.minute = 22;
time.second = 10;
//*********************************************
SQL_TIMESTAMP_STRUCT timestamp;
timestamp.year = 2008;
timestamp.month = 03;
timestamp.day = 18;
timestamp.hour = 5;
timestamp.minute = 22;
timestamp.second = 10;
timestamp.fraction = 764576;
int f1temp,f2temp;
char f3temp[20];
float f4temp, f5temp;
SQL_DATE_STRUCT f6Date;
SQL_TIME_STRUCT f7Time;
SQL_TIMESTAMP_STRUCT f8Timestamp;
int f9temp;
long long f10temp;
ret = SQLPrepare(stmt,(unsigned char*)"DELETE FROM T1 WHERE F1=? AND F2=? AND F3=? AND F4=? AND F5=? AND F6=? AND F7=? AND F8=? AND F9=? AND F10=?",SQL_NTS);
checkrc(ret,__LINE__);
//ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SMALL,SQL_SMALL,0,0,)
ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&f1temp,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,2,SQL_PARAM_INPUT,SQL_C_SSHORT,SQL_INTEGER,0,0,&f2temp,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,196,0,(void*)f3temp,0,&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,4,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_FLOAT,0,0,&f4temp,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,5,SQL_PARAM_INPUT,SQL_C_FLOAT,SQL_REAL,0,0,&f5temp,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,6,SQL_PARAM_INPUT,SQL_C_TYPE_DATE,SQL_TYPE_DATE,196,0,&f6Date,sizeof(f6Date),&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,7,SQL_PARAM_INPUT,SQL_C_TYPE_TIME,SQL_TYPE_TIME,196,0,&f7Time,sizeof(f7Time),&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,8,SQL_PARAM_INPUT,SQL_C_TYPE_TIMESTAMP,SQL_TYPE_TIMESTAMP,196,0,&f8Timestamp,sizeof(f8Timestamp),&slen);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,9,SQL_PARAM_INPUT,SQL_C_TINYINT,SQL_TINYINT,0,0,&f9temp,0,NULL);
checkrc(ret,__LINE__);
ret = SQLBindParameter(stmt,10,SQL_PARAM_INPUT,SQL_C_SBIGINT,SQL_BIGINT,0,0,&f10temp,0,NULL);
checkrc(ret,__LINE__);
//*******************************************************************************************************
int j, count=0;
f6Date=date;
f7Time=time;
f8Timestamp=timestamp;
for(j=0;j<20;j++)
{
f1temp=f1++;
f2temp=f2++;
strcpy(f3temp,"jitendra");
f4temp=f4++;
f5temp=f5;
f9temp=f9;
f10temp=f10;
ret = SQLExecute(stmt);
checkrc(ret,__LINE__);
count++;
}
ret = SQLTransact(env,dbc,SQL_COMMIT);
checkrc(ret,__LINE__);
printf("Total row deleted=%d\n",count);
return 0;
}
示例6: ODBC_Test
//.........这里部分代码省略.........
else if (!TXTCMP (request, TEXT ("reconnect")))
{
if (ODBC_Reconnect())
return -1;
continue;
}
#if defined (unix)
else if (!TXTCMP (request, TEXT ("environment")))
{
extern char **environ;
int i;
for (i = 0; environ[i]; i++)
fprintf (stderr, "%03d: [%s]\n", i, environ[i]);
continue;
}
#endif
else if (!TXTCMP (request, TEXT ("quit"))
|| !TXTCMP (request, TEXT ("exit")))
break; /* If you want to quit, just say so */
else
{
/*
* Prepare & Execute the statement
*/
if (SQLPrepare (hstmt, (SQLTCHAR *) request,
SQL_NTS) != SQL_SUCCESS)
{
ODBC_Errors ("SQLPrepare");
continue;
}
if ((sts = SQLExecute (hstmt)) != SQL_SUCCESS)
{
ODBC_Errors ("SQLExec");
if (sts != SQL_SUCCESS_WITH_INFO)
continue;
}
}
/*
* Loop through all the result sets
*/
totalSets = 1;
do
{
/*
* Get the number of result columns for this cursor.
* If it is 0, then the statement was probably a select
*/
if (SQLNumResultCols (hstmt, &numCols) != SQL_SUCCESS)
{
ODBC_Errors ("SQLNumResultCols");
goto endCursor;
}
if (numCols == 0)
{
SQLLEN nrows = 0;
SQLRowCount (hstmt, &nrows);
printf ("Statement executed. %ld rows affected.\n",
nrows > 0 ? (long) nrows : 0L);
goto endCursor;
}
示例7: backsql_count_children
int
backsql_count_children(
Operation *op,
SQLHDBC dbh,
struct berval *dn,
unsigned long *nchildren )
{
backsql_info *bi = (backsql_info *)op->o_bd->be_private;
SQLHSTMT sth = SQL_NULL_HSTMT;
BACKSQL_ROW_NTS row;
RETCODE rc;
int res = LDAP_SUCCESS;
Debug( LDAP_DEBUG_TRACE, "==>backsql_count_children(): dn=\"%s\"\n",
dn->bv_val, 0, 0 );
if ( dn->bv_len > BACKSQL_MAX_DN_LEN ) {
Debug( LDAP_DEBUG_TRACE,
"backsql_count_children(): DN \"%s\" (%ld bytes) "
"exceeds max DN length (%d):\n",
dn->bv_val, dn->bv_len, BACKSQL_MAX_DN_LEN );
return LDAP_OTHER;
}
/* begin TimesTen */
Debug(LDAP_DEBUG_TRACE, "children id query \"%s\"\n",
bi->sql_has_children_query, 0, 0);
assert( bi->sql_has_children_query != NULL );
rc = backsql_Prepare( dbh, &sth, bi->sql_has_children_query, 0 );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"backsql_count_children(): error preparing SQL:\n%s",
bi->sql_has_children_query, 0, 0);
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
return LDAP_OTHER;
}
rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, dn );
if ( rc != SQL_SUCCESS) {
/* end TimesTen */
Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
"error binding dn=\"%s\" parameter:\n",
dn->bv_val, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
return LDAP_OTHER;
}
rc = SQLExecute( sth );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_count_children(): "
"error executing query (\"%s\", \"%s\"):\n",
bi->sql_has_children_query, dn->bv_val, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
return LDAP_OTHER;
}
backsql_BindRowAsStrings_x( sth, &row, op->o_tmpmemctx );
rc = SQLFetch( sth );
if ( BACKSQL_SUCCESS( rc ) ) {
char *end;
*nchildren = strtol( row.cols[ 0 ], &end, 0 );
if ( end == row.cols[ 0 ] ) {
res = LDAP_OTHER;
} else {
switch ( end[ 0 ] ) {
case '\0':
break;
case '.': {
unsigned long ul;
/* FIXME: braindead RDBMSes return
* a fractional number from COUNT!
*/
if ( lutil_atoul( &ul, end + 1 ) != 0 || ul != 0 ) {
res = LDAP_OTHER;
}
} break;
default:
res = LDAP_OTHER;
}
}
} else {
res = LDAP_OTHER;
}
backsql_FreeRow_x( &row, op->o_tmpmemctx );
SQLFreeStmt( sth, SQL_DROP );
Debug( LDAP_DEBUG_TRACE, "<==backsql_count_children(): %lu\n",
*nchildren, 0, 0 );
//.........这里部分代码省略.........
示例8: LLOG
bool ODBCConnection::Execute()
{
LLOG("Execute " << (void *)this << " " << (void *)session << " " << statement);
if(session->hstmt == SQL_NULL_HANDLE)
return false;
session->FlushConnections();
last_insert_table.Clear();
number.Clear();
text.Clear();
time.Clear();
CParser p(statement);
if((p.Id("insert") || p.Id("INSERT")) && (p.Id("into") || p.Id("INTO")) && p.IsId())
last_insert_table = p.ReadId();
String query;
int pi = 0;
const char *s = statement;
while(s < statement.End())
if(*s == '\'' || *s == '\"')
s = ODBCReadString(s, query);
else {
if(*s == '?') {
if(pi >= param.GetCount()) {
session->SetError("Invalid number of parameters", statement);
return false;
}
Value v = param[pi++];
if(v.GetType() == 34)
query.Cat(SqlCompile(MSSQL, ~SqlBinary(SqlRaw(v))));
else
query.Cat(SqlCompile(MSSQL, ~SqlVal(v)));
}
else
query.Cat(*s);
s++;
}
param.Clear();
if(!IsOk(SQLPrepare(session->hstmt, (SQLCHAR *)~query, query.GetCount())))
return false;
/*
}
else {
if(!IsOk(SQLPrepare(session->hstmt, (SQLCHAR *)~statement, statement.GetCount())))
return false;
parse = false;
bparam = pick(param);
param.Clear();
for(int i = 0; i < bparam.GetCount(); i++) {
Param& p = bparam[i];
if(!IsOk(SQLBindParameter(session->hstmt, i + 1, SQL_PARAM_INPUT, p.ctype, p.sqltype,
p.width, 0, (SQLPOINTER)~p.data, p.data.GetLength(), &p.li)))
return false;
}
}
*/
SQLSMALLINT ncol;
if(!IsOk(SQLExecute(session->hstmt)) || !IsOk(SQLNumResultCols(session->hstmt, &ncol))) {
SQLFreeStmt(session->hstmt, SQL_CLOSE);
return false;
}
info.Clear();
string_type.Clear();
for(int i = 1; i <= ncol; i++) {
SQLCHAR ColumnName[256];
SQLSMALLINT NameLength;
SQLSMALLINT DataType;
SQLULEN ColumnSize;
SQLSMALLINT DecimalDigits;
SQLSMALLINT Nullable;
if(!IsOk(SQLDescribeCol(session->hstmt, i, ColumnName, 255, &NameLength, &DataType,
&ColumnSize, &DecimalDigits, &Nullable)))
return false;
string_type.Add(SQL_C_CHAR);
SqlColumnInfo& f = info.Add();
f.nullable = Nullable != SQL_NO_NULLS;
f.binary = false;
f.precision = DecimalDigits;
f.scale = 0;
f.width = ColumnSize;
f.name = (char *)ColumnName;
switch(DataType) {
case SQL_DECIMAL:
case SQL_NUMERIC:
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_REAL:
case SQL_FLOAT:
case SQL_DOUBLE:
case SQL_BIT:
case SQL_TINYINT:
f.type = DOUBLE_V;
break;
case SQL_BIGINT:
f.type = INT64_V;
break;
case SQL_TYPE_DATE:
f.type = DATE_V;
break;
case SQL_TYPE_TIMESTAMP:
//.........这里部分代码省略.........
示例9: DBBinary
CDBBinary CODBCRecordset::SelectBinary(const CString& strQuery)
{
CDBBinary DBBinary(5, 5);
DBBinary.Clear();
DBBinary.SetCurUsedSize(-1);
if (0 == strQuery.GetLength())
{
return DBBinary;
}
HSTMT hStmt;
unsigned char Data[BINARY_FIELD_MAX_SIZE] = {0};
SQLLEN ind = SQL_DATA_AT_EXEC;
if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, m_pDatabase->GetConn(), &hStmt))
{
return DBBinary;
}
SQLPrepare(hStmt, SQLData(strQuery), SQL_NTS);
if (SQL_ERROR == SQLBindParameter(hStmt, 1, SQL_PARAM_OUTPUT, SQL_C_BINARY, SQL_BINARY, BINARY_FIELD_MAX_SIZE,
0, (SQLPOINTER)Data, BINARY_FIELD_MAX_SIZE, &ind))
{
return DBBinary;
}
if (SQL_ERROR == SQLExecute(hStmt))
{
return DBBinary;
}
SQLLEN sqlLen;
DBBinary.Begin();
while (SQL_SUCCESS == SQLFetch(hStmt))
{
if (!m_pDatabase->IsOpen())
{
DBBinary.SetCurUsedSize(-1);
return DBBinary;
}
if (SQL_ERROR == SQLGetData(hStmt, 1, SQL_BINARY, (SQLPOINTER)Data, BINARY_FIELD_MAX_SIZE, &sqlLen))
{
DBBinary.SetCurUsedSize(-1);
return DBBinary;
}
if (-1 == sqlLen)
{
if (0 != DBBinary.InsertData(Data, 0))
{
DBBinary.SetCurUsedSize(-1);
return DBBinary;
}
continue;
}
if (SQL_ERROR == SQLGetData(hStmt, 1, SQL_C_DEFAULT, (SQLPOINTER)Data, sqlLen, &ind))
{
DBBinary.SetCurUsedSize(-1);
return DBBinary;
}
if (sqlLen != DBBinary.InsertData(Data, sqlLen))
{
DBBinary.SetCurUsedSize(-1);
return DBBinary;
}
}
SQLFreeHandle(SQL_HANDLE_STMT, hStmt);
return DBBinary;
}
示例10: query_test
static void
query_test(int prepare, SQLRETURN expected, const char *expected_status)
{
#define DESC_LEN 51
#define ARRAY_SIZE 10
SQLUINTEGER *ids = XMALLOC_N(SQLUINTEGER,ARRAY_SIZE);
typedef SQLCHAR desc_t[DESC_LEN];
desc_t *descs = XMALLOC_N(desc_t, ARRAY_SIZE);
SQLLEN *id_lens = XMALLOC_N(SQLLEN,ARRAY_SIZE), *desc_lens = XMALLOC_N(SQLLEN,ARRAY_SIZE);
SQLUSMALLINT i, *statuses = XMALLOC_N(SQLUSMALLINT,ARRAY_SIZE);
unsigned *num_errors = XMALLOC_N(unsigned, ARRAY_SIZE);
SQLULEN processed;
RETCODE ret;
char status[20];
SQLTCHAR *err = ODBC_GET(sizeof(odbc_err)*sizeof(SQLTCHAR));
SQLTCHAR *state = ODBC_GET(sizeof(odbc_sqlstate)*sizeof(SQLTCHAR));
assert(odbc_stmt != SQL_NULL_HSTMT);
odbc_reset_statement();
odbc_command_with_result(odbc_stmt, "drop table #tmp1");
odbc_command("create table #tmp1 (id tinyint, value char(20))");
SQLSetStmtAttr(odbc_stmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
SQLSetStmtAttr(odbc_stmt, SQL_ATTR_PARAMSET_SIZE, (void *) ARRAY_SIZE, 0);
SQLSetStmtAttr(odbc_stmt, SQL_ATTR_PARAM_STATUS_PTR, statuses, 0);
SQLSetStmtAttr(odbc_stmt, SQL_ATTR_PARAMS_PROCESSED_PTR, &processed, 0);
SQLBindParameter(odbc_stmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, ids, 0, id_lens);
SQLBindParameter(odbc_stmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, DESC_LEN - 1, 0, descs, DESC_LEN, desc_lens);
processed = ARRAY_SIZE + 1;
for (i = 0; i < ARRAY_SIZE; i++) {
statuses[i] = SQL_PARAM_DIAG_UNAVAILABLE;
ids[i] = (i + 1) * multiply;
sprintf((char *) descs[i], "data %d", i * 7);
id_lens[i] = 0;
desc_lens[i] = SQL_NTS;
num_errors[i] = 0;
}
multiply = 90;
if (!prepare) {
ret = SQLExecDirect(odbc_stmt, test_query, SQL_NTS);
} else {
SQLPrepare(odbc_stmt, test_query, SQL_NTS);
ret = SQLExecute(odbc_stmt);
}
if (processed > ARRAY_SIZE) {
char buf[256];
sprintf(buf, "Invalid processed number: %d", (int) processed);
ODBC_REPORT_ERROR(buf);
}
for (i = 1; CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, i, state, NULL, err, sizeof(odbc_err), NULL, "SINo") != SQL_NO_DATA; ++i) {
SQLINTEGER row;
strcpy(odbc_err, C(err));
strcpy(odbc_sqlstate, C(state));
CHKGetDiagField(SQL_HANDLE_STMT, odbc_stmt, i, SQL_DIAG_ROW_NUMBER, &row, sizeof(row), NULL, "S");
if (row == SQL_ROW_NUMBER_UNKNOWN) continue;
if (row < 1 || row > ARRAY_SIZE) {
fprintf(stderr, "invalid row %d returned reading error number %d\n", (int) row, i);
exit(1);
}
++num_errors[row-1];
printf("for row %2d returned '%s' %s\n", (int) row, odbc_sqlstate, odbc_err);
}
for (i = 0; i < processed; ++i) {
int has_diag = 0;
switch (statuses[i]) {
case SQL_PARAM_SUCCESS_WITH_INFO:
has_diag = 1;
case SQL_PARAM_SUCCESS:
status[i] = 'V';
break;
case SQL_PARAM_ERROR:
has_diag = 1;
status[i] = '!';
break;
case SQL_PARAM_UNUSED:
status[i] = ' ';
break;
case SQL_PARAM_DIAG_UNAVAILABLE:
status[i] = '?';
break;
default:
fprintf(stderr, "Invalid status returned %d\n", statuses[i]);
exit(1);
}
if (has_diag) {
//.........这里部分代码省略.........
示例11: main
int main()
{
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret;
SQLCHAR outstr[1024];
SQLSMALLINT outstrlen;
// Aloocate an environment handle
ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
checkrc(ret,__LINE__);
//we need odbc3 support
SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
//ALLOCATE A Connection handle
ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
checkrc(ret,__LINE__);
// connect to the DSN mydsn
ret = SQLConnect (dbc,
(SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"),
(SQLCHAR *) "root",
(SQLSMALLINT) strlen ("root"),
(SQLCHAR *) "manager",
(SQLSMALLINT) strlen (""));
if(SQL_SUCCEEDED(ret))
{
printf("\nConnected to the Data Source..\n");
}
else
{
printf("error in connection\n");
ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
checkrc(ret,__LINE__);
ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
checkrc(ret,__LINE__);
return 1;
}
//******************************************************************
// TABLE CREATED
ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt);
checkrc(ret,__LINE__);
SQLCHAR table[200]=
"CREATE TABLE T1(F1 INT,F2 INT)";
ret = SQLPrepare(stmt,table,SQL_NTS);
checkrc(ret,__LINE__);
ret = SQLExecute(stmt);
printf("\nTABLE CREATED\n");
//****************************************************************
InsertTest(env,dbc,stmt);
//*****************************************************************
int ret1;
ret1=FetchTest(env,dbc,stmt);
//****************************************************************
ret = SQLPrepare(stmt,(unsigned char*)"drop table T1;",SQL_NTS);
checkrc(ret,__LINE__);
ret = SQLExecute(stmt);
checkrc(ret,__LINE__);
printf("Table 'T1' Dropped\n");
ret = SQLFreeHandle(SQL_HANDLE_STMT,stmt);
checkrc(ret,__LINE__);
ret = SQLDisconnect(dbc);
checkrc(ret,__LINE__);
ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
checkrc(ret,__LINE__);
ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
checkrc(ret,__LINE__);
if(ret1 == 0)return 1;
return 0;
}
示例12: TestSQLFetch
//.........这里部分代码省略.........
}
else
{
TEST_FAILED;
LogMsg(ERRMSG,_T("expect: '%s' and actual: '%s' of column %d are not match, at line %d\n"),CResults[j],CCharOutput2,j+1,__LINE__);
}
}
}
SQLFreeStmt(hstmt,SQL_CLOSE);
TESTCASE_END;
h++;
}
k++;
}//End while
SQLExecDirect(hstmt,(SQLTCHAR*) ExecDirStr[0],SQL_NTS); /* cleanup */
//============================================================================================
TESTCASE_BEGIN("Testcase for Mode_special_1\n");
returncode = SQLExecDirect(hstmt,sqlstring0,SQL_NTS);
returncode = SQLExecDirect(hstmt,sqlstring1,SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode = SQLExecDirect(hstmt,sqlstring2,SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecDirect"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode = SQLPrepare(hstmt,sqlstring3,SQL_NTS);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLPrepare"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode = SQLBindCol(hstmt,1,SQL_C_TCHAR,CCharOutput2,300,NULL);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode = SQLExecute(hstmt);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLExecute"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
returncode = SQLFetch(hstmt);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFetch"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
TEST_RETURN;
}
#ifndef _WM
if (_tcscmp(CCharOutput2,_T("125.2")) == 0)
{
LogMsg(NONE,_T("expect: '125.2' and actual: '%s' are matched\n"),CCharOutput2);
}
else
{
TEST_FAILED;
LogMsg(ERRMSG,_T("expect: '125.2' and actual: '%s' are not match, at line %d\n"),CCharOutput2,__LINE__);
}
#else
if (_tcscmp(CCharOutput2,"125.28") == 0)
{
LogMsg(NONE,_T("expect: '125.28' and actual: '%s' are matched\n"),CCharOutput2);
}
else
{
TEST_FAILED;
LogMsg(ERRMSG,_T("expect: '125.28' and actual: '%s' are not match, at line %d\n"),CCharOutput2,__LINE__);
}
#endif
//============================================================================================
FullDisconnect(pTestInfo);
LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLFetch.\n"));
free_list(var_list);
TEST_RETURN;
}
示例13: SWITCH_DECLARE
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line,
switch_odbc_handle_t *handle,
const char *sql, switch_core_db_callback_func_t callback, void *pdata,
char **err)
{
#ifdef SWITCH_HAVE_ODBC
SQLHSTMT stmt = NULL;
SQLSMALLINT c = 0, x = 0;
SQLLEN m = 0;
char *err_str = NULL;
int result;
int err_cnt = 0;
int done = 0;
switch_assert(callback != NULL);
if (!db_is_up(handle)) {
goto error;
}
if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
err_str = strdup("Unable to SQL allocate handle.");
goto error;
}
if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
err_str = strdup("Unable to prepare SQL statement.");
goto error;
}
result = SQLExecute(stmt);
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO && result != SQL_NO_DATA) {
goto error;
}
SQLNumResultCols(stmt, &c);
SQLRowCount(stmt, &m);
while (!done) {
int name_len = 256;
char **names;
char **vals;
int y = 0;
result = SQLFetch(stmt);
if (result != SQL_SUCCESS) {
if (result != SQL_NO_DATA) {
err_cnt++;
}
break;
}
names = calloc(c, sizeof(*names));
vals = calloc(c, sizeof(*vals));
switch_assert(names && vals);
for (x = 1; x <= c; x++) {
SQLSMALLINT NameLength = 0, DataType = 0, DecimalDigits = 0, Nullable = 0;
SQLULEN ColumnSize = 0;
names[y] = malloc(name_len);
memset(names[y], 0, name_len);
SQLDescribeCol(stmt, x, (SQLCHAR *) names[y], (SQLSMALLINT) name_len, &NameLength, &DataType, &ColumnSize, &DecimalDigits, &Nullable);
if (!ColumnSize) {
ColumnSize = 255;
}
ColumnSize++;
vals[y] = malloc(ColumnSize);
memset(vals[y], 0, ColumnSize);
SQLGetData(stmt, x, SQL_C_CHAR, (SQLCHAR *) vals[y], ColumnSize, NULL);
y++;
}
if (callback(pdata, y, vals, names)) {
done = 1;
}
for (x = 0; x < y; x++) {
free(names[x]);
free(vals[x]);
}
free(names);
free(vals);
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
if (!err_cnt) {
return SWITCH_ODBC_SUCCESS;
}
error:
if (stmt) {
//.........这里部分代码省略.........
示例14: db_is_up
static int db_is_up(switch_odbc_handle_t *handle)
{
int ret = 0;
SQLHSTMT stmt = NULL;
SQLLEN m = 0;
int result;
switch_event_t *event;
switch_odbc_status_t recon = 0;
char *err_str = NULL;
SQLCHAR sql[255] = "";
int max_tries = 120;
int code = 0;
SQLRETURN rc;
SQLSMALLINT nresultcols;
top:
if (!handle) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "No DB Handle\n");
goto done;
}
if (handle->is_firebird) {
strcpy((char *) sql, "select first 1 * from RDB$RELATIONS");
} else {
strcpy((char *) sql, "select 1");
}
if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
code = __LINE__;
goto error;
}
if (SQLPrepare(stmt, sql, SQL_NTS) != SQL_SUCCESS) {
code = __LINE__;
goto error;
}
result = SQLExecute(stmt);
if (result != SQL_SUCCESS && result != SQL_SUCCESS_WITH_INFO) {
code = __LINE__;
goto error;
}
SQLRowCount(stmt, &m);
rc = SQLNumResultCols(stmt, &nresultcols);
if (rc != SQL_SUCCESS) {
code = __LINE__;
goto error;
}
ret = (int) nresultcols;
/* determine statement type */
if (nresultcols <= 0) {
/* statement is not a select statement */
code = __LINE__;
goto error;
}
goto done;
error:
err_str = switch_odbc_handle_get_error(handle, stmt);
recon = switch_odbc_handle_connect(handle);
max_tries--;
if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Failure-Message", "The sql server is not responding for DSN %s [%s][%d]",
switch_str_nil(handle->dsn), switch_str_nil(err_str), code);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The sql server is not responding for DSN %s [%s][%d]\n",
switch_str_nil(handle->dsn), switch_str_nil(err_str), code);
if (recon == SWITCH_ODBC_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection has been re-established");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "The connection has been re-established\n");
} else {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "The connection could not be re-established");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The connection could not be re-established\n");
}
if (!max_tries) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Additional-Info", "Giving up!");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Giving up!\n");
}
switch_event_fire(&event);
}
if (!max_tries) {
goto done;
}
switch_safe_free(err_str);
switch_yield(1000000);
goto top;
done:
switch_safe_free(err_str);
//.........这里部分代码省略.........
示例15: __declspec
//.........这里部分代码省略.........
SQLBindCol(hstmt, 1, SQL_C_ULONG, &LinkID, 0, NULL);
SQLBindCol(hstmt, 2, SQL_C_USHORT, &(LinkAddr.zone), 0, NULL);
SQLBindCol(hstmt, 3, SQL_C_USHORT, &(LinkAddr.net), 0, NULL);
SQLBindCol(hstmt, 4, SQL_C_USHORT, &(LinkAddr.node), 0, NULL);
SQLBindCol(hstmt, 5, SQL_C_WCHAR, Ip, 512, NULL);
sqlret = SQLFetch(hstmt);
while ((sqlret == SQL_SUCCESS) || (sqlret == SQL_SUCCESS_WITH_INFO))
{
//
res = GetAddrInfoW(Ip, L"24554", &hints, &result);
if (res == 0)
{
memcpy(&(LinksTable[i].sa), result->ai_addr, sizeof(struct sockaddr_in));
// printf("%u %u %S %u.%u.%u.%u\n", i,LinkID, Ip, LinksTable[i].sa.sin_addr.S_un.S_un_b.s_b1, LinksTable[i].sa.sin_addr.S_un.S_un_b.s_b2, LinksTable[i].sa.sin_addr.S_un.S_un_b.s_b3, LinksTable[i].sa.sin_addr.S_un.S_un_b.s_b4);
LinksTable[i].LinkID = LinkID;
LinksTable[i].LinkAddr.FullAddr = LinkAddr.FullAddr;
LinksTable[i].s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
EventsTable[i] = WSACreateEvent();
WSAEventSelect(LinksTable[i].s, EventsTable[i], FD_CONNECT);
FreeAddrInfoW(result);
++i;
}
else
{
wsprintfW(LogStr,L"%u:%u/%u: Ip address %s cannot be resolved", LinkAddr.zone, LinkAddr.net, LinkAddr.node,Ip);
AddLogEntry(LogStr);
}
sqlret = SQLFetch(hstmt);
}
}
SQLCloseCursor(hstmt);
SQLFreeStmt(hstmt, SQL_UNBIND);
NumOfLinks = i;
for (i = 0; i < NumOfLinks; i++)
{
connect(LinksTable[i].s, (struct sockaddr *)&(LinksTable[i].sa), sizeof(struct sockaddr_in));
}
j = 0;
SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &LinkID, 0, NULL);
SQLPrepareW(hstmt, L"Update Links set DialOut=1 where LinkID=?", SQL_NTS);
while (j < NumOfLinks)
{
res = WSAWaitForMultipleEvents(NumOfLinks, EventsTable, FALSE, WSA_INFINITE, FALSE);
WSAEnumNetworkEvents(LinksTable[res].s, EventsTable[res], &evt);
shutdown(LinksTable[res].s, SD_BOTH);
closesocket(LinksTable[res].s);
if (evt.iErrorCode[FD_CONNECT_BIT] == 0)
{
wsprintfW(LogStr, L"%u:%u/%u: OK", LinksTable[res].LinkAddr.zone, LinksTable[res].LinkAddr.net, LinksTable[res].LinkAddr.node);
LinkID = LinksTable[res].LinkID;
SQLExecute(hstmt);
}
else
{
switch (evt.iErrorCode[FD_CONNECT_BIT])
{
case WSAECONNREFUSED:
wsprintfW(LogStr, L"%u:%u/%u: Connection refused", LinksTable[res].LinkAddr.zone, LinksTable[res].LinkAddr.net, LinksTable[res].LinkAddr.node);
break;
case WSAETIMEDOUT:
wsprintfW(LogStr, L"%u:%u/%u: Connection timed out", LinksTable[res].LinkAddr.zone, LinksTable[res].LinkAddr.net, LinksTable[res].LinkAddr.node);
break;
default:wsprintfW(LogStr, L"%u:%u/%u: Unknown connection error", LinksTable[res].LinkAddr.zone, LinksTable[res].LinkAddr.net, LinksTable[res].LinkAddr.node);
}
}
AddLogEntry(LogStr);
++j;
}
//
for (j = 0; j < NumOfLinks; j++)
{
WSACloseEvent(EventsTable[j]);
}
SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
//
WSACleanup();
HeapDestroy(hHeap);
exit:
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
AddLogEntry(L"Links alive check done");
SetEvent(cfg.hLinksUpdateEvent);
return TRUE;
}