本文整理汇总了C++中SQLFetch函数的典型用法代码示例。如果您正苦于以下问题:C++ SQLFetch函数的具体用法?C++ SQLFetch怎么用?C++ SQLFetch使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SQLFetch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_rows
static void
test_rows(void)
{
const rows_set_t *p;
SQLULEN len;
SQLUINTEGER *ids = MALLOC_N(SQLUINTEGER,ARRAY_SIZE);
SQLLEN *id_lens = MALLOC_N(SQLLEN,ARRAY_SIZE);
unsigned long int h, l;
unsigned int n;
for (n = 0; n < ARRAY_SIZE; ++n) {
ids[n] = n;
id_lens[n] = 0;
}
/* test setting just some test pointers */
set_ird_params1(int2ptr(0x01020304));
check_ird_params();
set_ird_params2(int2ptr(0xabcdef12));
check_ird_params();
/* now see results */
for (p = row_set; ; ++p) {
const char *test_name = NULL;
odbc_reset_statement();
len = 0xdeadbeef;
len <<= 16;
len <<= 16;
len |= 12345678;
if (*p)
(*p)(&len);
check_ird_params();
#if 0
CHKSetStmtAttr(SQL_ATTR_PARAMSET_SIZE, (void *) int2ptr(ARRAY_SIZE), 0, "S");
CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 5, 0, ids, 0, id_lens, "S");
#endif
CHKBindCol(1, SQL_C_ULONG, ids, 0, id_lens, "S");
if (*p) {
CHKSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, (void *) int2ptr(ARRAY_SIZE), 0, "S");
odbc_command("SELECT DISTINCT i FROM #tmp1");
SQLFetch(odbc_stmt);
test_name = "SQLSetStmtAttr";
} else {
CHKSetStmtAttr(SQL_ROWSET_SIZE, (void *) int2ptr(ARRAY_SIZE), 0, "S");
odbc_command("SELECT DISTINCT i FROM #tmp1");
CHKExtendedFetch(SQL_FETCH_NEXT, 0, &len, NULL, "S");
test_name = "SQLExtendedFetch";
}
SQLMoreResults(odbc_stmt);
l = len;
len >>= 16;
h = len >> 16;
l &= 0xfffffffflu;
if (h != 0 || l != 2) {
fprintf(stderr, "Wrong number returned in rows high %lu(0x%lx) low %lu(0x%lx) test %s\n", h, h, l, l, test_name);
exit(1);
}
if (!*p)
break;
}
free(ids);
free(id_lens);
}
示例2: TestSQLTransact
//.........这里部分代码省略.........
TESTCASE_BEGINW(Heading);
//MAY 9, 2014 - TURNING AUTOCOMMIT ON FOR DDLs FOR TRAF, AS DDLs ARE NOT SUPPORTED WITH AUTOCOMMIT OFF
if (i == 4 || i == 0)
SQLSetConnectOption((SQLHANDLE)hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[i],SQL_NTS);
SQLSetConnectOption((SQLHANDLE)hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
if (!CHECKRC(SQL_SUCCESS, returncode, "SQLExecDirect"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
}
else
{
returncode=SQLTransact((SQLHANDLE)henv,(SQLHANDLE)hdbc,fType[j]);
Sleep(2); // tmf rollback is slower.
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLTransact"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
}
returncode = SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[iend],SQL_NTS);
if(!CHECKRC(CheckRes[i].ExeRes[j],returncode,"SQLExecDirect"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
}
else
{
if (returncode == SQL_SUCCESS || returncode == SQL_SUCCESS_WITH_INFO)
{
Output = (TCHAR *)malloc(NAME_LEN);
returncode=SQLBindCol(hstmt,1,SQL_C_TCHAR,Output,NAME_LEN,&OutputLen);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLBindCol"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
}
else
{
returncode = SQLFetch(hstmt);
if(!CHECKRC(CheckRes[i].FetchRes[j],returncode,"SQLFetch"))
{
LogAllErrors(henv,hdbc,hstmt);
TEST_FAILED;
}
else
{
if (returncode != SQL_NO_DATA_FOUND && returncode != SQL_ERROR)
{
if (_tcscspn(CheckRes[i].DataRes[j],Output) == 0)
{
LogMsg(NONE,_T("expect: %s and actual: %s are matched\n"),Output,CheckRes[i].DataRes[j]);
}
else
{
LogMsg(NONE,_T("expect: %s and actual: %s are not matched\n"),Output,CheckRes[i].DataRes[j]);
TEST_FAILED;
}
}
}
free(Output);
SQLFreeStmt(hstmt,SQL_CLOSE);
}
}
}
}
TESTCASE_END;
}/* end j loop */
}/* end i loop */
}
//========================================================================================================
SQLExecDirect(hstmt,(SQLTCHAR*)ExecDirStr[4],SQL_NTS); /* CLEANUP */
returncode = SQLDisconnect((SQLHANDLE)hdbc);
if(!CHECKRC(SQL_ERROR,returncode,"SQLDisconnect"))
{
LogAllErrorsVer3(henv,hdbc,hstmt);
TEST_FAILED;
}
// Free the open transactions.
returncode=SQLTransact((SQLHANDLE)henv,(SQLHANDLE)hdbc,SQL_ROLLBACK);
Sleep(2);
returncode=FullDisconnect(pTestInfo);
if(!CHECKRC(SQL_SUCCESS,returncode,"SQLFullDisconnect"))
{
LogAllErrorsVer3(henv,hdbc,hstmt);
TEST_FAILED;
}
LogMsg(SHORTTIMESTAMP+LINEAFTER,_T("End testing API => SQLTransact.\n"));
free_list(var_list);
TEST_RETURN;
}
示例3: f_sql_fetch
svalue_t *
f_sql_fetch( svalue_t * argv, int argc )
{
#if ODBC_DEBUG & DEBUG_FUNC
printf( "call f_sql_fetch( )\n" );
#endif
int id, method = 0;
hDBC * handle;
SQLRETURN ret;
STORE_DOUBLE_USED;
switch( argc ) {
case 2 :
TYPE_TEST2( argv, T_NUMBER );
method = argv->u.number;
free_svalue( argv );
argv--;
case 1 :
TYPE_TEST1( argv, T_NUMBER );
id = argv->u.number;
free_svalue( argv );
break;
default:
errorf( "Too many arguments to sql_fetch().\n" );
return( NULL );
}
if ( !(handle = get_db_connection_by_id( id )) ) {
errorf( "Illegal handle for database.\n" );
return( NULL );
}
if ( !handle->hStmt ) {
put_number( argv, 0 );
return( argv );
}
//printf( "\nFetching ....\n" );
ret = SQLFetch( handle->hStmt );
if ( ret == SQL_NO_DATA ) {
//printf( "NO_DATA\n" );
put_number( argv, 0 );
return( argv );
} else if ( !SQL_SUCCEEDED( ret ) ) {
put_number( argv, 0 );
return( argv );
}
if ( !handle->columns ) {
put_number( argv, 0 );
return( argv );
}
if ( !method ) { //fetch as array
put_array( argv, fetch_into_vector( handle ) );
} else { //fetch as mapping
put_mapping( argv, fetch_into_mapping( handle ) );
}
#if ODBC_DEBUG & DEBUG_FUNC
printf( "ret f_sql_fetch( )\n" );
#endif
return( argv );
}
示例4: ODBC_Test
//.........这里部分代码省略.........
/*
* Print header field
*/
#ifdef UNICODE
printf ("%-*.*S", displayWidth, displayWidth, colName);
#else
printf ("%-*.*s", displayWidth, displayWidth, colName);
#endif
if (colNum < numCols)
putchar ('|');
}
putchar ('\n');
/*
* Print second line
*/
for (colNum = 1; colNum <= numCols; colNum++)
{
for (i = 0; i < displayWidths[colNum - 1]; i++)
putchar ('-');
if (colNum < numCols)
putchar ('+');
}
putchar ('\n');
/*
* Print all the fields
*/
totalRows = 0;
while (1)
{
#if (ODBCVER < 0x0300)
int sts = SQLFetch (hstmt);
#else
int sts = SQLFetchScroll (hstmt, SQL_FETCH_NEXT, 1);
#endif
if (sts == SQL_NO_DATA_FOUND)
break;
if (sts != SQL_SUCCESS)
{
ODBC_Errors ("Fetch");
break;
}
for (colNum = 1; colNum <= numCols; colNum++)
{
/*
* Fetch this column as character
*/
#ifdef UNICODE
sts = SQLGetData (hstmt, colNum, SQL_C_WCHAR, fetchBuffer,
NUMTCHAR (fetchBuffer), &colIndicator);
#else
sts = SQLGetData (hstmt, colNum, SQL_C_CHAR, fetchBuffer,
NUMTCHAR (fetchBuffer), &colIndicator);
#endif
if (sts != SQL_SUCCESS_WITH_INFO && sts != SQL_SUCCESS)
{
ODBC_Errors ("SQLGetData");
goto endCursor;
}
/*
* Show NULL fields as ****
示例5: SQLAllocHandle
void
PeterRoosenTracksConverter::run_converter(bool status)
{
SQLRETURN sql_return;
SQLHSTMT hstmt;
sql_return = SQLAllocHandle(SQL_HANDLE_STMT, _connection, &hstmt);
if (sql_return != SQL_SUCCESS)
{
std::cout << "Allocating statement handle failed." << std::endl;
}
double x1, y1, x2, y2;
SQLINTEGER x1_ind, y1_ind, x2_ind, y2_ind;
sql_return = SQLBindCol(hstmt, 1, SQL_C_DOUBLE, &x1, sizeof(double), &x1_ind);
if (sql_return != SQL_SUCCESS)
{
std::cout << "Binding to column 1 failed." << std::endl;
}
sql_return = SQLBindCol(hstmt, 2, SQL_C_DOUBLE, &y1, sizeof(double), &y1_ind);
if (sql_return != SQL_SUCCESS)
{
std::cout << "Binding to column 2 failed." << std::endl;
}
sql_return = SQLBindCol(hstmt, 3, SQL_C_DOUBLE, &x2, sizeof(double), &x2_ind);
if (sql_return != SQL_SUCCESS)
{
std::cout << "Binding to column 3 failed." << std::endl;
}
sql_return = SQLBindCol(hstmt, 4, SQL_C_DOUBLE, &y2, sizeof(double), &y2_ind);
if (sql_return != SQL_SUCCESS)
{
std::cout << "Binding to column 4 failed." << std::endl;
}
std::string stmt_string("SELECT x1, y1, x2, y2 FROM tracks WHERE id < 100000 ORDER BY id ASC;");
sql_return = SQLExecDirect(hstmt, (SQLCHAR*)(stmt_string.c_str()), SQL_NTS);
if (sql_return != SQL_SUCCESS)
{
std::cout << "Executing SQL statement failed." << std::endl;
}
// init positions:
double old_x1 = -1.0;
double old_x2 = -1.0;
double old_y1 = -1.0;
double old_y2 = -1.0;
enum CoordOrder
{
COORD_ORDER_1TO2,
COORD_ORDER_2TO1,
UNKNOWN
};
CoordOrder coord_order = UNKNOWN;
// done.
// init time (to 2000-01-01 00:00:00):
tm* current_time = new tm;
current_time->tm_sec = 0;
current_time->tm_min = 0;
current_time->tm_hour = 0;
current_time->tm_mday = 1;
current_time->tm_mon = 0;
current_time->tm_year = 100;
time_t count = mktime(current_time);
// done.
// init and open output file:
std::ofstream output_file;
output_file.setf(std::ios::fixed);
output_file.precision(4);
std::string init_filename(_output_file);
init_filename.append("0");
output_file.open(init_filename.c_str());
int file_counter = 1;
// done.
// init step size:
const int STEP_SIZE = 10;
// done.
// loop over result set:
while ( (sql_return = SQLFetch(hstmt)) != SQL_NO_DATA)
{
if ( (status) && (file_counter % 10000 == 0) )
std::cout << file_counter << std::endl;
if (sql_return == SQL_ERROR)
std::cout << "Fetching column " << count + 1
<< " failed." << std::endl;
/* if (output_file.tellp() >= _max_output_file_size)
{
output_file.close();
//.........这里部分代码省略.........
示例6: TbListTablePrivileges
/* get the privileges for tables that meet specified criteria */
int TbListTablePrivileges(SQLHANDLE hdbc)
{
SQLRETURN cliRC = SQL_SUCCESS;
int rc = 0;
SQLHANDLE hstmt; /* statement handle */
struct
{
SQLINTEGER ind;
SQLCHAR val[129];
}
tbSchema, tbName, grantor, grantee, privilege;
struct
{
SQLINTEGER ind;
SQLCHAR val[4];
}
is_grantable;
/* criteria look for */
SQLCHAR tbSchemaPattern[] = "%";
SQLCHAR tbNamePattern[] = "ORG";
printf("\n-----------------------------------------------------------");
printf("\nUSE THE CLI FUNCTIONS\n");
printf(" SQLSetConnectAttr\n");
printf(" SQLAllocHandle\n");
printf(" SQLTablePrivileges\n");
printf(" SQLBindCol\n");
printf(" SQLFetch\n");
printf(" SQLFreeHandle\n");
printf("TO GET PRIVILEGES FOR TABLES THAT MEET SPECIFIED CRITERIA:\n");
/* set AUTOCOMMIT on */
cliRC = SQLSetConnectAttr(hdbc,
SQL_ATTR_AUTOCOMMIT,
(SQLPOINTER)SQL_AUTOCOMMIT_ON,
SQL_NTS);
DBC_HANDLE_CHECK(hdbc, cliRC);
/* allocate a statement handle */
cliRC = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
DBC_HANDLE_CHECK(hdbc, cliRC);
/* call SQLTablePrivileges */
printf("\n Call SQLTablePrivileges for:\n");
printf(" tbSchemaPattern = %s\n", tbSchemaPattern);
printf(" tbNamePattern = %s\n", tbNamePattern);
/* get privileges associated with a table */
cliRC = SQLTablePrivileges(hstmt,
NULL,
0,
tbSchemaPattern,
SQL_NTS,
tbNamePattern,
SQL_NTS);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 2 to variable */
cliRC = SQLBindCol(hstmt, 2, SQL_C_CHAR, tbSchema.val, 129, &tbSchema.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 3 to variable */
cliRC = SQLBindCol(hstmt, 3, SQL_C_CHAR, tbName.val, 129, &tbName.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 4 to variable */
cliRC = SQLBindCol(hstmt,
4,
SQL_C_CHAR,
(SQLPOINTER)grantor.val,
129,
&grantor.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 5 to variable */
cliRC = SQLBindCol(hstmt,
5,
SQL_C_CHAR,
(SQLPOINTER)grantee.val,
129,
&grantee.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 6 to variable */
cliRC = SQLBindCol(hstmt,
6,
SQL_C_CHAR,
(SQLPOINTER)privilege.val,
129,
&privilege.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 7 to variable */
cliRC = SQLBindCol(hstmt,
7,
SQL_C_CHAR,
//.........这里部分代码省略.........
示例7: WriteBodyDelimited
static void WriteBodyDelimited( SQLHSTMT hStmt, char cDelimiter )
{
SQLINTEGER nCol = 0;
SQLSMALLINT nColumns = 0;
SQLLEN nIndicator = 0;
SQLCHAR szColumnValue[MAX_DATA_WIDTH+1];
SQLRETURN nReturn = 0;
SQLRETURN ret;
SQLINTEGER *types;
*szColumnValue = '\0';
if ( SQLNumResultCols( hStmt, &nColumns ) != SQL_SUCCESS )
nColumns = -1;
if ( bQuote && nColumns > 0 )
{
types = malloc( nColumns * sizeof ( SQLINTEGER ));
for ( nCol = 1; nCol <= nColumns && types; nCol++ )
{
SQLSMALLINT type = 0;
nReturn = SQLDescribeCol( hStmt, nCol, NULL, 0, NULL, &type, NULL, NULL, NULL );
switch ( type )
{
case SQL_CHAR:
case SQL_VARCHAR:
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_LONGVARCHAR:
case SQL_WLONGVARCHAR:
types[ nCol - 1 ] = 1;
break;
default:
types[ nCol - 1 ] = 0;
break;
}
}
}
else
{
types = NULL;
}
/* ROWS */
while (( ret = SQLFetch( hStmt )) == SQL_SUCCESS )
{
/* COLS */
for ( nCol = 1; nCol <= nColumns; nCol++ )
{
nReturn = SQLGetData( hStmt, nCol, SQL_C_CHAR, (SQLPOINTER)szColumnValue, sizeof(szColumnValue), &nIndicator );
if ( nReturn == SQL_SUCCESS && nIndicator != SQL_NULL_DATA )
{
if ( types && types[ nCol - 1 ] )
{
putchar( '"' );
}
fputs((char*) szColumnValue, stdout );
if ( types && types[ nCol - 1 ] )
{
putchar( '"' );
}
if ( nCol < nColumns )
{
putchar( cDelimiter );
}
}
else if ( nReturn == SQL_ERROR )
{
ret = SQL_ERROR;
break;
}
else
{
if ( nCol < nColumns )
{
putchar( cDelimiter );
}
}
}
if (ret != SQL_SUCCESS)
{
break;
}
printf( "\n" );
}
if ( ret == SQL_ERROR )
{
if ( bVerbose ) DumpODBCLog( 0, 0, hStmt );
}
if ( types )
{
free( types );
}
}
示例8: RecvCMD_SET_COMMANDER
void RecvCMD_SET_COMMANDER(t_packet *p, t_connection c[], int cn ) // 사령관의 데이터를 세트한다.
{
NW_Character tempNWCharacter;
DWORD tempDWORD;
HSTMT hStmt=NULL;
RETCODE ret;
SWORD nClos;
char query_stmt[80]={0,};
SDWORD cbValue;
SQLAllocStmt(hDBC,&hStmt);
wsprintf(query_stmt,"select fame_pk from chr_info where name='%s'",p->u.NationWar.SetCommander.CommanderName);
ret = SQLExecDirect(hStmt,(UCHAR*)query_stmt,SQL_NTS);
if (ret!=SQL_SUCCESS_WITH_INFO && ret !=SQL_SUCCESS)
{
MyLog(0,"Query Failure!! RecvCMD_SET_COMMANDER..");
SQLFreeStmt(hStmt,SQL_DROP);
return;
}
SQLNumResultCols(hStmt,&nClos);
ret=SQLFetch(hStmt);
if (ret!=SQL_SUCCESS_WITH_INFO && ret !=SQL_SUCCESS)
{
//MyLog(0,"WarField Fetch Error!!");
SQLFreeStmt(hStmt,SQL_DROP);
return ;
}
ret=SQLGetData(hStmt,1,SQL_C_SLONG,&tempDWORD,sizeof(int),&cbValue);
if (ret!=SQL_SUCCESS_WITH_INFO && ret!=SQL_SUCCESS)
{
MyLog(0,"SQL Return Error(%d)!!",ret);
SQLFreeStmt(hStmt,SQL_DROP);
return ;
}
SQLFreeStmt(hStmt,SQL_DROP);
memcpy(&tempNWCharacter,&tempDWORD,sizeof(DWORD));
tempNWCharacter.isCommander=1;
memcpy(&tempDWORD,&tempNWCharacter,sizeof(DWORD));
memcpy(&tempNWCharacter,&tempDWORD,sizeof(DWORD));
SQLAllocStmt(hDBC,&hStmt);
wsprintf(query_stmt,"update chr_info set fame_pk=%d where name='%s'",tempDWORD,p->u.NationWar.SetCommander.CommanderName);
ret=SQLExecDirect(hStmt,(UCHAR*)query_stmt,SQL_NTS);
if (ret!=SQL_SUCCESS_WITH_INFO && ret!=SQL_SUCCESS)
{
MyLog(0,"Update Query Failure!! RecvCMD_SET_COMMANDER..");
SQLFreeStmt(hStmt,SQL_DROP);
return;
}
SQLFreeStmt(hStmt,SQL_DROP);
}
示例9: main
int
main (int argc, char *argv[])
{
if (argc < 4)
{
fprintf (stderr,
"ERR : called as setcurs <dsn> <uid> <pwd> [<scroll>=1]\n");
exit (-3);
}
rc = SQLAllocEnv (&henv);
if (rc != SQL_SUCCESS)
{
fprintf (stderr, "ERR : cannot alloc ODBC environment\n");
exit (-3);
}
rc = SQLAllocConnect (henv, &hdbc);
CHK_ERR (SQL_NULL_HSTMT);
rc = SQLConnect (hdbc, argv[1], SQL_NTS, argv[2], SQL_NTS, argv[3],
SQL_NTS);
CHK_ERR (SQL_NULL_HSTMT);
/* Allocate the statements and set the cursor name. */
rc = SQLAllocStmt (hdbc, &hstmtSelect);
CHK_ERR (SQL_NULL_HSTMT);
rc = SQLAllocStmt (hdbc, &hstmtUpdate);
CHK_ERR (SQL_NULL_HSTMT);
if (argc <= 4 || atoi (argv[4]) != 0)
{
rc = SQLSetStmtOption (hstmtSelect, SQL_CURSOR_TYPE, SQL_CURSOR_STATIC);
CHK_ERR (hstmtSelect);
rc = SQLSetScrollOptions (hstmtSelect, SQL_CONCUR_READ_ONLY, 1, 1);
CHK_ERR (hstmtSelect);
}
rc = SQLSetCursorName (hstmtSelect, "C1", SQL_NTS);
CHK_ERR (hstmtSelect);
/* SELECT the result set and bind its columns to local buffers. */
rc = SQLExecDirect (hstmtSelect, "SELECT NAME,PHONE from GOGO", SQL_NTS);
CHK_ERR (hstmtSelect);
rc = SQLBindCol (hstmtSelect, 1, SQL_C_CHAR, szName, NAME_LEN, &cbName);
CHK_ERR (hstmtSelect);
rc = SQLBindCol (hstmtSelect, 2, SQL_C_CHAR, szPhone, PHONE_LEN, &cbPhone);
CHK_ERR (hstmtSelect);
/* Read through the result set until the cursor is */
/* positioned on the row for John Smith. */
do
retcode = SQLFetch (hstmtSelect);
while ((retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) &&
(strcmp (szName, "Smith, John") != 0));
rc = retcode;
CHK_ERR (hstmtSelect);
/* Perform a positioned update of John Smith's name. */
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
rc = SQLExecDirect (hstmtUpdate,
"UPDATE GOGO SET PHONE='2064890154' WHERE CURRENT OF C1", SQL_NTS);
CHK_ERR (hstmtUpdate);
}
#if 0
SQLFreeStmt (hstmtUpdate, SQL_DROP);
SQLFreeStmt (hstmtSelect, SQL_DROP);
SQLDisconnect (hdbc);
SQLFreeConnect (hdbc);
#endif
printf ("PASSED: SetCursorName Test\n");
exit (0);
}
示例10: backsql_get_attr_vals
static int
backsql_get_attr_vals( void *v_at, void *v_bsi )
{
backsql_at_map_rec *at = v_at;
backsql_srch_info *bsi = v_bsi;
backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
RETCODE rc;
SQLHSTMT sth = SQL_NULL_HSTMT;
BACKSQL_ROW_NTS row;
unsigned long i,
k = 0,
oldcount = 0,
res = 0;
#ifdef BACKSQL_COUNTQUERY
unsigned count,
j,
append = 0;
SQLLEN countsize = sizeof( count );
Attribute *attr = NULL;
slap_mr_normalize_func *normfunc = NULL;
#endif /* BACKSQL_COUNTQUERY */
#ifdef BACKSQL_PRETTY_VALIDATE
slap_syntax_validate_func *validate = NULL;
slap_syntax_transform_func *pretty = NULL;
#endif /* BACKSQL_PRETTY_VALIDATE */
assert( at != NULL );
assert( bsi != NULL );
#ifdef BACKSQL_ARBITRARY_KEY
Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
"oc=\"%s\" attr=\"%s\" keyval=%s\n",
BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val,
bsi->bsi_c_eid->eid_keyval.bv_val );
#else /* ! BACKSQL_ARBITRARY_KEY */
Debug( LDAP_DEBUG_TRACE, "==>backsql_get_attr_vals(): "
"oc=\"%s\" attr=\"%s\" keyval=%ld\n",
BACKSQL_OC_NAME( bsi->bsi_oc ), at->bam_ad->ad_cname.bv_val,
bsi->bsi_c_eid->eid_keyval );
#endif /* ! BACKSQL_ARBITRARY_KEY */
#ifdef BACKSQL_PRETTY_VALIDATE
validate = at->bam_true_ad->ad_type->sat_syntax->ssyn_validate;
pretty = at->bam_true_ad->ad_type->sat_syntax->ssyn_pretty;
if ( validate == NULL && pretty == NULL ) {
return 1;
}
#endif /* BACKSQL_PRETTY_VALIDATE */
#ifdef BACKSQL_COUNTQUERY
if ( at->bam_true_ad->ad_type->sat_equality ) {
normfunc = at->bam_true_ad->ad_type->sat_equality->smr_normalize;
}
/* Count how many rows will be returned. This avoids memory
* fragmentation that can result from loading the values in
* one by one and using realloc()
*/
rc = backsql_Prepare( bsi->bsi_dbh, &sth, at->bam_countquery, 0 );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_vals(): "
"error preparing count query: %s\n",
at->bam_countquery, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
return 1;
}
rc = backsql_BindParamID( sth, 1, SQL_PARAM_INPUT,
&bsi->bsi_c_eid->eid_keyval );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_vals(): "
"error binding key value parameter\n", 0, 0, 0 );
SQLFreeStmt( sth, SQL_DROP );
return 1;
}
rc = SQLExecute( sth );
if ( ! BACKSQL_SUCCESS( rc ) ) {
Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_vals(): "
"error executing attribute count query '%s'\n",
at->bam_countquery, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
return 1;
}
SQLBindCol( sth, (SQLUSMALLINT)1, SQL_C_LONG,
(SQLPOINTER)&count,
(SQLINTEGER)sizeof( count ),
&countsize );
rc = SQLFetch( sth );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "backsql_get_attr_vals(): "
"error fetch results of count query: %s\n",
at->bam_countquery, 0, 0 );
backsql_PrintErrors( bi->sql_db_env, bsi->bsi_dbh, sth, rc );
SQLFreeStmt( sth, SQL_DROP );
//.........这里部分代码省略.........
示例11: retrieve_file
static void retrieve_file(char *dir)
{
int x = 0;
int res;
int fd=-1;
size_t fdlen = 0;
void *fdm = MAP_FAILED;
SQLHSTMT stmt;
char sql[256];
char fmt[80]="", empty[10] = "";
char *c;
SQLLEN colsize;
char full_fn[256];
struct odbc_obj *obj;
struct generic_prepare_struct gps = { .sql = sql, .param = dir };
obj = ast_odbc_request_obj(odbc_database, 1);
if (obj) {
do {
ast_copy_string(fmt, vmfmts, sizeof(fmt));
c = strchr(fmt, '|');
if (c)
*c = '\0';
if (!strcasecmp(fmt, "wav49"))
strcpy(fmt, "WAV");
snprintf(full_fn, sizeof(full_fn), "%s.%s", dir, fmt);
snprintf(sql, sizeof(sql), "SELECT recording FROM %s WHERE dir=? AND msgnum=-1", odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
break;
}
res = SQLFetch(stmt);
if (res == SQL_NO_DATA) {
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
break;
} else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
break;
}
fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, 0770);
if (fd < 0) {
ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
break;
}
res = SQLGetData(stmt, 1, SQL_BINARY, empty, 0, &colsize);
fdlen = colsize;
if (fd > -1) {
char tmp[1]="";
lseek(fd, fdlen - 1, SEEK_SET);
if (write(fd, tmp, 1) != 1) {
close(fd);
fd = -1;
break;
}
if (fd > -1)
fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
}
if (fdm != MAP_FAILED) {
memset(fdm, 0, fdlen);
res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
break;
}
}
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
} while (0);
ast_odbc_release_obj(obj);
} else
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
if (fdm != MAP_FAILED)
munmap(fdm, fdlen);
if (fd > -1)
close(fd);
return;
}
示例12: 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 );
//.........这里部分代码省略.........
示例13: backsql_dn2id
//.........这里部分代码省略.........
Debug( LDAP_DEBUG_TRACE,
" backsql_dn2id(\"%s\"): "
"upperdn=\"%s\"\n",
ndn->bv_val, upperdn, 0 );
ber_str2bv( upperdn, 0, 0, &tbbDN );
} else {
tbbDN = realndn;
}
}
rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &tbbDN );
if ( rc != SQL_SUCCESS) {
/* end TimesTen */
Debug( LDAP_DEBUG_TRACE, " backsql_dn2id(\"%s\"): "
"error binding dn=\"%s\" parameter:\n",
ndn->bv_val, tbbDN.bv_val, 0 );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
res = LDAP_OTHER;
goto done;
}
rc = SQLExecute( sth );
if ( rc != SQL_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, " backsql_dn2id(\"%s\"): "
"error executing query (\"%s\", \"%s\"):\n",
ndn->bv_val, bi->sql_id_query, tbbDN.bv_val );
backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
res = LDAP_OTHER;
goto done;
}
backsql_BindRowAsStrings_x( sth, &row, op->o_tmpmemctx );
rc = SQLFetch( sth );
if ( BACKSQL_SUCCESS( rc ) ) {
char buf[ SLAP_TEXT_BUFLEN ];
#ifdef LDAP_DEBUG
snprintf( buf, sizeof(buf),
"id=%s keyval=%s oc_id=%s dn=%s",
row.cols[ 0 ], row.cols[ 1 ],
row.cols[ 2 ], row.cols[ 3 ] );
Debug( LDAP_DEBUG_TRACE,
" backsql_dn2id(\"%s\"): %s\n",
ndn->bv_val, buf, 0 );
#endif /* LDAP_DEBUG */
res = LDAP_SUCCESS;
if ( id != NULL ) {
struct berval dn;
id->eid_next = NULL;
#ifdef BACKSQL_ARBITRARY_KEY
ber_str2bv_x( row.cols[ 0 ], 0, 1, &id->eid_id,
op->o_tmpmemctx );
ber_str2bv_x( row.cols[ 1 ], 0, 1, &id->eid_keyval,
op->o_tmpmemctx );
#else /* ! BACKSQL_ARBITRARY_KEY */
if ( lutil_atoulx( &id->eid_id, row.cols[ 0 ], 0 ) != 0 ) {
res = LDAP_OTHER;
goto done;
}
if ( lutil_atoulx( &id->eid_keyval, row.cols[ 1 ], 0 ) != 0 ) {
res = LDAP_OTHER;
goto done;
示例14: db_unixodbc_fetch_result
/*!
* \brief Gets a partial result set, fetch rows from a result
*
* Gets a partial result set, fetch a number of rows from a databae result.
* This function initialize the given result structure on the first run, and
* fetches the nrows number of rows. On subsequenting runs, it uses the
* existing result and fetches more rows, until it reaches the end of the
* result set. Because of this the result needs to be null in the first
* invocation of the function. If the number of wanted rows is zero, the
* function returns anything with a result of zero.
* \param _h structure representing the database connection
* \param _r pointer to a structure representing the result
* \param nrows number of fetched rows
* \return return zero on success, negative value on failure
*/
int db_unixodbc_fetch_result(const db1_con_t* _h, db1_res_t** _r, const int nrows)
{
int row_n = 0, i = 0, ret = 0, len;
SQLSMALLINT columns;
list* rows = NULL;
list* rowstart = NULL;
strn* temp_row = NULL;
if ((!_h) || (!_r) || nrows < 0)
{
LM_ERR("invalid parameter value\n");
return -1;
}
/* exit if the fetch count is zero */
if (nrows == 0) {
if (*_r)
db_free_result(*_r);
*_r = 0;
return 0;
}
/* On the first fetch for a query, allocate structures and get columns */
if(*_r == NULL) {
/* Allocate a new result structure */
*_r = db_new_result();
LM_DBG("just allocated a new db result structure");
if (*_r == NULL) {
LM_ERR("no memory left\n");
return -2;
}
/* Get columns names and count */
if (db_unixodbc_get_columns(_h, *_r) < 0) {
LM_ERR("getting column names failed\n");
db_free_columns(*_r);
return -2;
}
/* On subsequent fetch attempts, reuse already allocated structures */
} else {
LM_DBG("db result structure already exist, reusing\n");
/* free old rows */
if(RES_ROWS(*_r) != NULL)
db_free_rows(*_r);
RES_ROWS(*_r) = 0;
RES_ROW_N(*_r) = 0;
}
SQLNumResultCols(CON_RESULT(_h), (SQLSMALLINT *)&columns);
/* Now fetch nrows at most */
len = sizeof(db_row_t) * nrows;
RES_ROWS(*_r) = (struct db_row*)pkg_malloc(len);
if (!RES_ROWS(*_r)) {
LM_ERR("no memory left\n");
return -5;
}
LM_DBG("allocated %d bytes for RES_ROWS at %p\n", len, RES_ROWS(*_r));
LM_DBG("Now fetching %i rows at most\n", nrows);
while(SQL_SUCCEEDED(ret = SQLFetch(CON_RESULT(_h)))) {
/* Allocate a temporary row */
temp_row = db_unixodbc_new_cellrow(columns);
if (!temp_row) {
LM_ERR("no private memory left\n");
pkg_free(RES_ROWS(*_r));
pkg_free(*_r);
*_r = 0;
return -1;
}
LM_DBG("fetching %d columns for row %d...\n",columns, row_n);
for(i=0; i < columns; i++) {
LM_DBG("fetching column %d\n",i);
if (!db_unixodbc_load_cell(_h, i+1, temp_row + i, RES_TYPES(*_r)[i])) {
pkg_free(RES_ROWS(*_r));
db_unixodbc_free_cellrow(columns, temp_row);
pkg_free(*_r);
*_r = 0;
return -5;
}
}
//.........这里部分代码省略.........
示例15: TbListColumns
/* list columns that meet specified criteria */
int TbListColumns(SQLHANDLE hdbc)
{
SQLRETURN cliRC = SQL_SUCCESS;
int rc = 0;
SQLHANDLE hstmt; /* statement handle */
struct
{
SQLINTEGER ind;
SQLCHAR val[129];
}
colName, colType;
struct
{
SQLINTEGER ind;
SQLCHAR val[255];
}
colRemarks;
struct
{
SQLINTEGER ind;
SQLINTEGER val;
}
colLength;
struct
{
SQLINTEGER ind;
SQLSMALLINT val;
}
colScale, colNullable;
/* criteria to look for */
SQLCHAR tbSchemaPattern[] = "%";
SQLCHAR tbNamePattern[] = "STAFF";
SQLCHAR colNamePattern[] = "%";
printf("\n-----------------------------------------------------------");
printf("\nUSE THE CLI FUNCTIONS\n");
printf(" SQLSetConnectAttr\n");
printf(" SQLAllocHandle\n");
printf(" SQLColumns\n");
printf(" SQLBindCol\n");
printf(" SQLFetch\n");
printf(" SQLFreeHandle\n");
printf("TO SHOW HOW TO LIST COLUMNS THAT MEET SPECIFIED CRITERIA:\n");
/* set AUTOCOMMIT on */
cliRC = SQLSetConnectAttr(hdbc,
SQL_ATTR_AUTOCOMMIT,
(SQLPOINTER)SQL_AUTOCOMMIT_ON,
SQL_NTS);
DBC_HANDLE_CHECK(hdbc, cliRC);
/* allocate a statement handle */
cliRC = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
DBC_HANDLE_CHECK(hdbc, cliRC);
/* call SQLColumns */
printf("\n Call SQLColumns for:\n");
printf(" tbSchemaPattern = %s\n", tbSchemaPattern);
printf(" tbNamePattern = %s\n", tbNamePattern);
printf(" colNamePattern = %s\n", colNamePattern);
/* get column information for a table */
cliRC = SQLColumns(hstmt,
NULL,
0,
tbSchemaPattern,
SQL_NTS,
tbNamePattern,
SQL_NTS,
colNamePattern,
SQL_NTS);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 4 to variable */
cliRC = SQLBindCol(hstmt, 4, SQL_C_CHAR, colName.val, 129, &colName.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 6 to variable */
cliRC = SQLBindCol(hstmt, 6, SQL_C_CHAR, colType.val, 129, &colType.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 7 to variable */
cliRC = SQLBindCol(hstmt,
7,
SQL_C_LONG,
(SQLPOINTER)&colLength.val,
sizeof(colLength.val),
&colLength.ind);
STMT_HANDLE_CHECK(hstmt, hdbc, cliRC);
/* bind column 9 to variable */
cliRC = SQLBindCol(hstmt,
9,
SQL_C_SHORT,
//.........这里部分代码省略.........