本文整理汇总了C++中SQLGetData函数的典型用法代码示例。如果您正苦于以下问题:C++ SQLGetData函数的具体用法?C++ SQLGetData怎么用?C++ SQLGetData使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SQLGetData函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SQLGetData
// Get field as string
_tstring field_impl::as_string() const
{
if (is_null_flag != -1)
return str_buf;
SQLLEN sz_needed = 0;
SQLTCHAR small_buff[256];
RETCODE rc;
// Try with small buffer
is_null_flag = 0;
rc = SQLGetData(stmt_h, col_num, SQL_C_TCHAR, small_buff, sizeof(small_buff), &sz_needed);
if (TIODBC_SUCCESS_CODE(rc))
{
if (sz_needed == SQL_NULL_DATA) {
is_null_flag = 1;
return _tstring();
}
str_buf = sqltchar2ybstring(small_buff, "");
return str_buf;
}
else if (sz_needed > 0)
{
// A bigger buffer is needed
SQLINTEGER sz_buff = sz_needed + 1;
SQLTCHAR_buf buff(sz_buff);
SQLGetData(stmt_h, col_num, SQL_C_TCHAR, buff.data, sz_buff, &sz_needed);
str_buf = sqltchar2ybstring(buff.data, "");
return str_buf;
}
return _tstring(); // Empty
}
示例2: s
void classSpecialColumns::LoadColumns()
{
CursorScoper s(listView()) ;
SQLRETURN nReturn ;
SQLCHAR szColumnName[MAX_COLUMN_WIDTH];
SQLCHAR szColumnType[MAX_COLUMN_WIDTH];
SQLCHAR szColumnSize[MAX_COLUMN_WIDTH];
SQLCHAR szRemarks [MAX_COLUMN_WIDTH];
QString qsDesc ;
classColumn *pColumn = NULL ;
// CREATE A STATEMENT
StatementScoper stmt( hDbc ) ; if ( !stmt() ) return ;
// EXECUTE OUR SQL/CALL
if (!SQL_SUCCEEDED(nReturn=SQLSpecialColumns( stmt(), SQL_BEST_ROWID, 0, 0, (SQLCHAR*)qsLibrary.data(), SQL_NTS, (SQLCHAR*)qsTable.data(), SQL_NTS, SQL_SCOPE_SESSION, SQL_NULLABLE ) ) )
return my_msgBox( "classSpecialColumns", "SQLSpecialColumns", nReturn, NULL, NULL, stmt() ) ;
// GET RESULTS
while (SQL_SUCCEEDED(SQLFetch( stmt() ) ) )
{
if (!SQL_SUCCEEDED(SQLGetData( stmt(), 2, SQL_C_CHAR, &szColumnName[0], sizeof(szColumnName), 0 ) ) )
strcpy( (char *)szColumnName, "Unknown" );
if (!SQL_SUCCEEDED(SQLGetData( stmt(), 4, SQL_C_CHAR, &szColumnType[0], sizeof(szColumnType), 0 ) ) )
strcpy( (char *)szColumnType, "Unknown" );
if (!SQL_SUCCEEDED(SQLGetData( stmt(), 5, SQL_C_CHAR, &szColumnSize[0], sizeof(szColumnSize), 0 ) ) )
strcpy( (char *)szColumnSize, "Unknown" );
qsDesc.sprintf("Len=%s", QString((char*)szColumnSize).stripWhiteSpace().data() ) ;
listColumns.append( pColumn = new classColumn( this, pColumn, pCanvas, hDbc, QString((char*)szColumnName).stripWhiteSpace(), QString((char*)szColumnType).stripWhiteSpace(), qsDesc ) ) ;
}
}
示例3: GetAsString
std::string GetAsString() const
{
SQLINTEGER Needed = 0;
const unsigned BufSize = 256;
char SmallBuff[BufSize] = { 0 };
RETCODE Ret = SQLGetData(Stmt.GetHolder().GetHandle(), static_cast<SQLUSMALLINT>(Index), SQL_C_CHAR,
SmallBuff, BufSize,
//reinterpret_cast for x64
reinterpret_cast<SQLLEN *>(&Needed));
if (TIODBC_SUCCESS_CODE(Ret))
return std::string(SmallBuff);
if (Needed > 0)
{
SQLINTEGER Buff = Needed + 1;
std::vector<char> Data(Buff, 0);
Ret = SQLGetData(Stmt.GetHolder().GetHandle(), static_cast<SQLUSMALLINT>(Index), SQL_C_CHAR,
reinterpret_cast<SQLTCHAR *>(&Data.front()), Buff,
//reinterpret_cast for x64
reinterpret_cast<SQLLEN *>(&Needed));
if (TIODBC_SUCCESS_CODE(Ret))
return std::string(&Data[0], Data.size());
throw FieldException("Error get field", feErrorGetField);
}
return std::string();
}
示例4: main
int
main(int argc, char *argv[])
{
char buf[16];
Connect();
/* TODO test with VARCHAR too */
Command(Statement, "SELECT CONVERT(TEXT,'Prova')");
if (SQLFetch(Statement) != SQL_SUCCESS) {
printf("Unable to fetch row\n");
CheckReturn();
exit(1);
}
/* these 2 tests test an old severe BUG in FreeTDS */
if (SQLGetData(Statement, 1, SQL_C_CHAR, buf, 0, NULL) != SQL_SUCCESS_WITH_INFO) {
printf("Unable to get data 1\n");
CheckReturn();
exit(1);
}
if (SQLGetData(Statement, 1, SQL_C_CHAR, buf, 0, NULL) != SQL_SUCCESS_WITH_INFO) {
printf("Unable to get data 2\n");
CheckReturn();
exit(1);
}
if (SQLGetData(Statement, 1, SQL_C_CHAR, buf, 3, NULL) != SQL_SUCCESS_WITH_INFO) {
printf("Unable to get data \n");
CheckReturn();
exit(1);
}
if (strcmp(buf, "Pr") != 0) {
printf("Wrong data result 1\n");
exit(1);
}
if (SQLGetData(Statement, 1, SQL_C_CHAR, buf, 16, NULL) != SQL_SUCCESS) {
printf("Unable to get data \n");
CheckReturn();
exit(1);
}
if (strcmp(buf, "ova") != 0) {
printf("Wrong data result 2 res = '%s'\n", buf);
exit(1);
}
Disconnect();
printf("Done.\n");
return 0;
}
示例5: DoTest
static void
DoTest(int n)
{
int res;
SQLCHAR output[256];
SQLSMALLINT colType;
SQLULEN colSize;
SQLSMALLINT colScale, colNullable;
SQLLEN dataSize;
TIMESTAMP_STRUCT ts;
if (CommandWithResult(Statement, "select convert(datetime, '2002-12-27 18:43:21')") != SQL_SUCCESS)
ODBC_REPORT_ERROR("Unable to execute statement");
res = SQLFetch(Statement);
if (res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO)
ODBC_REPORT_ERROR("Unable to fetch row");
if (SQLDescribeCol(Statement, 1, output, sizeof(output), NULL, &colType, &colSize, &colScale, &colNullable) != SQL_SUCCESS)
ODBC_REPORT_ERROR("Error getting data");
if (n == 0) {
memset(&ts, 0, sizeof(ts));
if (SQLGetData(Statement, 1, SQL_C_TIMESTAMP, &ts, sizeof(ts), &dataSize) != SQL_SUCCESS) {
printf("Unable to get data col %d\n", 1);
CheckReturn();
exit(1);
}
sprintf((char *) output, "%04d-%02d-%02d %02d:%02d:%02d.000", ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
} else {
if (SQLGetData(Statement, 1, SQL_C_CHAR, output, sizeof(output), &dataSize) != SQL_SUCCESS) {
printf("Unable to get data col %d\n", 1);
CheckReturn();
exit(1);
}
}
printf("Date returned: %s\n", output);
if (strcmp((char *) output, "2002-12-27 18:43:21.000") != 0) {
printf("Invalid returned date\n");
exit(1);
}
res = SQLFetch(Statement);
if (res != SQL_NO_DATA)
ODBC_REPORT_ERROR("Unable to fetch row");
res = SQLCloseCursor(Statement);
if (!SQL_SUCCEEDED(res))
ODBC_REPORT_ERROR("Unable to close cursor");
}
示例6: SQLAllocStmt
void classTable::LoadColumns()
{
SQLHSTMT hstmt;
SQLRETURN nReturn = -1;
SQLCHAR szTableName[101] = "";
SQLCHAR szColumnName[101] = "";
SQLCHAR szColumnType[101] = "";
SQLCHAR szDescription[301] = "";
QString qsError;
classColumn *pColumn = NULL;
// CREATE A STATEMENT
nReturn = SQLAllocStmt( hDbc, &hstmt );
if ( nReturn != SQL_SUCCESS )
{
QMessageBox::warning( pCanvas, "Data Manager", "Failed to SQLAllocStmt" );
return;
}
// EXECUTE OUR SQL/CALL
strcpy( (char *)szTableName, qsName.data() );
if ( SQL_SUCCESS != (nReturn=SQLColumns( hstmt, 0, 0, 0, 0, szTableName, SQL_NTS, 0, 0 )) )
{
QMessageBox::warning( pCanvas, "Data Manager", "Failed to SQLColumns" );
return;
}
// GET RESULTS
nReturn = SQLFetch( hstmt );
while ( nReturn == SQL_SUCCESS || nReturn == SQL_SUCCESS_WITH_INFO )
{
szDescription[0] = '\0';
nReturn = SQLGetData( hstmt, SQLColumns_COLUMN_NAME, SQL_C_CHAR, &szColumnName[0], sizeof(szColumnName), 0 );
if ( nReturn != SQL_SUCCESS )
strcpy( (char *)szColumnName, "Unknown" );
nReturn = SQLGetData( hstmt, SQLColumns_TYPE_NAME, SQL_C_CHAR, &szColumnType[0], sizeof(szColumnType), 0 );
listColumns.append( pColumn = new classColumn( this, pColumn, pCanvas, hDbc, (char *)szColumnName, (char*)szColumnType, (char*)szDescription ) );
nReturn = SQLFetch( hstmt );
}
// FREE STATEMENT
nReturn = SQLFreeStmt( hstmt, SQL_DROP );
if ( nReturn != SQL_SUCCESS )
QMessageBox::warning( pCanvas, "Data Manager", "Failed to SQLFreeStmt" );
}
示例7: ring_vm_odbc_getdata
void ring_vm_odbc_getdata ( void *pPointer )
{
ring_odbc *pODBC ;
SQLINTEGER indicator ;
SQLUSMALLINT i ;
SQLRETURN ret ;
char *buf, *buf2 ;
int nSize ;
if ( RING_API_PARACOUNT != 2 ) {
RING_API_ERROR(RING_API_MISS2PARA);
return ;
}
if ( RING_API_ISPOINTER(1) && RING_API_ISNUMBER(2) ) {
pODBC = (ring_odbc *) RING_API_GETCPOINTER(1,RING_VM_POINTER_ODBC) ;
if ( pODBC == NULL ) {
return ;
}
i = (SQLUSMALLINT) RING_API_GETNUMBER(2) ;
nSize = 512 ;
buf = (char *) malloc(nSize) ;
if ( buf == NULL ) {
RING_API_ERROR(RING_OOM);
return ;
}
ret = SQLGetData(pODBC->stmt, i, SQL_C_CHAR,buf, nSize, &indicator);
if ( SQL_SUCCEEDED(ret) ) {
if ( indicator == SQL_NULL_DATA ) {
strcpy(buf,"NULL");
nSize = 4 ;
} else if ( (ret == SQL_SUCCESS_WITH_INFO) && (indicator > 512) ) {
nSize = 512+indicator ;
buf2 = (char *) realloc(buf , nSize);
if ( buf2 == NULL ) {
RING_API_ERROR(RING_OOM);
return ;
}
buf = buf2 ;
SQLGetData(pODBC->stmt, i, SQL_C_CHAR,buf+511, indicator+1, &indicator);
nSize = 511+indicator ;
} else {
nSize = indicator ;
}
RING_API_RETSTRING2(buf,nSize);
} else {
RING_API_RETNUMBER(0);
}
free( buf ) ;
} else {
RING_API_ERROR(RING_API_BADPARATYPE);
}
}
示例8: SMSD_Log
const char *SMSDODBC_GetString(GSM_SMSDConfig * Config, SQL_result *res, unsigned int field)
{
SQLLEN sqllen;
int size;
SQLRETURN ret;
char shortbuffer[1];
if (field > SMSD_ODBC_MAX_RETURN_STRINGS) {
SMSD_Log(DEBUG_ERROR, Config, "Field %d returning NULL, too many fields!", field);
return NULL;
}
/* Figure out string length */
ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, shortbuffer, 0, &sqllen);
if (!SQL_SUCCEEDED(ret)) {
SMSDODBC_LogError(Config, ret, SQL_HANDLE_STMT, res->odbc, "SQLGetData(string,0) failed");
return NULL;
}
/*
* This hack seems to be needed to avoid type breakage on Win64, don't ask me why.
*
* Might be actually bug in MinGW compiler, but when using SQLLEN type bellow
* anything fails (it does not match to SQL_NULL_DATA and realloc always fails).
*/
size = sqllen;
/* Did not we get NULL? */
if (size == SQL_NULL_DATA) {
SMSD_Log(DEBUG_SQL, Config, "Field %d returning NULL", field);
return NULL;
}
/* Allocate string */
Config->conn.odbc.retstr[field] = realloc(Config->conn.odbc.retstr[field], size + 1);
if (Config->conn.odbc.retstr[field] == NULL) {
SMSD_Log(DEBUG_ERROR, Config, "Field %d returning NULL, failed to allocate %d bytes of memory", field, size + 1);
return NULL;
}
/* Actually grab result from database */
ret = SQLGetData(res->odbc, field + 1, SQL_C_CHAR, Config->conn.odbc.retstr[field], size + 1, &sqllen);
if (!SQL_SUCCEEDED(ret)) {
SMSDODBC_LogError(Config, ret, SQL_HANDLE_STMT, res->odbc, "SQLGetData(string) failed");
return NULL;
}
SMSD_Log(DEBUG_SQL, Config, "Field %d returning string \"%s\"", field, Config->conn.odbc.retstr[field]);
return Config->conn.odbc.retstr[field];
}
示例9: LoadChangeItem
int LoadChangeItem()//010708 lsw
{
HSTMT hStmt = NULL;
RETCODE retCode;
SDWORD cbValue;
SQLAllocStmt(hDBC, &hStmt);
retCode = SQLExecDirect(hStmt, (UCHAR *)"Select * from item_change order by original", SQL_NTS);
if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
{
int i = 0;
retCode = SQLFetch(hStmt);
while( retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
{
if(i >= MAX_CHANGE_ITEM_COUNT)//020730 lsw
{
SQLFreeStmt(hStmt, SQL_DROP);
return 0;
}
retCode = SQLGetData(hStmt, 1, SQL_C_LONG, &itemchange[i].origin_item_no , 0, &cbValue);
retCode = SQLGetData(hStmt, 2, SQL_C_LONG, &itemchange[i].will_change_item_no , 0, &cbValue);
retCode = SQLGetData(hStmt, 3, SQL_C_LONG, &itemchange[i].add_soksung , 0, &cbValue);
retCode = SQLGetData(hStmt, 4, SQL_C_LONG, &itemchange[i].add_grade , 0, &cbValue);
ichangeItemCount=i;
i++;
retCode = SQLFetch(hStmt);
if(retCode == SQL_SUCCESS || retCode == SQL_SUCCESS_WITH_INFO)
{
}
else if( retCode == SQL_NO_DATA )
{
break;
}
else
{
SQLFreeStmt(hStmt, SQL_DROP);
return 0;
}
}
}
SQLFreeStmt(hStmt, SQL_DROP); // 0308 YGI
return(1);
}
示例10: sql_column_float
SQLREAL sql_column_float(SQLHSTMT stmt, SQLUSMALLINT col) {
SQLREAL buf;
SQLINTEGER len;
SQLRETURN rc = SQLGetData(stmt, col + 1, SQL_REAL, &buf, 0, &len);
if (SQL_NULL_DATA == len) return 0;
return buf;
}
示例11: sql_fetch_row
/*************************************************************************
*
* Function: sql_fetch_row
*
* Purpose: database specific fetch_row. Returns a SQL_ROW struct
* with all the data for the query in 'sqlsocket->row'. Returns
* 0 on success, -1 on failure, SQL_DOWN if 'database is down'
*
*************************************************************************/
static int sql_fetch_row(SQLSOCK * sqlsocket, SQL_CONFIG *config)
{
int c, i;
SQLINTEGER len, slen;
SQL_ROW retval;
rlm_sql_db2_sock *sock;
sock = sqlsocket->conn;
c = sql_num_fields(sqlsocket, config);
retval = (SQL_ROW)rad_malloc(c*sizeof(char*)+1);
/* advance cursor */
if(SQLFetch(sock->stmt) == SQL_NO_DATA_FOUND) {
sqlsocket->row = NULL;
return 0;
}
for(i = 0; i < c; i++) {
/* get column length */
SQLColAttribute(sock->stmt,
i+1, SQL_DESC_DISPLAY_SIZE,
NULL, 0, NULL, &len);
retval[i] = (char*)rad_malloc(len+1);
/* get the actual column */
SQLGetData(sock->stmt,
i+1, SQL_C_CHAR, retval[i], len+1, &slen);
if(slen == SQL_NULL_DATA)
retval[i][0] = '\0';
}
sqlsocket->row = retval;
return 0;
}
示例12: SQLNumResultCols
void ODBCHandler::printStatement(SQLHSTMT *stmt)
{
SQLRETURN ret;
SQLRETURN ret2;
SQLSMALLINT columns; /* number of columns in result-set */
int row = 0;
/* How many columns are there */
SQLNumResultCols(*stmt, &columns);
/* Loop through the rows in the result-set */
while (SQL_SUCCEEDED(ret = SQLFetch(*stmt))) {
SQLUSMALLINT i;
ColDesc c;
fprintf(stderr,"Row %d\n", row++);
/* Loop through the columns */
for (i = 1; i <= columns; i++) {
SQLLEN indicator;
SQLCHAR buf[512];
//get column info
ret2 = SQLDescribeCol(*stmt,i,c.colName, sizeof(c.colName), &c.nameLen,NULL, NULL, NULL, NULL);
/* retrieve column data as a string */
ret = SQLGetData(*stmt, i, SQL_C_CHAR,buf, sizeof(buf), &indicator);
if (SQL_SUCCEEDED(ret)) {
/* Handle null columns */
if (indicator == SQL_NULL_DATA) strcpy((char*)buf, "NULL");
fprintf(stderr," Column %s %u : %s\n", c.colName,i, buf);
}
}
}
}
示例13: switch
bool CODBC_RowResult::CheckSIENoD_Binary(CDB_Stream* val)
{
SQLLEN f = 0;
char buffer[8*1024];
switch(SQLGetData(GetHandle(), m_CurrItem+1, SQL_C_BINARY, buffer, sizeof(buffer), &f)) {
case SQL_SUCCESS_WITH_INFO:
if(f == SQL_NO_TOTAL || f > SQLLEN(sizeof(buffer))) f = sizeof(buffer);
else ReportErrors();
case SQL_SUCCESS:
if(f > 0) {
if(f > SQLLEN(sizeof(buffer))) f = sizeof(buffer);
val->Append(buffer, f);
}
return true;
case SQL_NO_DATA:
break;
case SQL_ERROR:
ReportErrors();
default:
{
DATABASE_DRIVER_ERROR(
string("SQLGetData failed while retrieving BLOB into C") +
CDB_Object::GetTypeName(val->GetType()) + '.',
430022);
}
}
return false;
}
示例14: SQLAllocHandle
string ODBCHandler::get_tables()
{
SQLHSTMT stmt;
SQLRETURN ret;
SQLSMALLINT nr_columns;
stringstream tbl_list;
string ODBC_error;
bool list_start = false;
SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt);
SQLTables(stmt, NULL, 0, NULL, 0, NULL, 0, (unsigned char*)"TABLE",
SQL_NTS);
SQLNumResultCols(stmt, &nr_columns);
while (SQL_SUCCEEDED(ret = SQLFetch(stmt))) {
SQLUSMALLINT i;
tbl_list<<"{";
for (i = 1; i <= nr_columns; i++) {
SQLLEN indicator;
char buf[512];
ret = SQLGetData(stmt, i, SQL_C_CHAR,
buf, sizeof(buf), &indicator);
if (SQL_SUCCEEDED(ret)) {
if (indicator != SQL_NULL_DATA) {//strcpy(buf, "NULL");
if (list_start)
tbl_list<<",";
else
list_start = true;
tbl_list<<buf;
}
}
}
tbl_list<<"}";
}
return tbl_list.str();
}
示例15: SQLGetData
char *dbt2_sql_getvalue(struct db_context_t *dbc,
struct sql_result_t *sql_result, int field)
{
SQLRETURN rc;
char *tmp;
tmp = NULL;
SQLINTEGER cb_var = 0;
if (sql_result->current_row && field < sql_result->num_fields) {
if ((tmp = calloc(sizeof(char), sql_result->lengths[field] + 1))) {
rc = SQLGetData(dbc->hstmt, field + 1, SQL_C_CHAR, tmp,
sql_result->lengths[field] + 1, &cb_var);
if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
LOG_ODBC_ERROR(SQL_HANDLE_STMT, dbc->hstmt);
}
} else {
LOG_ERROR_MESSAGE("dbt2_sql_getvalue: CALLOC FAILED for value from field=%d\n", field);
}
#ifdef DEBUG_QUERY
} else {
LOG_ERROR_MESSAGE("dbt2_sql_getvalue: FIELD %d current_row %d\nQUERY --- %s\n", field, sql_result->current_row, sql_result->query);
#endif
}
return tmp;
}