3 #if wxUSE_DATABASE_ODBC 5 #include <wx/arrimpl.cpp> 6 WX_DEFINE_OBJARRAY(ValuesArray);
8 #define ODBC_FIELD_NAME_LEN 71 15 m_pOdbcStatement = NULL;
16 m_bManageStatement =
false;
23 m_pStatement = pStatement;
25 m_bManageStatement = bManageStatement;
28 SQLTCHAR field_name[ODBC_FIELD_NAME_LEN];
29 SQLSMALLINT colnamelen;
31 for (
int i=0; i<nCol; i++)
36 ODBC_FIELD_NAME_LEN, &colnamelen, 0);
37 if ( nReturn != SQL_SUCCESS && nReturn != SQL_SUCCESS_WITH_INFO )
47 wxString strField((wxChar*)field_name);
49 m_FieldLookupMap[strField.Upper()] = i;
95 if ( nReturn != SQL_SUCCESS && nReturn != SQL_SUCCESS_WITH_INFO )
97 if ( nReturn == SQL_NO_DATA )
117 for (
int ctr = 1; ctr < nField; ctr++)
123 wxMemoryBuffer buffer;
142 wxMemoryBuffer buffer;
154 for (
int ctr = 1; ctr <= nField; ctr++)
164 wxMemoryBuffer buffer;
176 strValue = strValue.Trim();
177 size_t real_size = strValue.Length();
188 unsigned long int colType;
192 if (SQL_FLOAT == colType || SQL_DOUBLE == colType)
197 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
206 if (sqlPtr == SQL_NULL_DATA)
217 else if (SQL_DATETIME == colType)
219 TIMESTAMP_STRUCT ret;
224 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
233 if (sqlPtr == SQL_NULL_DATA)
243 wxDateTime dt(ret.day, wxDateTime::Month(ret.month-1), ret.year, ret.hour,
244 ret.minute, ret.second, ret.fraction);
251 SQLPOINTER buff[8192];
253 memset(buff, 0, 8192*
sizeof(SQLTCHAR));
255 SQLINTEGER col_size = 8192;
256 SQLLEN real_size = 0;
262 if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO )
272 if (real_size == SQL_NULL_DATA)
275 if ( real_size > col_size )
277 while ( nRet != SQL_NO_DATA )
280 if ( nRet != SQL_SUCCESS && nRet != SQL_SUCCESS_WITH_INFO && nRet != SQL_NO_DATA )
320 return wxEmptyString;
353 return wxInvalidDateTime;
380 SQLINTEGER iLength = 8192;
382 unsigned char buff[8193];
384 memset(buff, 0, 8193*
sizeof(
unsigned char));
387 SQL_C_BINARY, SQL_BINARY, iLength, 0, &buff, iLength, &iSize);
392 if (iSize == SQL_NULL_DATA)
399 if ( nReturn != SQL_SUCCESS && nReturn != SQL_SUCCESS_WITH_INFO )
401 wxLogError(_T(
"Error with RunQueryWithResults - 1\n"));
409 wxMemoryBuffer tempBuffer(0);
410 tempBuffer.SetDataLen(0);
411 tempBuffer.SetBufSize(0);
419 size_t dataLength = (iLength < iSize) ? iLength : iSize;
420 size_t bufferSize = dataLength;
421 wxMemoryBuffer tempBuffer(dataLength);
423 tempBuffer.AppendData( buff, dataLength );
425 while ( iSize > iLength )
428 if ( nReturn != SQL_SUCCESS && nReturn != SQL_SUCCESS_WITH_INFO )
430 wxLogError(_T(
"Error with RunQueryWithResults - 2\n"));
435 dataLength = (iLength < iSize) ? iLength : iSize;
436 tempBuffer.AppendData( buff, dataLength );
437 bufferSize += dataLength;
440 wxMemoryBuffer tempBufferExactSize(bufferSize);
441 void* pData = tempBufferExactSize.GetWriteBuf(bufferSize);
442 memcpy(pData, tempBuffer.GetData(), bufferSize);
443 tempBufferExactSize.UngetWriteBuf(bufferSize);
444 tempBufferExactSize.SetDataLen(bufferSize);
445 tempBufferExactSize.SetBufSize(bufferSize);
446 Buffer = tempBufferExactSize;
448 wxMemoryBuffer localCopy(Buffer);
451 return Buffer.GetData();
455 BlobMap::iterator it =
m_BlobMap.find(nField);
458 wxMemoryBuffer tempBuffer(0);
459 tempBuffer.SetDataLen(0);
460 tempBuffer.SetBufSize(0);
467 return Buffer.GetData();
474 StringToIntMap::iterator SearchIterator =
m_FieldLookupMap.find(strField.Upper());
477 wxString msg(_(
"Field '") + strField + _(
"' not found in the resultset"));
478 #if wxUSE_DATABASE_EXCEPTIONS 488 return ((*SearchIterator).second+1);
503 SQLINTEGER iNativeCode;
522 SQLTCHAR col_name[8192];
523 SQLSMALLINT col_name_length;
524 SQLSMALLINT col_data_type;
526 SQLSMALLINT col_decimal_digits;
527 SQLSMALLINT col_nullable;
529 memset(col_name, 0, 8192);
532 8192, &col_name_length, &col_data_type, &col_size, &col_decimal_digits, &col_nullable );
535 return (col_data_type == SQL_BIT || col_data_type == SQL_BINARY ||
536 col_data_type == SQL_VARBINARY || col_data_type == SQL_LONGVARBINARY);
539 #endif//wxUSE_DATABASE_ODBC StringToIntMap m_FieldLookupMap
virtual void Close()
Close the result set (call wxDatabase::CloseResultSet() instead on the result set)
IntegerSet m_RetrievedValues
virtual wxResultSetMetaData * GetMetaData()
Retrieve the MetaData associated with this result set.
SQLDescribeColType GetSQLDescribeCol()
virtual bool IsFieldNull(int nField)
Check if a field in the current result set record is NULL.
virtual long GetResultLong(int nField)
Retrieve a long from the result set by the 1-based field index.
virtual void * GetResultBlob(int nField, wxMemoryBuffer &Buffer)
Retrieve a BLOB from the result set by the 1-based field index.
void LogMetaDataForCleanup(wxResultSetMetaData *pMetaData)
Add meta data object pointer to the list for "garbage collection".
wxOdbcPreparedStatement * m_pStatement
void RetrieveFieldData(int nField)
ValuesArray m_fieldValues
wxOdbcInterface * m_pInterface
SQLHSTMT GetLastStatement()
#define wxDATABASE_FIELD_NOT_IN_RESULTSET
SQLBindParameterType GetSQLBindParameter()
void ThrowDatabaseException()
virtual bool Next()
Move to the next record in the result set.
SQLColAttributeType GetSQLColAttribute()
wxOdbcInterface * m_pInterface
void CloseMetaData()
Close all meta data objects that have been generated but not yet closed.
void SetErrorMessage(const wxString &strErrorMessage)
SQLColAttributesType GetSQLColAttributes()
virtual double GetResultDouble(int nField)
Retrieve a double from the result set by the 1-based field index.
virtual wxString GetResultString(int nField)
Retrieve a wxString from the result set by the 1-based field index.
virtual bool GetResultBool(int nField)
Retrieve a boolean from the result set by the 1-based field index.
virtual wxDateTime GetResultDate(int nField)
Retrieve a wxDateTime from the result set by the 1-based field index.
virtual int LookupField(const wxString &strField)
SQLFetchType GetSQLFetch()
virtual int GetResultInt(int nField)
Retrieve an integer from the result set by the 1-based field index.
void SetErrorCode(int nErrorCode)
SQLGetDiagRecType GetSQLGetDiagRec()
SQLHSTMT m_pOdbcStatement
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)
wxOdbcResultSet(wxOdbcInterface *pInterface)
virtual ~wxOdbcResultSet()
SQLGetDataType GetSQLGetData()
void InterpretErrorCodes(long nCode, SQLHSTMT stmth_ptr=NULL)
virtual int GetFieldLength(int nField)
void InterpretErrorCodes(long nCode, SQLHSTMT stmth_ptr=NULL)