Version: 1.0.0
sqlite_resultset_metatdata.cpp
Go to the documentation of this file.
1 #include "wx/database/wxprec.h"
2 
3 #if wxUSE_DATABASE_SQLITE
4 
5 /*
6  SPECIAL NOTE:
7  The sqlite3_column_* functions are 0-based, but the JDBC wxResultSetMetaData
8  functions are 1-based. To be consistent with the 1-based JDBC (and also
9  wxPreparedStatement paramters, we are using a 1-based system here.)
10  */
11 
12 // ctor
14 {
15  m_pSqliteStatement = pStmt;
16 }
17 
19 {
20  int returnType = COLUMN_UNKNOWN;
21  wxString columnTypeString = ConvertFromUnicodeStream(sqlite3_column_decltype(m_pSqliteStatement, i-1));
22  columnTypeString.MakeUpper();
23  if (columnTypeString.IsSameAs(_("INTEGER")) || columnTypeString.IsSameAs(_("INT")) || columnTypeString.IsSameAs(_("LONG")))
24  returnType = COLUMN_INTEGER;
25  else if (columnTypeString.IsSameAs(_("STRING")) || columnTypeString.StartsWith(_("VARCHAR")))
26  returnType = COLUMN_STRING;
27  else if (columnTypeString.IsSameAs(_("DOUBLE")) || columnTypeString.IsSameAs(_("FLOAT")))
28  returnType = COLUMN_DOUBLE;
29  else if (columnTypeString.IsSameAs(_("BOOL")))
30  returnType = COLUMN_BOOL;
31  else if (columnTypeString.IsSameAs(_("BLOB")))
32  returnType = COLUMN_BLOB;
33  else if (columnTypeString.IsSameAs(_("DATE")) || columnTypeString.IsSameAs(_("DATETIME")) || columnTypeString.IsSameAs(_("TIMESTAMP")))
34  returnType = COLUMN_DATE;
35  else
36  returnType = COLUMN_UNKNOWN;
37 
38  if (returnType == COLUMN_UNKNOWN)
39  {
40  int columnType = sqlite3_column_type(m_pSqliteStatement, i-1);
41  switch (columnType)
42  {
43  case SQLITE_INTEGER:
44  puts("sqlite3_column_type returned SQLITE_INTEGER");
45  returnType = COLUMN_INTEGER;
46  break;
47  case SQLITE_FLOAT:
48  returnType = COLUMN_DOUBLE;
49  break;
50  case SQLITE_TEXT:
51  returnType = COLUMN_STRING;
52  break;
53  case SQLITE_BLOB:
54  returnType = COLUMN_BLOB;
55  break;
56  case SQLITE_NULL:
57  returnType = COLUMN_NULL;
58  break;
59  default:
60  returnType = COLUMN_UNKNOWN;
61  break;
62  };
63  }
64 
65  return returnType;
66 }
67 
69 {
70  return -1;
71 }
72 
74 {
75  wxString columnName = ConvertFromUnicodeStream(sqlite3_column_name(m_pSqliteStatement, i-1));
76  return columnName;
77 }
78 
80 {
81  return sqlite3_column_count(m_pSqliteStatement);
82 }
83 
84 #endif//wxUSE_DATABASE_SQLITE
85 
virtual wxString GetColumnName(int i)
Retrieve a column's name.
virtual int GetColumnCount()
Retrieve the number of columns in the result set.
wxSqliteResultSetMetaData(sqlite3_stmt *pStmt)
virtual int GetColumnSize(int i)
Retrieve a column's size.
virtual int GetColumnType(int i)
Retrieve a column's type.
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)