environ.c
来自「postgresql-odbc,跨平台应用」· C语言 代码 · 共 696 行 · 第 1/2 页
C
696 行
break; case CONN_IN_USE: pg_sqlstate_set(env, szSqlState, "HY000", "S1000"); /* general error */ break; case CONN_UNSUPPORTED_OPTION: pg_sqlstate_set(env, szSqlState, "HYC00", "IM001"); /* driver does not support this function */ break; case CONN_INVALID_ARGUMENT_NO: pg_sqlstate_set(env, szSqlState, "HY009", "S1009"); /* invalid argument value */ break; case CONN_TRANSACT_IN_PROGRES: pg_sqlstate_set(env, szSqlState, "HY010", "S1010"); /* * when the user tries to switch commit mode in a * transaction */ /* -> function sequence error */ break; case CONN_NO_MEMORY_ERROR: pg_sqlstate_set(env, szSqlState, "HY001", "S1001"); break; case CONN_NOT_IMPLEMENTED_ERROR: pg_sqlstate_set(env, szSqlState, "HYC00", "S1C00"); break; case CONN_VALUE_OUT_OF_RANGE: pg_sqlstate_set(env, szSqlState, "HY019", "22003"); break; case CONNECTION_COULD_NOT_SEND: case CONNECTION_COULD_NOT_RECEIVE: case CONNECTION_COMMUNICATION_ERROR: pg_sqlstate_set(env, szSqlState, "08S01", "08S01"); break; default: pg_sqlstate_set(env, szSqlState, "HY000", "S1000"); /* general error */ break; } } mylog(" szSqlState = '%s',len=%d, szError='%s'\n", szSqlState, msglen, szErrorMsg); if (once_again) { CC_set_errornumber(conn, status); return SQL_SUCCESS_WITH_INFO; } else return SQL_SUCCESS;}RETCODE SQL_APIPGAPI_EnvError( HENV henv, SQLSMALLINT RecNumber, SQLCHAR FAR * szSqlState, SQLINTEGER FAR * pfNativeError, SQLCHAR FAR * szErrorMsg, SQLSMALLINT cbErrorMsgMax, SQLSMALLINT FAR * pcbErrorMsg, UWORD flag){ EnvironmentClass *env = (EnvironmentClass *) henv; char *msg; int status; mylog("**** PGAPI_EnvError: henv=%p <%d>\n", henv, cbErrorMsgMax); if (RecNumber != 1 && RecNumber != -1) return SQL_NO_DATA_FOUND; if (cbErrorMsgMax < 0) return SQL_ERROR; if (!EN_get_error(env, &status, &msg) || NULL == msg) { mylog("EN_get_error: status = %d, msg = #%s#\n", status, msg); if (NULL != szSqlState) pg_sqlstate_set(env, szSqlState, "00000", "00000"); if (NULL != pcbErrorMsg) *pcbErrorMsg = 0; if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) szErrorMsg[0] = '\0'; return SQL_NO_DATA_FOUND; } mylog("EN_get_error: status = %d, msg = #%s#\n", status, msg); if (NULL != pcbErrorMsg) *pcbErrorMsg = (SQLSMALLINT) strlen(msg); if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) strncpy_null(szErrorMsg, msg, cbErrorMsgMax); if (NULL != pfNativeError) *pfNativeError = status; if (szSqlState) { switch (status) { case ENV_ALLOC_ERROR: /* memory allocation failure */ pg_sqlstate_set(env, szSqlState, "HY001", "S1001"); break; default: pg_sqlstate_set(env, szSqlState, "HY000", "S1000"); /* general error */ break; } } return SQL_SUCCESS;}/* Returns the next SQL error information. */RETCODE SQL_APIPGAPI_Error( HENV henv, HDBC hdbc, HSTMT hstmt, SQLCHAR FAR * szSqlState, SQLINTEGER FAR * pfNativeError, SQLCHAR FAR * szErrorMsg, SQLSMALLINT cbErrorMsgMax, SQLSMALLINT FAR * pcbErrorMsg){ RETCODE ret; UWORD flag = PODBC_ALLOW_PARTIAL_EXTRACT | PODBC_ERROR_CLEAR; mylog("**** PGAPI_Error: henv=%p, hdbc=%p hstmt=%d\n", henv, hdbc, hstmt); if (cbErrorMsgMax < 0) return SQL_ERROR; if (SQL_NULL_HSTMT != hstmt) ret = PGAPI_StmtError(hstmt, -1, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg, flag); else if (SQL_NULL_HDBC != hdbc) ret = PGAPI_ConnectError(hdbc, -1, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg, flag); else if (SQL_NULL_HENV != henv) ret = PGAPI_EnvError(henv, -1, szSqlState, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg, flag); else { if (NULL != szSqlState) strcpy(szSqlState, "00000"); if (NULL != pcbErrorMsg) *pcbErrorMsg = 0; if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0)) szErrorMsg[0] = '\0'; ret = SQL_NO_DATA_FOUND; } mylog("**** PGAPI_Error exit code=%d\n", ret); return ret;}/* * EnvironmentClass implementation */EnvironmentClass *EN_Constructor(void){ CSTR func = "EN_Constructor"; EnvironmentClass *rv = NULL;#ifdef WIN32#ifndef _WSASTARTUP_IN_DLLMAIN_ WORD wVersionRequested; WSADATA wsaData; const int major = 1, minor = 1; /* Load the WinSock Library */ wVersionRequested = MAKEWORD(major, minor); if (WSAStartup(wVersionRequested, &wsaData)) { mylog("%s: WSAStartup error\n", func); return rv; } /* Verify that this is the minimum version of WinSock */ if (LOBYTE(wsaData.wVersion) != major || HIBYTE(wsaData.wVersion) != minor) { mylog("%s: WSAStartup version=(%d,%d)\n", func, LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion)); }#endif /* _WSASTARTUP_IN_DLLMAIN_ */#endif /* WIN32 */ rv = (EnvironmentClass *) malloc(sizeof(EnvironmentClass));cleanup: if (rv) { rv->errormsg = 0; rv->errornumber = 0; rv->flag = 0; INIT_ENV_CS(rv); }#ifdef WIN32#ifndef _WSASTARTUP_IN_DLLMAIN_ else { mylog("%s: malloc error\n", func); WSACleanup(); }#endif /* _WSASTARTUP_IN_DLLMAIN_ */#endif /* WIN32 */ return rv;}charEN_Destructor(EnvironmentClass *self){ int lf, nullcnt; char rv = 1; mylog("in EN_Destructor, self=%p\n", self); if (!self) return 0; /* * the error messages are static strings distributed throughout the * source--they should not be freed */ /* Free any connections belonging to this environment */ for (lf = 0, nullcnt = 0; lf < conns_count; lf++) { if (NULL == conns[lf]) nullcnt++; else if (conns[lf]->henv == self) { if (CC_Destructor(conns[lf])) conns[lf] = NULL; else rv = 0; nullcnt++; } } if (conns && nullcnt >= conns_count) { mylog("clearing conns count=%d\n", conns_count); free(conns); conns = NULL; conns_count = 0; } DELETE_ENV_CS(self); free(self);#ifdef WIN32#ifndef _WSASTARTUP_IN_DLLMAIN_ WSACleanup();#endif /* _WSASTARTUP_IN_DLLMAIN_ */#endif mylog("exit EN_Destructor: rv = %d\n", rv);#ifdef _MEMORY_DEBUG_ debug_memory_check();#endif /* _MEMORY_DEBUG_ */ return rv;}charEN_get_error(EnvironmentClass *self, int *number, char **message){ if (self && self->errormsg && self->errornumber) { *message = self->errormsg; *number = self->errornumber; self->errormsg = 0; self->errornumber = 0; return 1; } else return 0;}#define INIT_CONN_COUNT 128charEN_add_connection(EnvironmentClass *self, ConnectionClass *conn){ int i, alloc; ConnectionClass **newa; char ret = FALSE; mylog("EN_add_connection: self = %p, conn = %p\n", self, conn); ENTER_CONNS_CS; for (i = 0; i < conns_count; i++) { if (!conns[i]) { conn->henv = self; conns[i] = conn; ret = TRUE; mylog(" added at i=%d, conn->henv = %p, conns[i]->henv = %p\n", i, conn->henv, conns[i]->henv); goto cleanup; } } if (conns_count > 0) alloc = 2 * conns_count; else alloc = INIT_CONN_COUNT; if (newa = (ConnectionClass **) realloc(conns, alloc * sizeof(ConnectionClass *)), NULL == newa) goto cleanup; conn->henv = self; newa[conns_count] = conn; conns = newa; ret = TRUE; mylog(" added at %d, conn->henv = %p, conns[%d]->henv = %p\n", conns_count, conn->henv, conns_count, conns[conns_count]->henv); for (i = conns_count + 1; i < alloc; i++) conns[i] = NULL; conns_count = alloc;cleanup: LEAVE_CONNS_CS; return ret;}charEN_remove_connection(EnvironmentClass *self, ConnectionClass *conn){ int i; for (i = 0; i < conns_count; i++) if (conns[i] == conn && conns[i]->status != CONN_EXECUTING) { ENTER_CONNS_CS; conns[i] = NULL; LEAVE_CONNS_CS; return TRUE; } return FALSE;}voidEN_log_error(const char *func, char *desc, EnvironmentClass *self){ if (self) qlog("ENVIRON ERROR: func=%s, desc='%s', errnum=%d, errmsg='%s'\n", func, desc, self->errornumber, self->errormsg); else qlog("INVALID ENVIRON HANDLE ERROR: func=%s, desc='%s'\n", func, desc);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?