int ODBCWrapper::insertBar(const int stmtId, unsigned int datetime, double *vals, const int size) { int rv = 0; Statement *stmt = stmts[stmtId]; if (!stmt) return MOB_INVALID_STMTID; //TODO: rewrite to use type-specific parameter binding method DataPointer *dps = (DataPointer *) malloc(sizeof(DataPointer) * (size + 1)); SQL_TIMESTAMP_STRUCT ts; time_t tt = (time_t) datetime; TimestampPointer::timet2timestamp(&tt, &ts); dps[0] = TimestampPointer(&ts); for(int i = 0; i < size; i++) dps[i + 1] = DoublePointer(&vals[i]); try { stmt->bindParameters(dps, size + 1); rv = stmt->execute(); } catch (ODBCException *e) { handleException(e); free(dps); return MOB_NG; } free(dps); return rv; }
int ODBCWrapper::copyRates(const int stmtId, RateInfo *rates, const int size, const int start, const int end) { int rv = 0; Statement *stmt = stmts[stmtId]; if (!stmt) return MOB_INVALID_STMTID; if (start < 0 || end > size || start > end) return MOB_NG; for (int i = start; i < end; i++) { SQL_TIMESTAMP_STRUCT ts; time_t tt = (time_t) rates[i].ctm; TimestampPointer::timet2timestamp(&tt, &ts); DataPointer dps[6] = { TimestampPointer(&ts), DoublePointer(&rates[i].open), DoublePointer(&rates[i].high), DoublePointer(&rates[i].low), DoublePointer(&rates[i].close), DoublePointer(&rates[i].vol) }; try { //TODO: rewrite to use type-specific parameter binding method stmt->bindParameters(dps, 6); rv += stmt->execute(); } catch (ODBCException *e) { handleException(e); return MOB_NG; } } return rv; }