static SQLRETURN MNDBAllocDesc(ODBCDbc *dbc, SQLHANDLE *OutputHandlePtr) { if (!dbc->Connected) { /* Connection does not exist */ addDbcError(dbc, "08003", NULL, 0); return SQL_ERROR; } if (OutputHandlePtr == NULL) { /* Invalid use of null pointer */ addDbcError(dbc, "HY009", NULL, 0); return SQL_ERROR; } *OutputHandlePtr = (SQLHANDLE *) newODBCDesc(dbc); #ifdef ODBCDEBUG ODBCLOG("new desc %p\n", *OutputHandlePtr); #endif return *OutputHandlePtr == NULL ? SQL_ERROR : SQL_SUCCESS; }
/* * Creates a new allocated ODBCStmt object and initializes it. * * Precondition: none * Postcondition: returns a new ODBCStmt object */ ODBCStmt * newODBCStmt(ODBCDbc *dbc) { ODBCStmt *stmt = (ODBCStmt *) malloc(sizeof(ODBCStmt)); assert(stmt); assert(dbc); assert(dbc->mid); if (stmt == NULL) { /* Memory allocation error */ addDbcError(dbc, "HY001", NULL, 0); return NULL; } stmt->Dbc = dbc; stmt->Error = NULL; stmt->RetrievedErrors = 0; stmt->State = INITED; stmt->hdl = mapi_new_handle(dbc->mid); if (stmt->hdl == NULL) { /* Memory allocation error */ addDbcError(dbc, "HY001", NULL, 0); free(stmt); return NULL; } assert(stmt->hdl); stmt->currentRow = 0; stmt->startRow = 0; stmt->rowSetSize = 0; stmt->queryid = -1; stmt->nparams = 0; stmt->querytype = -1; stmt->rowcount = 0; /* add this stmt to the administrative linked stmt list */ stmt->next = dbc->FirstStmt; dbc->FirstStmt = stmt; stmt->cursorType = SQL_CURSOR_FORWARD_ONLY; stmt->cursorScrollable = SQL_NONSCROLLABLE; stmt->retrieveData = SQL_RD_ON; stmt->noScan = SQL_NOSCAN_OFF; stmt->ApplRowDescr = newODBCDesc(dbc); stmt->ApplParamDescr = newODBCDesc(dbc); stmt->ImplRowDescr = newODBCDesc(dbc); stmt->ImplParamDescr = newODBCDesc(dbc); stmt->AutoApplRowDescr = stmt->ApplRowDescr; stmt->AutoApplParamDescr = stmt->ApplParamDescr; if (stmt->ApplRowDescr == NULL || stmt->ApplParamDescr == NULL || stmt->ImplRowDescr == NULL || stmt->ImplParamDescr == NULL) { destroyODBCStmt(stmt); return NULL; } stmt->ApplRowDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO; stmt->ApplParamDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO; stmt->ImplRowDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO; stmt->ImplParamDescr->sql_desc_alloc_type = SQL_DESC_ALLOC_AUTO; stmt->ImplRowDescr->Stmt = stmt; stmt->ImplParamDescr->Stmt = stmt; stmt->Type = ODBC_STMT_MAGIC_NR; /* set it valid */ return stmt; }