Version: 1.0.0
odbc_resultset_metadata.cpp
Go to the documentation of this file.
1 #include "wx/database/wxprec.h"
2 
3 #if wxUSE_DATABASE_ODBC
4 
5 // ctor
6 wxOdbcResultSetMetaData::wxOdbcResultSetMetaData(wxOdbcInterface* pInterface, SQLHSTMT sqlOdbcStatement)
7 {
8  m_pInterface = pInterface;
9  m_pOdbcStatement = sqlOdbcStatement;
10 }
11 
13 {
14  int returnType = COLUMN_UNKNOWN;
15 
16  SQLTCHAR col_name[8192];
17  SQLSMALLINT col_name_length;
18  SQLSMALLINT col_data_type;
19  SQLULEN col_size;
20  SQLSMALLINT col_decimal_digits;
21  SQLSMALLINT col_nullable;
22 
23  memset(col_name, 0, 8192);
24 
25  SQLRETURN nRet = m_pInterface->GetSQLDescribeCol()( m_pOdbcStatement, i, col_name,
26  8192, &col_name_length, &col_data_type, &col_size, &col_decimal_digits, &col_nullable );
27 
28  if ( nRet != SQL_SUCCESS )
29  return returnType;
30 
31  switch (col_data_type)
32  {
33  case SQL_SMALLINT:
34  case SQL_INTEGER:
35  case SQL_TINYINT:
36  case SQL_BIGINT:
37  returnType = COLUMN_INTEGER;
38  break;
39  case SQL_DECIMAL:
40  case SQL_NUMERIC:
41  case SQL_REAL:
42  case SQL_FLOAT:
43  case SQL_DOUBLE:
44  returnType = COLUMN_DOUBLE;
45  break;
46  case SQL_CHAR:
47  case SQL_VARCHAR:
48  case SQL_LONGVARCHAR:
49  case SQL_WCHAR:
50  case SQL_WVARCHAR:
51  case SQL_WLONGVARCHAR:
52  returnType = COLUMN_STRING;
53  break;
54  case SQL_BIT:
55  case SQL_BINARY:
56  case SQL_VARBINARY:
57  case SQL_LONGVARBINARY:
58  returnType = COLUMN_BLOB;
59  break;
60  case SQL_TYPE_DATE:
61  case SQL_TYPE_TIME:
62  case SQL_TYPE_TIMESTAMP:
63  returnType = COLUMN_DATE;
64  break;
65  default:
66  returnType = COLUMN_UNKNOWN;
67  break;
68  };
69 
70  return returnType;
71 }
72 
74 {
75  int returnSize = -1;
76 
77  SQLTCHAR col_name[8192];
78  SQLSMALLINT col_name_length;
79  SQLSMALLINT col_data_type;
80  SQLULEN col_size;
81  SQLSMALLINT col_decimal_digits;
82  SQLSMALLINT col_nullable;
83 
84  memset(col_name, 0, 8192);
85 
86  SQLRETURN nRet = m_pInterface->GetSQLDescribeCol()( m_pOdbcStatement, i, col_name,
87  8192, &col_name_length, &col_data_type, &col_size, &col_decimal_digits, &col_nullable );
88 
89  if ( nRet == SQL_SUCCESS )
90  return col_size;
91 
92  return returnSize;
93 }
94 
96 {
97  wxString columnName;
98 
99  SQLTCHAR col_name[8192];
100  SQLSMALLINT col_name_length;
101  SQLSMALLINT col_data_type;
102  SQLULEN col_size;
103  SQLSMALLINT col_decimal_digits;
104  SQLSMALLINT col_nullable;
105 
106  memset(col_name, 0, 8192);
107 
108  SQLRETURN nRet = m_pInterface->GetSQLDescribeCol()( m_pOdbcStatement, i, col_name,
109  8192, &col_name_length, &col_data_type, &col_size, &col_decimal_digits, &col_nullable );
110 
111  if ( nRet == SQL_SUCCESS )
112  {
113  //return wxString((wxChar*)col_name);
114  columnName = ConvertFromUnicodeStream((const char*)(wxChar*)col_name);
115  }
116 
117  return columnName;
118 }
119 
121 {
122  SQLSMALLINT col_count;
123 
124  SQLRETURN nRet = m_pInterface->GetSQLNumResultCols()( m_pOdbcStatement, &col_count );
125 
126  if ( nRet == SQL_SUCCESS )
127  return col_count;
128 
129  return 0;
130 }
131 
132 #endif//wxUSE_DATABASE_ODBC
133 
virtual int GetColumnType(int i)
Retrieve a column's type.
SQLDescribeColType GetSQLDescribeCol()
Definition: odbc_inteface.h:78
SQLNumResultColsType GetSQLNumResultCols()
Definition: odbc_inteface.h:73
virtual int GetColumnCount()
Retrieve the number of columns in the result set.
virtual wxString GetColumnName(int i)
Retrieve a column's name.
virtual int GetColumnSize(int i)
Retrieve a column's size.
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)
wxOdbcResultSetMetaData(wxOdbcInterface *pInterface, SQLHSTMT sqlOdbcStatement)