4 #include <wvdbusconn.h>
12 int vxtype_to_pgtype(WvStringParm vxtype
)
14 if (vxtype
== "String")
15 return PG_TYPE_VARCHAR
;
16 else if (vxtype
== "Int64")
18 else if (vxtype
== "Int32")
20 else if (vxtype
== "Int16")
22 else if (vxtype
== "UInt8")
24 else if (vxtype
== "Bool")
26 else if (vxtype
== "Double")
27 return PG_TYPE_FLOAT8
;
28 else if (vxtype
== "Uuid")
29 return PG_TYPE_VARCHAR
;
30 else if (vxtype
== "Binary")
32 else if (vxtype
== "DateTime")
33 return VX_TYPE_DATETIME
;
34 else if (vxtype
== "Decimal")
35 return PG_TYPE_NUMERIC
;
42 res
= QR_Constructor();
48 void set_field_info(int col
, const char *colname
, OID type
, int typesize
)
50 mylog("Col#%d is '%s', type=%d, size=%d\n", col
, colname
, type
, typesize
);
53 // FIXME: This will destroy old data
54 mylog("!!!!!! Resizing colinfo array, destroying data !!!!!!\n");
56 QR_set_num_fields(res
, maxcol
+1);
58 QR_set_field_info_v(res
, col
, colname
, type
, typesize
);
59 assert(!strcmp(QR_get_fieldname(res
, col
), colname
));
62 operator QResultClass
* () const
72 void runquery(WvDBusConn
&conn
, const char *func
, const char *query
)
74 WvDBusMsg
msg("vx.versaplexd", "/db", "vx.db", func
);
76 WvDBusMsg reply
= conn
.send_and_wait(msg
, 50000);
79 mylog("DBus error: '%s'\n", ((WvString
)reply
).cstr());
82 WvDBusMsg::Iter
top(reply
);
83 WvDBusMsg::Iter
colinfo(top
.getnext().open());
84 WvDBusMsg::Iter
data(top
.getnext().open().getnext().open());
85 WvDBusMsg::Iter
flags(top
.getnext().open());
88 // Sadly there's no better way to get the number of columns
89 for (num_cols
= 0; colinfo
.next(); num_cols
++) { }
91 // Allocate space for the column info data.
92 QR_set_num_fields(res
, num_cols
);
93 maxcol
= num_cols
- 1;
95 for (int colnum
= 0; colinfo
.next(); colnum
++)
97 WvDBusMsg::Iter
i(colinfo
.open());
99 int colsize
= i
.getnext();
100 WvString colname
= i
.getnext();
101 int coltype
= vxtype_to_pgtype(i
.getnext());
103 set_field_info(colnum
, colname
, coltype
, colsize
);
106 for (data
.rewind(); data
.next(); )
108 TupleField
*tuple
= QR_AddNew(res
);
110 WvDBusMsg::Iter
cols(data
.open());
112 cols
.next() && colnum
< numcols();
114 set_tuplefield_string(&tuple
[colnum
], *cols
);
123 StatementClass
*stmt
;
126 VxStatement(StatementClass
*_stmt
)
135 * things need to think that this statement is finished so the
136 * results can be retrieved.
138 stmt
->status
= STMT_FINISHED
;
140 /* set up the current tuple pointer for SQLFetch */
141 stmt
->currTuple
= -1;
142 SC_set_rowset_start(stmt
, -1, FALSE
);
143 SC_set_current_col(stmt
, -1);
146 ret
= DiscardStatementSvp(stmt
, ret
, FALSE
);
151 ret
= SC_initialize_and_recycle(stmt
);
154 void set_result(VxResultSet
&rs
)
156 SC_set_Result(stmt
, rs
);
158 /* the binding structure for a statement is not set up until
159 * a statement is actually executed, so we'll have to do this
162 extend_column_bindings(SC_get_ARDF(stmt
), rs
.numcols());
165 RETCODE
retcode() const
182 return ret
== SQL_SUCCESS
;
187 WvDBusConn
*db
= SC_get_conn(stmt
)->dbus
;
193 #endif // __VXHELPERS_H