/* * Destroys the ODBCDbc object including its own managed data. * * Precondition: dbc must be valid, inactive (not connected) and * no ODBCStmt (or ODBCDesc) objects may refer to this dbc. * Postcondition: dbc is completely destroyed, dbc handle is become invalid. */ void destroyODBCDbc(ODBCDbc *dbc) { assert(isValidDbc(dbc)); assert(!dbc->Connected); assert(dbc->FirstStmt == NULL); /* first set this object to invalid */ dbc->Type = 0; /* remove this dbc from the env */ assert(dbc->Env); assert(dbc->Env->FirstDbc); { /* search for this dbc in the list */ ODBCDbc *tmp_dbc = (ODBCDbc *) dbc->Env->FirstDbc; ODBCDbc *prv_dbc = NULL; while ((tmp_dbc != NULL) && (tmp_dbc != dbc)) { prv_dbc = tmp_dbc; tmp_dbc = tmp_dbc->next; } assert(tmp_dbc == dbc); /* we must have found it */ /* now remove it from the linked list */ if (prv_dbc != NULL) { prv_dbc->next = dbc->next; } else { dbc->Env->FirstDbc = dbc->next; } } /* cleanup own managed data */ deleteODBCErrorList(&dbc->Error); if (dbc->dsn) free(dbc->dsn); if (dbc->uid) free(dbc->uid); if (dbc->pwd) free(dbc->pwd); if (dbc->host) free(dbc->host); if (dbc->dbname) free(dbc->dbname); free(dbc); }
/* * Destroys the ODBCStmt object including its own managed data. * * Precondition: stmt must be valid. * Postcondition: stmt is completely destroyed, stmt handle is invalid. */ void destroyODBCStmt(ODBCStmt *stmt) { ODBCStmt **stmtp; assert(isValidStmt(stmt)); /* first set this object to invalid */ stmt->Type = 0; /* remove this stmt from the dbc */ assert(stmt->Dbc); assert(stmt->Dbc->FirstStmt); /* search for stmt in linked list */ stmtp = &stmt->Dbc->FirstStmt; while (*stmtp && *stmtp != stmt) stmtp = &(*stmtp)->next; /* stmtp points to location in list where stmt is found */ assert(*stmtp == stmt); /* we must have found it */ /* now remove it from the linked list */ *stmtp = stmt->next; /* cleanup own managed data */ deleteODBCErrorList(&stmt->Error); destroyODBCDesc(stmt->ImplParamDescr); destroyODBCDesc(stmt->ImplRowDescr); destroyODBCDesc(stmt->AutoApplParamDescr); destroyODBCDesc(stmt->AutoApplRowDescr); if (stmt->hdl) mapi_close_handle(stmt->hdl); free(stmt); }