]> granicus.if.org Git - php/commitdiff
@- Added odbc_error() and odbc_errormsg() functions (Stig)
authorStig Bakken <ssb@php.net>
Mon, 15 Jan 2001 01:11:06 +0000 (01:11 +0000)
committerStig Bakken <ssb@php.net>
Mon, 15 Jan 2001 01:11:06 +0000 (01:11 +0000)
ext/odbc/php_odbc.c
ext/odbc/php_odbc.h

index 393aa8ae207d64ab4a81f1907b29685ffdaf4c9a..ea0dfdb7d2cbd930d7cc0d51880d2e469435ab68 100644 (file)
@@ -66,6 +66,8 @@ static int le_result, le_conn, le_pconn;
 static unsigned char a3_arg3_force_ref[] = { 3, BYREF_NONE, BYREF_ALLOW, BYREF_FORCE };
 
 function_entry odbc_functions[] = {
+    PHP_FE(odbc_error, NULL)
+    PHP_FE(odbc_errormsg, NULL)
        PHP_FE(odbc_setoption, NULL)
        PHP_FE(odbc_autocommit, NULL)
        PHP_FE(odbc_close, NULL)
@@ -319,7 +321,7 @@ PHP_MINIT_FUNCTION(odbc)
 {
        ODBCLS_D;
 #ifdef SQLANY_BUG
-       HDBC    foobar;
+       ODBC_SQL_CONN_T foobar;
        RETCODE rc;
 #endif
 
@@ -420,6 +422,8 @@ PHP_RINIT_FUNCTION(odbc)
        
        ODBCG(defConn) = -1;
        ODBCG(num_links) = ODBCG(num_persistent);
+    memset(ODBCG(laststate), '\0', 6);
+    memset(ODBCG(lasterrormsg), '\0', SQL_MAX_MESSAGE_LENGTH);
        return SUCCESS;
 }
 
@@ -466,22 +470,38 @@ void odbc_sql_error(ODBC_SQL_ERROR_PARAMS)
        char    errormsg[SQL_MAX_MESSAGE_LENGTH];
        SWORD   errormsgsize; /* Not used */
        RETCODE rc;
+    ODBC_SQL_ENV_T henv;
+    ODBC_SQL_CONN_T conn;
        ODBCLS_FETCH();
 
+    if (conn_resource) {
+        henv = conn_resource->henv;
+        conn = conn_resource->hdbc;
+    } else {
+        henv = SQL_NULL_HENV;
+        conn = SQL_NULL_HDBC;
+    }
+
        /* This leads to an endless loop in many drivers! 
         *
           while(henv != SQL_NULL_HENV){
                do {
         */
-                       rc = SQLError(henv, conn, stmt, state,
-                           &error, errormsg, sizeof(errormsg)-1, &errormsgsize);
-               if (func) {
-                       php_error(E_WARNING, "SQL error: %s, SQL state %s in %s",
-                                  errormsg, state, func);
-                       } else {
-                       php_error(E_WARNING, "SQL error: %s, SQL state %s",
-                                                   errormsg, state);
-                       }
+    rc = SQLError(henv, conn, stmt, state,
+                  &error, errormsg, sizeof(errormsg)-1, &errormsgsize);
+    if (conn_resource) {
+        memcpy(conn_resource->laststate, state, sizeof(state));
+        memcpy(conn_resource->lasterrormsg, errormsg, sizeof(errormsg));
+    }
+    memcpy(ODBCG(laststate), state, sizeof(state));
+    memcpy(ODBCG(lasterrormsg), errormsg, sizeof(errormsg));
+    if (func) {
+        php_error(E_WARNING, "SQL error: %s, SQL state %s in %s",
+                  errormsg, state, func);
+    } else {
+        php_error(E_WARNING, "SQL error: %s, SQL state %s",
+                  errormsg, state);
+    }
        /*              
                } while (SQL_SUCCEEDED(rc));
        }
@@ -591,7 +611,7 @@ void odbc_transact(INTERNAL_FUNCTION_PARAMETERS, int type)
        
        rc = SQLTransact(conn->henv, conn->hdbc, (UWORD)((type)?SQL_COMMIT:SQL_ROLLBACK));
        if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTransact");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLTransact");
                RETURN_FALSE;
        }
 
@@ -710,6 +730,7 @@ PHP_FUNCTION(odbc_longreadlen)
 }
 /* }}} */
 
+
 /* {{{ proto int odbc_prepare(int connection_id, string query)
    Prepares a statement for execution */
 PHP_FUNCTION(odbc_prepare)
@@ -748,7 +769,7 @@ PHP_FUNCTION(odbc_prepare)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -764,7 +785,7 @@ PHP_FUNCTION(odbc_prepare)
                        */
                        if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, SQL_CURSOR_DYNAMIC)
                                == SQL_ERROR) {
-                               odbc_sql_error(conn->henv, conn->hdbc, result->stmt, " SQLSetStmtOption");
+                               odbc_sql_error(conn, result->stmt, " SQLSetStmtOption");
                                SQLFreeStmt(result->stmt, SQL_DROP);
                                efree(result);
                                RETURN_FALSE;
@@ -780,10 +801,10 @@ PHP_FUNCTION(odbc_prepare)
     case SQL_SUCCESS:
         break;
     case SQL_SUCCESS_WITH_INFO:
-        odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLPrepare");
+        odbc_sql_error(conn, result->stmt, "SQLPrepare");
         break;
     default:
-        odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLPrepare");
+        odbc_sql_error(conn, result->stmt, "SQLPrepare");
         RETURN_FALSE;
     }
        
@@ -923,7 +944,7 @@ PHP_FUNCTION(odbc_execute)
        rc = SQLFreeStmt(result->stmt, SQL_CLOSE);
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLFreeStmt");    
+               odbc_sql_error(result->conn_ptr, result->stmt, "SQLFreeStmt");  
        }
 
        rc = SQLExecute(result->stmt);
@@ -945,7 +966,7 @@ PHP_FUNCTION(odbc_execute)
             break;
         case SQL_NO_DATA_FOUND:
         case SQL_SUCCESS_WITH_INFO:
-            odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLExecute");
+            odbc_sql_error(result->conn_ptr, result->stmt, "SQLExecute");
             break;
         default:
             RETVAL_FALSE;
@@ -1024,8 +1045,7 @@ PHP_FUNCTION(odbc_cursor)
                        if (!strncmp(state,"S1015",5)) {
                                sprintf(cursorname,"php_curs_%d", (int)result->stmt);
                                if (SQLSetCursorName(result->stmt,cursorname,SQL_NTS) != SQL_SUCCESS) {
-                                       odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc,
-                                                                       result->stmt, "SQLSetCursorName");
+                                       odbc_sql_error(result->conn_ptr, result->stmt, "SQLSetCursorName");
                                        RETVAL_FALSE;
                                } else {
                                        RETVAL_STRING(cursorname,1);
@@ -1088,7 +1108,7 @@ PHP_FUNCTION(odbc_exec)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -1104,7 +1124,7 @@ PHP_FUNCTION(odbc_exec)
                         */
                        if (SQLSetStmtOption(result->stmt, SQL_CURSOR_TYPE, SQL_CURSOR_DYNAMIC)
                                == SQL_ERROR) {
-                               odbc_sql_error(conn->henv, conn->hdbc, result->stmt, " SQLSetStmtOption");
+                               odbc_sql_error(conn, result->stmt, " SQLSetStmtOption");
                                SQLFreeStmt(result->stmt, SQL_DROP);
                                efree(result);
                                RETURN_FALSE;
@@ -1122,7 +1142,7 @@ PHP_FUNCTION(odbc_exec)
                /* XXX FIXME we should really check out SQLSTATE with SQLError
                 * in case rc is SQL_SUCCESS_WITH_INFO here.
                 */
-               odbc_sql_error(conn->henv, conn->hdbc, result->stmt, "SQLExecDirect"); 
+               odbc_sql_error(conn, result->stmt, "SQLExecDirect"); 
                SQLFreeStmt(result->stmt, SQL_DROP);
                efree(result);
                RETURN_FALSE;
@@ -1247,7 +1267,7 @@ static void php_odbc_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type)
         buf, result->longreadlen + 1, &result->values[i].vallen);
 
      if (rc == SQL_ERROR) {
-     odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+     odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
      efree(buf);
      RETURN_FALSE;
     }
@@ -1412,7 +1432,7 @@ PHP_FUNCTION(odbc_fetch_into)
                                                                buf, result->longreadlen + 1, &result->values[i].vallen);
 
                                        if (rc == SQL_ERROR) {
-                                       odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+                                       odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
                                        efree(buf);
                                        RETURN_FALSE;
                                }
@@ -1632,7 +1652,7 @@ PHP_FUNCTION(odbc_result)
                             field, fieldsize, &result->values[field_ind].vallen);
             
             if (rc == SQL_ERROR) {
-                odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+                odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
                 efree(field);
                 RETURN_FALSE;
             }
@@ -1675,7 +1695,7 @@ PHP_FUNCTION(odbc_result)
                             field, fieldsize, &result->values[field_ind].vallen);
 
                if (rc == SQL_ERROR) {
-                       odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+                       odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
             efree(field);
                        RETURN_FALSE;
                }
@@ -1781,7 +1801,7 @@ PHP_FUNCTION(odbc_result_all)
                                        php_printf("<td>");
 
                                        if (rc == SQL_ERROR) {
-                                               odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SQLGetData");
+                                               odbc_sql_error(result->conn_ptr, result->stmt, "SQLGetData");
                                                php_printf("</td></tr></table>");
                                                efree(buf);
                                                RETURN_FALSE;
@@ -1880,7 +1900,7 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int
        if (cur_opt != SQL_CUR_DEFAULT) {
                rc = SQLSetConnectOption((*conn)->hdbc, SQL_ODBC_CURSORS, cur_opt);
                if (rc != SQL_SUCCESS) {  /* && rc != SQL_SUCCESS_WITH_INFO ? */
-                       odbc_sql_error((*conn)->henv, (*conn)->hdbc, SQL_NULL_HSTMT, "SQLSetConnectOption");
+                       odbc_sql_error(*conn, SQL_NULL_HSTMT, "SQLSetConnectOption");
                        SQLFreeConnect((*conn)->hdbc);
                        pefree(*conn, persistent);
                        return FALSE;
@@ -1918,7 +1938,7 @@ int odbc_sqlconnect(odbc_connection **conn, char *db, char *uid, char *pwd, int
 #endif
 #endif
        if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-               odbc_sql_error((*conn)->henv, (*conn)->hdbc, SQL_NULL_HSTMT, "SQLConnect");
+               odbc_sql_error(*conn, SQL_NULL_HSTMT, "SQLConnect");
                SQLFreeConnect((*conn)->hdbc);
                pefree((*conn), persistent);
                return FALSE;
@@ -2361,7 +2381,7 @@ PHP_FUNCTION(odbc_autocommit)
                                                                 ((*pv_onoff)->value.lval) ?
                                                                 SQL_AUTOCOMMIT_ON : SQL_AUTOCOMMIT_OFF);
                if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-                       odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "Set autocommit");
+                       odbc_sql_error(conn, SQL_NULL_HSTMT, "Set autocommit");
                        RETURN_FALSE;
                }
                RETVAL_TRUE;
@@ -2370,7 +2390,7 @@ PHP_FUNCTION(odbc_autocommit)
 
                rc = SQLGetConnectOption(conn->hdbc, SQL_AUTOCOMMIT, (PTR)&status);
                if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-                       odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "Get commit status");
+                       odbc_sql_error(conn, SQL_NULL_HSTMT, "Get commit status");
                        RETURN_FALSE;
                }
                RETVAL_LONG((long)status);
@@ -2394,6 +2414,57 @@ PHP_FUNCTION(odbc_rollback)
 }
 /* }}} */
 
+static void php_odbc_lasterror(INTERNAL_FUNCTION_PARAMETERS, int mode)
+{
+       odbc_connection *conn;
+       pval **pv_handle;
+    char *ptr, *dest;
+    int argc, len;
+
+    argc = ZEND_NUM_ARGS();
+
+    if (argc > 1 || zend_get_parameters_ex(argc, &pv_handle)) {
+               WRONG_PARAM_COUNT;
+       }                            
+    if (mode == 0) {  /* last state */
+        len = 6;
+    } else { /* last error message */
+        len = SQL_MAX_MESSAGE_LENGTH;
+    }
+    ptr = ecalloc(len + 1, 1);
+    if (argc == 1) {
+        ZEND_FETCH_RESOURCE2(conn, odbc_connection *, pv_handle, -1, "ODBC-Link", le_conn, le_pconn);
+        if (mode == 0) {
+            strncpy(ptr, conn->laststate, len);
+        } else {
+            strncpy(ptr, conn->lasterrormsg, len);
+        }
+    } else {
+        if (mode == 0) {
+            strncpy(ptr, ODBCG(laststate), len);
+        } else {
+            strncpy(ptr, ODBCG(lasterrormsg), len);
+        }
+    }
+    RETVAL_STRING(ptr, 0);
+}
+
+/* {{{ proto string odbc_error([int connection_id])
+   Get the last error code */
+PHP_FUNCTION(odbc_error)
+{
+    php_odbc_lasterror(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
+}
+/* }}}    */
+
+/* {{{ proto string odbc_errormsg([int connection_id])
+   Get the last error message */
+PHP_FUNCTION(odbc_errormsg)
+{
+    php_odbc_lasterror(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
+}
+/* }}}    */
 
 /* {{{ proto int odbc_setoption(int conn_id|result_id, int which, int option, int value)
    Sets connection or statement options */
@@ -2427,7 +2498,7 @@ PHP_FUNCTION(odbc_setoption)
                        }
                        rc = SQLSetConnectOption(conn->hdbc, (unsigned short)((*pv_opt)->value.lval), (*pv_val)->value.lval);
                        if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-                               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SetConnectOption");
+                               odbc_sql_error(conn, SQL_NULL_HSTMT, "SetConnectOption");
                                RETURN_FALSE;
                        }
                        break;
@@ -2437,7 +2508,7 @@ PHP_FUNCTION(odbc_setoption)
                        rc = SQLSetStmtOption(result->stmt, (unsigned short)((*pv_opt)->value.lval), ((*pv_val)->value.lval));
 
                        if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
-                               odbc_sql_error(result->conn_ptr->henv, result->conn_ptr->hdbc, result->stmt, "SetStmtOption");
+                               odbc_sql_error(result->conn_ptr, result->stmt, "SetStmtOption");
                                RETURN_FALSE;
                        }
                        break;
@@ -2501,7 +2572,7 @@ PHP_FUNCTION(odbc_tables)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -2516,7 +2587,7 @@ PHP_FUNCTION(odbc_tables)
             type, SAFE_SQL_NTS(type));
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTables");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLTables");
                efree(result);
                RETURN_FALSE;
        }
@@ -2584,7 +2655,7 @@ PHP_FUNCTION(odbc_columns)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -2596,7 +2667,7 @@ PHP_FUNCTION(odbc_columns)
             column, SAFE_SQL_NTS(column));
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLColumns");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLColumns");
                efree(result);
                RETURN_FALSE;
        }
@@ -2663,7 +2734,7 @@ PHP_FUNCTION(odbc_columnprivileges)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -2675,7 +2746,7 @@ PHP_FUNCTION(odbc_columnprivileges)
             column, SAFE_SQL_NTS(column));
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLColumnPrivileges");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLColumnPrivileges");
                efree(result);
                RETURN_FALSE;
        }
@@ -2761,7 +2832,7 @@ PHP_FUNCTION(odbc_foreignkeys)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -2775,7 +2846,7 @@ PHP_FUNCTION(odbc_foreignkeys)
             ftable, SAFE_SQL_NTS(ftable) );
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLForeignKeys");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLForeignKeys");
                efree(result);
                RETURN_FALSE;
        }
@@ -2840,7 +2911,7 @@ PHP_FUNCTION(odbc_gettypeinfo)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -2848,7 +2919,7 @@ PHP_FUNCTION(odbc_gettypeinfo)
        rc = SQLGetTypeInfo(result->stmt, data_type );
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLGetTypeInfo");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLGetTypeInfo");
                efree(result);
                RETURN_FALSE;
        }
@@ -2912,7 +2983,7 @@ PHP_FUNCTION(odbc_primarykeys)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -2923,7 +2994,7 @@ PHP_FUNCTION(odbc_primarykeys)
             table, SAFE_SQL_NTS(table) );
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLPrimaryKeys");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLPrimaryKeys");
                efree(result);
                RETURN_FALSE;
        }
@@ -2994,7 +3065,7 @@ PHP_FUNCTION(odbc_procedurecolumns)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -3006,7 +3077,7 @@ PHP_FUNCTION(odbc_procedurecolumns)
             col, SAFE_SQL_NTS(col) );
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLProcedureColumns");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLProcedureColumns");
                efree(result);
                RETURN_FALSE;
        }
@@ -3076,7 +3147,7 @@ PHP_FUNCTION(odbc_procedures)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -3087,7 +3158,7 @@ PHP_FUNCTION(odbc_procedures)
             proc, SAFE_SQL_NTS(proc) );
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLProcedures");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLProcedures");
                efree(result);
                RETURN_FALSE;
        }
@@ -3162,7 +3233,7 @@ PHP_FUNCTION(odbc_specialcolumns)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -3176,7 +3247,7 @@ PHP_FUNCTION(odbc_specialcolumns)
             nullable);
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLSpecialColumns");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLSpecialColumns");
                efree(result);
                RETURN_FALSE;
        }
@@ -3247,7 +3318,7 @@ PHP_FUNCTION(odbc_statistics)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -3260,7 +3331,7 @@ PHP_FUNCTION(odbc_statistics)
             reserved);
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLStatistics");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLStatistics");
                efree(result);
                RETURN_FALSE;
        }
@@ -3325,7 +3396,7 @@ PHP_FUNCTION(odbc_tableprivileges)
        }
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLAllocStmt");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLAllocStmt");
                efree(result);
                RETURN_FALSE;
        }
@@ -3336,7 +3407,7 @@ PHP_FUNCTION(odbc_tableprivileges)
             table, SAFE_SQL_NTS(table));
 
        if (rc == SQL_ERROR) {
-               odbc_sql_error(conn->henv, conn->hdbc, SQL_NULL_HSTMT, "SQLTablePrivileges");
+               odbc_sql_error(conn, SQL_NULL_HSTMT, "SQLTablePrivileges");
                efree(result);
                RETURN_FALSE;
        }
index dd615a38e853e25c6673cf84e40fc9e24f50afbe..2cb43b37c8f0a882aee6fcc766f1c005858d8f43 100644 (file)
@@ -182,6 +182,8 @@ extern PHP_RINIT_FUNCTION(odbc);
 extern PHP_RSHUTDOWN_FUNCTION(odbc);
 PHP_MINFO_FUNCTION(odbc);
 
+PHP_FUNCTION(odbc_error);
+PHP_FUNCTION(odbc_errormsg);
 PHP_FUNCTION(odbc_setoption);
 PHP_FUNCTION(odbc_autocommit);
 PHP_FUNCTION(odbc_close);
@@ -229,17 +231,25 @@ PHP_FUNCTION(odbc_primarykeys);
 PHP_FUNCTION(odbc_specialcolumns);
 PHP_FUNCTION(odbc_statistics);
 
-typedef struct odbc_connection {
 #if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC )
-       SQLHANDLE henv;
-       SQLHANDLE hdbc;
+#define ODBC_SQL_ENV_T SQLHANDLE
+#define ODBC_SQL_CONN_T SQLHANDLE
+#define ODBC_SQL_STMT_T SQLHANDLE
 #elif defined( HAVE_SOLID_35 ) || defined( HAVE_SAPDB )
-       SQLHENV henv;
-       SQLHDBC hdbc;
+#define ODBC_SQL_ENV_T SQLHENV
+#define ODBC_SQL_CONN_T SQLHDBC
+#define ODBC_SQL_STMT_T SQLHSTMT
 #else
-       HENV henv;
-       HDBC hdbc;
+#define ODBC_SQL_ENV_T HENV
+#define ODBC_SQL_CONN_T HDBC
+#define ODBC_SQL_STMT_T HSTMT
 #endif
+
+typedef struct odbc_connection {
+    ODBC_SQL_ENV_T henv;
+    ODBC_SQL_CONN_T hdbc;
+    char laststate[6];
+    char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
        int id;
        int persistent;
 } odbc_connection;
@@ -252,13 +262,7 @@ typedef struct odbc_result_value {
 } odbc_result_value;
 
 typedef struct odbc_result {
-#if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC )
-       SQLHANDLE stmt;
-#elif defined( HAVE_SOLID_35 ) || defined( HAVE_SAPDB )
-       SQLHSTMT stmt;
-#else
-       HSTMT stmt;
-#endif
+    ODBC_SQL_STMT_T stmt;
        int id;
        odbc_result_value *values;
        SWORD numcols;
@@ -285,6 +289,8 @@ typedef struct {
        int defConn;
     long defaultlrl;
     long defaultbinmode;
+    char laststate[6];
+    char lasterrormsg[SQL_MAX_MESSAGE_LENGTH];
        HashTable *resource_list;
        HashTable *resource_plist;
 } php_odbc_globals;
@@ -297,13 +303,7 @@ odbc_connection *odbc_get_conn(HashTable *list, int count);
 void odbc_del_conn(HashTable *list, int ind);
 int odbc_bindcols(odbc_result *result);
 
-#if defined( HAVE_IBMDB2 ) || defined( HAVE_UNIXODBC )
-#define ODBC_SQL_ERROR_PARAMS SQLHANDLE henv, SQLHANDLE conn, SQLHANDLE stmt, char *func
-#elif defined( HAVE_SOLID_35 ) || defined( HAVE_SAPDB )
-#define ODBC_SQL_ERROR_PARAMS SQLHENV henv, SQLHDBC conn, SQLHSTMT stmt, char *func
-#else
-#define ODBC_SQL_ERROR_PARAMS HENV henv, HDBC conn, HSTMT stmt, char *func
-#endif
+#define ODBC_SQL_ERROR_PARAMS odbc_connection *conn_resource, ODBC_SQL_STMT_T stmt, char *func
 
 void odbc_sql_error(ODBC_SQL_ERROR_PARAMS);