ssb             Sun Jan 14 17:11:06 2001 EDT

  Modified files:              
    /php4/ext/odbc      php_odbc.c php_odbc.h 
  Log:
  @- Added odbc_error() and odbc_errormsg() functions (Stig)
  
  
Index: php4/ext/odbc/php_odbc.c
diff -u php4/ext/odbc/php_odbc.c:1.69 php4/ext/odbc/php_odbc.c:1.70
--- php4/ext/odbc/php_odbc.c:1.69       Fri Jan  5 14:01:22 2001
+++ php4/ext/odbc/php_odbc.c    Sun Jan 14 17:11:06 2001
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_odbc.c,v 1.69 2001/01/05 22:01:22 fmk Exp $ */
+/* $Id: php_odbc.c,v 1.70 2001/01/15 01:11:06 ssb Exp $ */
 
 #include "php.h"
 #include "php_globals.h"
@@ -66,6 +66,8 @@
 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 @@
 {
        ODBCLS_D;
 #ifdef SQLANY_BUG
-       HDBC    foobar;
+       ODBC_SQL_CONN_T foobar;
        RETCODE rc;
 #endif
 
@@ -420,6 +422,8 @@
        
        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 @@
        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 @@
        
        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 @@
 }
 /* }}} */
 
+
 /* {{{ proto int odbc_prepare(int connection_id, string query)
    Prepares a statement for execution */
 PHP_FUNCTION(odbc_prepare)
@@ -748,7 +769,7 @@
        }
 
        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 @@
                        */
                        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 @@
     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 @@
        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 @@
             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 @@
                        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 @@
        }
 
        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 @@
                         */
                        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 @@
                /* 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 @@
         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 @@
                                                                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 @@
                             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 @@
                             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_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 @@
        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 @@
 #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 @@
                                                                 
((*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 @@
 
                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 @@
 }
 /* }}} */
 
+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 @@
                        }
                        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 @@
                        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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
        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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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 @@
        }
 
        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 @@
             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: php4/ext/odbc/php_odbc.h
diff -u php4/ext/odbc/php_odbc.h:1.31 php4/ext/odbc/php_odbc.h:1.32
--- php4/ext/odbc/php_odbc.h:1.31       Thu Dec 28 14:01:50 2000
+++ php4/ext/odbc/php_odbc.h    Sun Jan 14 17:11:06 2001
@@ -17,7 +17,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_odbc.h,v 1.31 2000/12/28 22:01:50 kalowsky Exp $ */
+/* $Id: php_odbc.h,v 1.32 2001/01/15 01:11:06 ssb Exp $ */
 
 #ifndef PHP_ODBC_H
 #define PHP_ODBC_H
@@ -182,6 +182,8 @@
 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_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 @@
 } 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 @@
        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 @@
 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);
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to