Merge commit 'origin/master'
[versaplex.git] / vxodbc / vxhelpers.h
blob174331ec135c974f9181d48d7b488bf7205f59a3
1 #ifndef __VXHELPERS_H
2 #define __VXHELPERS_H
4 #include "statement.h"
5 #include "qresult.h"
6 #include <wvdbusconn.h>
7 #include "pgtypes.h"
10 class VxResultSet
12 int maxcol;
14 //A bool to select whether or not the column info from an incoming
15 //message is important or not.
16 bool process_colinfo;
18 int vxtype_to_pgtype(WvStringParm vxtype)
20 if (vxtype == "String")
21 return PG_TYPE_VARCHAR;
22 else if (vxtype == "Int64")
23 return PG_TYPE_INT8;
24 else if (vxtype == "Int32")
25 return PG_TYPE_INT4;
26 else if (vxtype == "Int16")
27 return PG_TYPE_INT2;
28 else if (vxtype == "UInt8")
29 return PG_TYPE_CHAR;
30 else if (vxtype == "Bool")
31 return PG_TYPE_BOOL;
32 else if (vxtype == "Double")
33 return PG_TYPE_FLOAT8;
34 else if (vxtype == "Uuid")
35 return PG_TYPE_VARCHAR;
36 else if (vxtype == "Binary")
37 return PG_TYPE_BYTEA;
38 else if (vxtype == "DateTime")
39 return VX_TYPE_DATETIME;
40 else if (vxtype == "Decimal")
41 return PG_TYPE_NUMERIC;
44 public:
45 QResultClass *res;
47 VxResultSet() : process_colinfo(true)
49 res = QR_Constructor();
50 maxcol = -1;
51 assert(res);
52 assert(*this == res);
55 void set_field_info(int col, const char *colname, OID type, int typesize)
57 mylog("Col#%d is '%s', type=%d, size=%d\n", col, colname, type, typesize);
58 if (maxcol < col)
60 // FIXME: This will destroy old data
61 mylog("!!!!!! Resizing colinfo array, destroying data !!!!!!\n");
62 maxcol = col;
63 QR_set_num_fields(res, maxcol+1);
65 QR_set_field_info_v(res, col, colname, type, typesize);
66 assert(!strcmp(QR_get_fieldname(res, col), colname));
69 operator QResultClass* () const
71 return res;
74 int numcols() const
76 return maxcol+1;
79 void _runquery(WvDBusConn &conn, const char *func, const char *query);
80 void return_versaplex_db();
81 void process_msg(WvDBusMsg &msg);
85 class VxStatement
87 StatementClass *stmt;
88 RETCODE ret;
89 public:
90 VxStatement(StatementClass *_stmt)
92 stmt = _stmt;
93 ret = SQL_SUCCESS;
96 ~VxStatement()
99 * things need to think that this statement is finished so the
100 * results can be retrieved.
102 stmt->status = STMT_FINISHED;
104 /* set up the current tuple pointer for SQLFetch */
105 stmt->currTuple = -1;
106 SC_set_rowset_start(stmt, -1, FALSE);
107 SC_set_current_col(stmt, -1);
109 if (stmt->internal)
110 ret = DiscardStatementSvp(stmt, ret, FALSE);
113 void reinit()
115 ret = SC_initialize_and_recycle(stmt);
118 void set_result(VxResultSet &rs)
120 SC_set_Result(stmt, rs);
122 /* the binding structure for a statement is not set up until
123 * a statement is actually executed, so we'll have to do this
124 * ourselves.
126 extend_column_bindings(SC_get_ARDF(stmt), rs.numcols());
129 RETCODE retcode() const
131 return ret;
134 void seterr()
136 ret = SQL_ERROR;
139 void setok()
141 ret = SQL_SUCCESS;
144 bool isok() const
146 return ret == SQL_SUCCESS;
149 WvDBusConn &dbus()
151 ConnectionClass *conn = SC_get_conn(stmt);
152 assert(conn->dbus);
153 return *conn->dbus;
156 void runquery(VxResultSet &rs, const char *func, const char *query);
159 #endif // __VXHELPERS_H