void qObjODBC::Execute(qCtx *ctx, qStr *out, const char *sql, CStr &body, CStr &head, CStr &foot) { if (!myConn) { ctx->Throw(out, 302, myConn.GetErrorMsg()); return; } myStmt = myConn.Execute(sql); if (!myStmt) { ctx->Throw(out, 302, myStmt.GetErrorMsg()); return; } if ( ! ( body.IsEmpty() && head.IsEmpty() && foot.IsEmpty() ) ) { if (myStmt.Bind()) { bool ok = myStmt.Next(); ctx->MapObj(&ok, (QOBJFUNC) EvalBreak, "break"); if (!head.IsEmpty()) ctx->Parse(head, out); ok = ok && !myStmt.Done(); while (ok) { ctx->Parse(body, out); if (ok) ok = myStmt.Next(); } if (!foot.IsEmpty()) ctx->Parse(foot, out); } } }
void qObjODBC::EvalRow(qCtx *ctx, qStr *out, qArgAry *args) { assert(myStmt.RowCount()!=-1); if (myStmt.RowCount() == -1) return; out->PutN(myStmt.RowCount()); }
void qObjODBC::EvalColName(qCtx *ctx, qStr *out, qArgAry *args) { assert(myStmt.RowCount()!=-1); if (myStmt.RowCount() == -1) return; CDbCol *col; if ((col = GetEvalCol(ctx, args))) { out->PutS(col->Name); } }
void qObjODBC::EvalCol(qCtx *ctx, qStr *out, qArgAry *args) { assert(myStmt.RowCount()!=-1); if (myStmt.RowCount() == -1) return; CDbCol *col; if ((col = GetEvalCol(ctx, args))) { int ind = col->GetInd(); if (myStmt.HasData() && SQL_HAS_DATA(ind)) { col->ConvBuf(); col->RTrim(); if (col->GetBuf() && *col->GetBuf()) out->PutS(col->GetBuf()); } } }
void qObjODBC::EvalCol(qCtx *ctx, qStr *out, qArgAry *args) { assert(myStmt.RowCount()!=-1); if (myStmt.RowCount() == -1) return; CDbCol *col; if ((col = GetEvalCol(ctx, args))) { int ind = col->GetInd(); // smx_log(SMXLOGLEVEL_DEBUG, "ind for %s is %d", (const char *) col->Name, ind); if (myStmt.HasData() && SQL_HAS_DATA(ind)) { col->ConvBuf(); col->RTrim(); if (col->GetBuf() && *col->GetBuf()) out->PutS(col->GetBuf()); } } }
CDbCol *qObjODBC::GetEvalCol(qCtx *ctx, qArgAry *args) { CDbCol *col = 0; if (args->Count() > 0) { CStr index = (*args)[0]; index.Trim(); if (!index.IsEmpty()) { if (isdigit(index[0])) { col = myStmt.Column(atoi(index)-1); } else { strlwr(index.GetBuffer()); col = myStmt.Column((const char *)index); } } } return col; }
void qObjODBC::EvalColumn(qCtx *ctx, qStr *out, qArgAry *args) { assert(myStmt.RowCount()!=-1); if (myStmt.RowCount() == -1) return; CDbCol *col; if ((col = GetEvalCol(ctx, args))) { int ind = col->GetInd(); if (myStmt.HasData() && SQL_HAS_DATA(ind)) { col->ConvBuf(); if (ind >= 0) { int n = min((SQLINTEGER)ind, col->DispSize); out->PutS(col->GetBuf(), n); } else { out->PutS(col->GetBuf()); } } } }
void qObjODBC::EvalEnumCol(qCtx *ctx, qStr *out, qArgAry *args) { assert(myStmt.RowCount()!=-1); if (myStmt.RowCount() == -1) return; if (args->Count() == 0) return; int num, type, size; const char *name=0; const char *value=0; bool ok = true; qCtxTmp sub(ctx); sub.MapObj(&num, "num"); sub.MapObj(&name, "name"); sub.MapObj(&value, "value"); sub.MapObj(&type, "type"); sub.MapObj(&size, "size"); sub.MapObj(&ok, (QOBJFUNC) EvalBreak, "break"); CDbCol *col; for(num = 1; ok && num <= myStmt.ColCount(); ++num) { col = myStmt.Column(num-1); name = col->Name; if (myStmt.HasData() && SQL_HAS_DATA(col->GetInd())) { col->ConvBuf(); col->RTrim(); value = col->GetBuf(); } else { value = 0; } type = col->Type; size = col->Size; sub.qCtx::Parse(args->GetAt(0), out); } }
void qObjODBC::EvalSkipRows(qCtx *ctx, qStr *out, qArgAry *args) { int val = ParseInt((*args)[0]); myStmt.Skip(val); }
inline SQLINTEGER &GetInd() { return myIndPtr[myStmt->BufIndex()]; }
char *GetBuf() { return myBuf + (DispSize+1) * myStmt->BufIndex(); }
inline SQLLEN &GetInd() { return myIndPtr[myStmt->BufIndex()]; }