/****************************************************************************/ // SQLSVR_O.C v1.0 - 10.11.1990 /****************************************************************************/ /* */ /* Copyright (c) 1989-1993 Bernhard Strassl */ /* Institute for Applied Computer Science and Information Systems */ /* University of Vienna, Austria */ /* */ /* See file COPYRIGHT in this directory for details. If this file is */ /* missing please mail to bernhard@ani.univie.ac.at */ /****************************************************************************/ // // Oracle Pro*C call interface version // #include #include #include #include #include #include #define CB_STATUS_EOF 1 csrdef** oracleCursors; csrdef* lda; /* oracle lda area */ char hst[256]; /* oracle Host definition */ class OracleInfo : private SqlInfo { friend class SqlSvr; int ndx; OracleInfo() { ndx = 0; } }; class SysDescr : private SqlDescr { friend class SqlSvr; SysDescr() {} ~SysDescr() {} OracleInfo* at(int i) { return((OracleInfo* )infoAt(i)); } OracleInfo* next(int& i) { return((OracleInfo* )infoNext(i)); } }; class SysCurParam { friend class SqlSvr; SysDescr* dum; SysCurParam() { dum = (SysDescr* )NULL; } }; SqlSvr::SqlSvr() { init_cb_data(); oracleCursors = new csrdef*[SS_MAXCURSORS]; allCursors = new CursorDescr; lda = (csrdef* )NULL; } SqlSvr::~SqlSvr() { delete oracleCursors; delete allCursors; if(lda != (csrdef* )NULL) { if(ologof(lda)) cb_error("Database logout failed"); delete lda; lda = (csrdef* )NULL; } } CursorInfo* SqlSvr::connect(char* uid, int cursize, short, short) { char oertxt[80], errmsg[200]; ostrstream msg(errmsg, 200); csrdef* aCurs; CursorInfo* ci; if(!cursize) cursize = int(SS_DEFCURSZ); if(lda == (csrdef* )NULL) { lda = new csrdef; if(orlon(lda, hst, uid, -1, (char *)0, -1, -1)) { msg << "Database logon failed, error code " << (int)lda->csrrc; oermsg(lda->csrrc, oertxt); msg << "\n" << oertxt; msg.put('\0'); cb_error(errmsg); return((CursorInfo* )NULL); } } ci = new CursorInfo; aCurs = new csrdef; if(ci->cstat = oopen(aCurs, lda, (char *)0, -1, cursize, (char *)0, -1)) { error(ci); // connect failed return((CursorInfo* )NULL); } oracleCursors[ci->cndx] = aCurs; // ci->sysinfo = (void* )new SysCurParam; ci->active = TRUE; return(ci); } bool SqlSvr::disconnect(CursorInfo* ci) { int i = 0; CursorInfo* ii; if(lda == (csrdef* )NULL) return(FALSE); if(ci->cstat = oclose(oracleCursors[ci->cndx])) { error(ci); // disconnect failed return(FALSE); } ci->active = FALSE; while((ii = allCursors->next(i)) != (CursorInfo* )NULL) { if(ii->active == TRUE) return(TRUE); } if(ologof(lda)) cb_error("Database logout failed", TRUE); delete lda; lda = (csrdef* )NULL; return(TRUE); } bool SqlSvr::compile(CursorInfo* ci, char* stmt) { if(ci->cstat = osql3(oracleCursors[ci->cndx], stmt, -1)) { error(ci); // compile failed return(FALSE); } return(TRUE); } bool SqlSvr::exec(CursorInfo* ci) { if(ci->cstat = oexec(oracleCursors[ci->cndx])) { error(ci); // execute failed return(FALSE); } return(TRUE); } bool SqlSvr::compexec(CursorInfo* ci, char* stmt) { if(ci->cstat = osql3(oracleCursors[ci->cndx], stmt, -1)) { error(ci); // compile failed return(FALSE); } if(ci->cstat = oexec(oracleCursors[ci->cndx])) { error(ci); // execute failed return(FALSE); } return(TRUE); } bool SqlSvr::bindInput(CursorInfo* ci, BindDescr* bd) { BindInfo* bi; int i = 0; while(bi = bd->next(i)) { if(ci->cstat = obndrn(oracleCursors[ci->cndx], (int ) bi->varIndex, (char* ) bi->data, (int ) bi->length, (int ) pdtype[bi->type], (int ) bi->scale, (short *)bi->indicator, (char *)0, -1, -1)) /* { ostrstream vn; vn << ":" << bi->varIndex; vn.put('\0'); if(ci->cstat = obndrv(oracleCursors[ci->cndx], (char* )vn.str(), (int ) -1, (char* ) bi->data, (int ) bi->length, (int ) pdtype[bi->type], (int ) bi->scale, (short *)bi->indicator, (char *)0, -1, -1)) */ { error(ci); // bind failed return(FALSE); } } return(TRUE); } bool SqlSvr::bindOutput(CursorInfo* ci, BindDescr* bd) { BindInfo* bi; int n = 0; while(bi = bd->next(n)) { if(ci->cstat = odefin(oracleCursors[ci->cndx], (int ) bi->varIndex, (char* ) bi->data, (int ) bi->length, (int ) pdtype[bi->type], (int ) bi->scale, (short* ) bi->indicator, (char *)-1, -1, -1, (short* ) &(bi->retLength), (short* ) &(bi->retCode))) { error(ci); // bind failed return(FALSE); } } return(TRUE); } #define ORACLE_EOF 4 bool SqlSvr::descr(CursorInfo* ci, QryDescr& qd) { QryInfo* qi; short i, headerLength; headerLength = 0; i = 1; do { qi = new QryInfo; qi->nameBuff = new char[CB_MAX_COLNAMELEN]; if(ci->cstat = odsc(oracleCursors[ci->cndx], (int )(qi->colIndex = i++), (short* ) &(qi->dataLength), (short* )-1, (short* )-1, (short* ) &(qi->type), // database type (unusable) qi->nameBuff, (short* ) &headerLength, (short* )-1) != ORACLE_EOF) { error(ci); return(FALSE); } *((qi->nameBuff) + headerLength) = '\0'; qd.addInfo((SqlInfo* )qi); } while(ci->cstat != ORACLE_EOF); return(TRUE); } bool SqlSvr::fetch(CursorInfo* ci, short& fcode) { if(ci->cstat = ofetch(oracleCursors[ci->cndx])) { if((fcode = ci->cstat) != ORACLE_EOF) error(ci); // fetch failed else fcode = ci->cstat = CB_STATUS_EOF; return(FALSE); } return(TRUE); } bool SqlSvr::getStatus(CursorInfo* ci, int& rcode) { /* if(ci->cstat == CB_STATUS_EOF) rcode = ci->cstat; else */ rcode = (int)(oracleCursors[ci->cndx])->csrrc; return(TRUE); } bool SqlSvr::getRbFlag(CursorInfo* ci, bool& rbf) { rbf = (bool )int(((oracleCursors[ci->cndx])->csrflg & 4)); return(TRUE); } bool SqlSvr::getRowCount(CursorInfo* /* ci */, char* /* tbl */, long& /* rows */) { cb_error("sorry, getRowCount not implemented in this version"); return(FALSE); } bool SqlSvr::getCurRowCount(CursorInfo* ci, long& rows) { rows = (long)(oracleCursors[ci->cndx])->csrrpc; return(TRUE); } bool SqlSvr::commit(CursorInfo* ci) { if(ci->cstat = ocom(lda)) { cb_error("commit failed"); return(FALSE); } return(TRUE); } bool SqlSvr::rollback(CursorInfo* ci) { if(ci->cstat = orol(lda)) { cb_error("rollback failed"); return(FALSE); } return(TRUE); } void SqlSvr::error(CursorInfo* ci) { bool fatal; cb_error("class SqlSvr: error in server function", FALSE); allCursors->dump(); if(ci == (CursorInfo* )NULL) cb_error("class SqlSvr: invalid cursor handle", TRUE); char* errtxt = new char[CB_MAX_ERRTXTLEN]; fatal = (bool )!getErrorText(ci, errtxt); cb_error(errtxt, fatal); } bool SqlSvr::getErrorText(CursorInfo* ci, char* txt) { oermsg((oracleCursors[ci->cndx])->csrrc, txt); return(TRUE); }