/****************************************************************************/ // SQLMISC.C v1.1 - 26.10.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 */ /****************************************************************************/ #include #include #include #include extern "C" { void exit(int); } short SS_MAXCURSORS; long SS_DEFINSZ; long SS_DEFOUTSZ; long SS_DEFCURSZ; short CB_MAX_PTYPES; short CB_MAX_SYSTYPES; short CB_MAX_ERRCOUNT; short CB_MAX_ERRTXTLEN; short CB_MAX_COLNAMELEN; short* perrors; short* pdlen; int* pdtype; char** pc; CursorDescr* allCursors; BindDescr** outdescrs; CbErrorHandler pErrorHandler; SqlSvr* TheServer = (SqlSvr* )NULL; void init_cb_data() { CB_MAX_PTYPES = _CB_MAX_PTYPES; CB_MAX_ERRCOUNT = _CB_MAX_ERRCOUNT; perrors = new short[CB_MAX_ERRCOUNT + 1]; pdlen = new short[CB_MAX_PTYPES + 1]; pdtype = new int[CB_MAX_PTYPES + 1]; init_sys_data(); init_parser_constants(); allCursors = new CursorDescr; outdescrs = new BindDescr*[SS_MAXCURSORS]; } void cb_error(char* errtxt, bool exitflg) { if(pErrorHandler) (*pErrorHandler)(errtxt, (int)exitflg); else { if(exitflg == TRUE) cerr << "FATAL "; cerr << "CB-Error: " << errtxt << "\n"; if(exitflg == TRUE) { cerr << "\nterminating.\n"; exit(-1); } } } BindInfo::BindInfo(short i, void* d, short t, int l, int s, bool indP, short* ind) { varIndex = i; data = d; type = t; if((indicator = ind) == NULL) indp_follows = indP; else indp_follows = FALSE; if(!(length = l)) { if(t > CB_MAX_SYSTYPES) cb_error("class BindInfo: invalid program data type"); else { if(!(length = pdlen[t])) { if((t == CB_PSTR || t == CB_PLSTRING) && d != (void* )NULL) length = strlen((char* )d); else { if((t != CB_PLSTREAM) && d != (void* )NULL) cb_error("class BindInfo: unknown buffer size"); } } } } scale = s; retLength = 0; retCode = 0; sysData = (void* )NULL; } void BindInfo::setBuffer(void* aPtr, short* iPtr) { indicator = iPtr; data = aPtr; if( length == 0 && (type == CB_PSTR || type == CB_PLSTRING)) length = strlen((char* )data); } void BindInfo::setIndp(short* iPtr) { indicator = iPtr; } CursorInfo::CursorInfo() { allCursors->addCursor(this); } SqlInfo* SqlDescr::infoAt(int i) { if(i < itemCount) return(items[i]); else return((SqlInfo* )NULL); } SqlDescr::~SqlDescr() { for(int i = 0; i < itemCount; i++) delete items[i]; delete items; } void SqlDescr::checkSize() { SqlInfo** olditems; olditems = items; if(!(items = new SqlInfo*[itemMax += (itemMax/2)])) cb_error("class SqlDescr: no more memory", TRUE); for(int i = 0; i < itemCount; i++) items[i] = olditems[i]; delete olditems; } void SqlDescr::dump() { for(int i = 0; i < itemCount; i++) (items[i])->dump(); } void CursorDescr::addCursor(CursorInfo* c) { CursorInfo* aCursor; if(aCursor = getUnused()) { items[aCursor->cndx] = (SqlInfo* )c; c->cndx = aCursor->cndx; delete aCursor; } else { if(itemCount < SS_MAXCURSORS) { c->cndx = itemCount; addInfo((SqlInfo *)c); } else cb_error("class CursorDescr: max cursors exceeded"); } } CursorInfo* CursorDescr::getUnused() { CursorInfo* aCi; for(int i = 0; i < itemCount; i++) { if((aCi = (CursorInfo* )items[i])->active == FALSE) return(aCi); } return(CursorInfo* )NULL; }