Back to index

php5  5.3.10
birdstep.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Nikolay P. Romanyuk <mag@redcom.ru>                         |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: birdstep.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 /*
00022  * TODO:
00023  * birdstep_fetch_into(),
00024  * Check all on real life apps.
00025  */
00026 
00027 #ifdef HAVE_CONFIG_H
00028 #include "config.h"
00029 #endif
00030 
00031 #include "php.h"
00032 
00033 #if WIN32
00034 # include "config.w32.h"
00035 # include "win95nt.h"
00036 # ifdef PHP_EXPORTS
00037 #  define PHPAPI __declspec(dllexport) 
00038 # else
00039 #  define PHPAPI __declspec(dllimport) 
00040 # endif
00041 #else
00042 # include <php_config.h>
00043 # define PHPAPI
00044 # define THREAD_LS
00045 #endif
00046 
00047 #ifdef HAVE_BIRDSTEP
00048 #include "php_birdstep.h"
00049 #include "ext/standard/info.h"
00050 #include "php_ini.h"
00051 
00052 /* {{{ arginfo */
00053 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_connect, 0, 0, 3)
00054        ZEND_ARG_INFO(0, server)
00055        ZEND_ARG_INFO(0, user)
00056        ZEND_ARG_INFO(0, pass)
00057 ZEND_END_ARG_INFO()
00058 
00059 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_close, 0, 0, 1)
00060        ZEND_ARG_INFO(0, id)
00061 ZEND_END_ARG_INFO()
00062 
00063 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_exec, 0, 0, 2)
00064        ZEND_ARG_INFO(0, index)
00065        ZEND_ARG_INFO(0, exec_str)
00066 ZEND_END_ARG_INFO()
00067 
00068 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_fetch, 0, 0, 1)
00069        ZEND_ARG_INFO(0, index)
00070 ZEND_END_ARG_INFO()
00071 
00072 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_result, 0, 0, 2)
00073        ZEND_ARG_INFO(0, index)
00074        ZEND_ARG_INFO(0, col)
00075 ZEND_END_ARG_INFO()
00076 
00077 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_freeresult, 0, 0, 1)
00078        ZEND_ARG_INFO(0, index)
00079 ZEND_END_ARG_INFO()
00080 
00081 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_autocommit, 0, 0, 1)
00082        ZEND_ARG_INFO(0, index)
00083 ZEND_END_ARG_INFO()
00084 
00085 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_off_autocommit, 0, 0, 1)
00086        ZEND_ARG_INFO(0, index)
00087 ZEND_END_ARG_INFO()
00088 
00089 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_commit, 0, 0, 1)
00090        ZEND_ARG_INFO(0, index)
00091 ZEND_END_ARG_INFO()
00092 
00093 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_rollback, 0, 0, 1)
00094        ZEND_ARG_INFO(0, index)
00095 ZEND_END_ARG_INFO()
00096 
00097 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_fieldname, 0, 0, 2)
00098        ZEND_ARG_INFO(0, index)
00099        ZEND_ARG_INFO(0, col)
00100 ZEND_END_ARG_INFO()
00101 
00102 ZEND_BEGIN_ARG_INFO_EX(arginfo_birdstep_fieldnum, 0, 0, 1)
00103        ZEND_ARG_INFO(0, index)
00104 ZEND_END_ARG_INFO()
00105 /* }}} */
00106 
00107 const zend_function_entry birdstep_functions[] = {
00108        PHP_FE(birdstep_connect,        arginfo_birdstep_connect)
00109        PHP_FE(birdstep_close,          arginfo_birdstep_close)
00110        PHP_FE(birdstep_exec,           arginfo_birdstep_exec)
00111        PHP_FE(birdstep_fetch,          arginfo_birdstep_fetch)
00112        PHP_FE(birdstep_result,         arginfo_birdstep_result)
00113        PHP_FE(birdstep_freeresult,     arginfo_birdstep_freeresult)
00114        PHP_FE(birdstep_autocommit,     arginfo_birdstep_autocommit)
00115        PHP_FE(birdstep_off_autocommit, arginfo_birdstep_off_autocommit)
00116        PHP_FE(birdstep_commit,         arginfo_birdstep_commit)
00117        PHP_FE(birdstep_rollback,       arginfo_birdstep_rollback)
00118        PHP_FE(birdstep_fieldnum,       arginfo_birdstep_fieldnum)
00119        PHP_FE(birdstep_fieldname,      arginfo_birdstep_fieldname)
00120 /*
00121  * Temporary Function aliases until the next major upgrade to PHP.  
00122  * These should allow users to continue to use their current scripts, 
00123  * but should in reality warn the user that this functionality is 
00124  * deprecated.
00125  */
00126        PHP_FALIAS(velocis_connect,        birdstep_connect,        arginfo_birdstep_connect)
00127        PHP_FALIAS(velocis_close,          birdstep_close,          arginfo_birdstep_close)
00128        PHP_FALIAS(velocis_exec,           birdstep_exec,           arginfo_birdstep_exec)
00129        PHP_FALIAS(velocis_fetch,          birdstep_fetch,          arginfo_birdstep_fetch)
00130        PHP_FALIAS(velocis_result,         birdstep_result,         arginfo_birdstep_result)
00131        PHP_FALIAS(velocis_freeresult,     birdstep_freeresult,     arginfo_birdstep_freeresult)
00132        PHP_FALIAS(velocis_autocommit,     birdstep_autocommit,     arginfo_birdstep_autocommit)
00133        PHP_FALIAS(velocis_off_autocommit, birdstep_off_autocommit, arginfo_birdstep_off_autocommit)
00134        PHP_FALIAS(velocis_commit,         birdstep_commit,         arginfo_birdstep_commit)
00135        PHP_FALIAS(velocis_rollback,       birdstep_rollback,       arginfo_birdstep_rollback)
00136        PHP_FALIAS(velocis_fieldnum,       birdstep_fieldnum,       arginfo_birdstep_fieldnum)
00137        PHP_FALIAS(velocis_fieldname,      birdstep_fieldname,      arginfo_birdstep_fieldname)
00138 /* End temporary aliases */
00139        {NULL, NULL, NULL}
00140 };
00141 
00142 zend_module_entry birdstep_module_entry = {
00143        STANDARD_MODULE_HEADER,
00144        "birdstep",
00145        birdstep_functions,
00146        PHP_MINIT(birdstep),
00147        PHP_MSHUTDOWN(birdstep),
00148        PHP_RINIT(birdstep),
00149        NULL,
00150        PHP_MINFO(birdstep),
00151        NO_VERSION_YET,
00152        STANDARD_MODULE_PROPERTIES
00153 };
00154 
00155 #ifdef COMPILE_DL_ODBC
00156 ZEND_GET_MODULE(birdstep)
00157 #endif
00158 
00159 THREAD_LS birdstep_module php_birdstep_module;
00160 THREAD_LS static HENV henv;
00161 
00162 #define PHP_GET_BIRDSTEP_RES_IDX(id) if (!(res = birdstep_find_result(list, id))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Not result index (%ld)", id); RETURN_FALSE; } 
00163 #define PHP_BIRDSTEP_CHK_LNK(id) if (!(conn = birdstep_find_conn(list, id))) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Not connection index (%ld)", id); RETURN_FALSE; }
00164                                                         
00165 
00166 static void _close_birdstep_link(zend_rsrc_list_entry *rsrc TSRMLS_DC)
00167 {
00168        VConn *conn = (VConn *)rsrc->ptr;
00169 
00170        if ( conn ) {
00171               efree(conn);
00172        }
00173 }
00174 
00175 static void _free_birdstep_result(zend_rsrc_list_entry *rsrc TSRMLS_DC)
00176 {
00177        Vresult *res = (Vresult *)rsrc->ptr;
00178 
00179        if ( res && res->values ) {
00180               register int i;
00181               for ( i=0; i < res->numcols; i++ ) {
00182                      if ( res->values[i].value )
00183                             efree(res->values[i].value);
00184               }
00185               efree(res->values);
00186        }
00187        if ( res ) {
00188               efree(res);
00189        }
00190 }
00191 
00192 PHP_MINIT_FUNCTION(birdstep)
00193 {
00194        SQLAllocEnv(&henv);
00195 
00196        if ( cfg_get_long("birdstep.max_links",&php_birdstep_module.max_links) == FAILURE ) {
00197               php_birdstep_module.max_links = -1;
00198        }
00199        php_birdstep_module.num_links = 0;
00200        php_birdstep_module.le_link   = zend_register_list_destructors_ex(_close_birdstep_link, NULL, "birdstep link", module_number);
00201        php_birdstep_module.le_result = zend_register_list_destructors_ex(_free_birdstep_result, NULL, "birdstep result", module_number);
00202 
00203        return SUCCESS;
00204 }
00205 
00206 PHP_RINIT_FUNCTION(birdstep)
00207 {
00208        return SUCCESS;
00209 }
00210 
00211 
00212 PHP_MINFO_FUNCTION(birdstep)
00213 {
00214        php_info_print_table_start();
00215        php_info_print_table_row(2, "RAIMA Birdstep Support", "enabled" );
00216        php_info_print_table_end();
00217 }
00218 
00219 PHP_MSHUTDOWN_FUNCTION(birdstep)
00220 {
00221        SQLFreeEnv(henv);
00222        return SUCCESS;
00223 }
00224 
00225 /* Some internal functions. Connections and result manupulate */
00226 
00227 static int birdstep_add_conn(HashTable *list,VConn *conn,HDBC hdbc)
00228 {
00229        int ind;
00230 
00231        ind = zend_list_insert(conn,php_birdstep_module.le_link);
00232        conn->hdbc = hdbc;
00233        conn->index = ind;
00234 
00235        return(ind);
00236 }
00237 
00238 static VConn * birdstep_find_conn(HashTable *list,int ind)
00239 {
00240        VConn *conn;
00241        int type;
00242 
00243        conn = zend_list_find(ind,&type);
00244        if ( !conn || type != php_birdstep_module.le_link ) {
00245               return(NULL);
00246        }
00247        return(conn);
00248 }
00249 
00250 static void birdstep_del_conn(HashTable *list,int ind)
00251 {
00252        zend_list_delete(ind);
00253 }
00254 
00255 static int birdstep_add_result(HashTable *list,Vresult *res,VConn *conn)
00256 {
00257        int ind;
00258 
00259        ind = zend_list_insert(res,php_birdstep_module.le_result);
00260        res->conn = conn;
00261        res->index = ind;
00262 
00263        return(ind);
00264 }
00265 
00266 static Vresult * birdstep_find_result(HashTable *list,int ind)
00267 {
00268        Vresult *res;
00269        int type;
00270 
00271        res = zend_list_find(ind,&type);
00272        if ( !res || type != php_birdstep_module.le_result ) {
00273               return(NULL);
00274        }
00275        return(res);
00276 }
00277 
00278 static void birdstep_del_result(HashTable *list,int ind)
00279 {
00280        zend_list_delete(ind);
00281 }
00282 
00283 /* Users functions */
00284 
00285 /* {{{ proto int birdstep_connect(string server, string user, string pass)
00286  */
00287 PHP_FUNCTION(birdstep_connect)
00288 {
00289        char *serv, *user, *pass;
00290        int serv_len, user_len, pass_len;
00291        RETCODE stat;
00292        HDBC hdbc;
00293        VConn *new;
00294        long ind;
00295 
00296        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &serv, &serv_len, &user, &user_len, &pass, &pass_len) == FAILURE) {
00297               return;
00298        }
00299        
00300        if ( php_birdstep_module.max_links != -1 && php_birdstep_module.num_links == php_birdstep_module.max_links ) {
00301               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Too many open connections (%d)",php_birdstep_module.num_links);
00302               RETURN_FALSE;
00303        }
00304 
00305        stat = SQLAllocConnect(henv,&hdbc);
00306        if ( stat != SQL_SUCCESS ) {
00307               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Could not allocate connection handle");
00308               RETURN_FALSE;
00309        }
00310        stat = SQLConnect(hdbc, serv, SQL_NTS, user, SQL_NTS, pass, SQL_NTS);
00311        if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00312               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Could not connect to server \"%s\" for %s", serv, user);
00313               SQLFreeConnect(hdbc);
00314               RETURN_FALSE;
00315        }
00316        new = (VConn *)emalloc(sizeof(VConn));
00317        ind = birdstep_add_conn(list,new,hdbc);
00318        php_birdstep_module.num_links++;
00319        RETURN_LONG(ind);
00320 }
00321 /* }}} */
00322 
00323 /* {{{ proto bool birdstep_close(int id)
00324  */
00325 PHP_FUNCTION(birdstep_close)
00326 {
00327        long id;
00328        VConn *conn;
00329 
00330        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
00331               return;
00332        }
00333 
00334        PHP_BIRDSTEP_CHK_LNK(id);
00335 
00336        SQLDisconnect(conn->hdbc);
00337        SQLFreeConnect(conn->hdbc);
00338        birdstep_del_conn(list, id);
00339        php_birdstep_module.num_links--;
00340        RETURN_TRUE;
00341 }
00342 /* }}} */
00343 
00344 /* {{{ proto int birdstep_exec(int index, string exec_str)
00345  */
00346 PHP_FUNCTION(birdstep_exec)
00347 {
00348        char *query;
00349        long ind;
00350        int query_len, indx;
00351        VConn *conn;
00352        Vresult *res;
00353        RETCODE stat;
00354        SWORD cols,i,colnamelen;
00355        SDWORD rows,coldesc;
00356 
00357        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &ind, &query, &query_len) == FAILURE) {
00358               return;
00359        }
00360 
00361        PHP_BIRDSTEP_CHK_LNK(ind);
00362 
00363        res = (Vresult *)emalloc(sizeof(Vresult));
00364        stat = SQLAllocStmt(conn->hdbc,&res->hstmt);
00365        if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00366               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLAllocStmt return %d",stat);
00367               efree(res);
00368               RETURN_FALSE;
00369        }
00370        stat = SQLExecDirect(res->hstmt,query,SQL_NTS);
00371        if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00372               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Cannot execute \"%s\" query",query);
00373               SQLFreeStmt(res->hstmt,SQL_DROP);
00374               efree(res);
00375               RETURN_FALSE;
00376        }
00377        /* Success query */
00378        stat = SQLNumResultCols(res->hstmt,&cols);
00379        if ( stat != SQL_SUCCESS ) {
00380               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);
00381               SQLFreeStmt(res->hstmt,SQL_DROP);
00382               efree(res);
00383               RETURN_FALSE;
00384        }
00385        if ( !cols ) { /* Was INSERT, UPDATE, DELETE, etc. query */
00386               stat = SQLRowCount(res->hstmt,&rows);
00387               if ( stat != SQL_SUCCESS ) {
00388                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLNumResultCols return %d",stat);
00389                      SQLFreeStmt(res->hstmt,SQL_DROP);
00390                      efree(res);
00391                      RETURN_FALSE;
00392               }
00393               SQLFreeStmt(res->hstmt,SQL_DROP);
00394               efree(res);
00395               RETURN_LONG(rows);
00396        } else {  /* Was SELECT query */
00397               res->values = (VResVal *)safe_emalloc(sizeof(VResVal), cols, 0);
00398               res->numcols = cols;
00399               for ( i = 0; i < cols; i++ ) {
00400                      SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_NAME,
00401                         res->values[i].name,sizeof(res->values[i].name),
00402                         &colnamelen,NULL);
00403                      SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_TYPE,
00404                         NULL,0,NULL,&res->values[i].valtype);
00405                      switch ( res->values[i].valtype ) {
00406                             case SQL_LONGVARBINARY:
00407                             case SQL_LONGVARCHAR:
00408                                    res->values[i].value = NULL;
00409                                    continue;
00410                             default:
00411                                    break;
00412                      }
00413                      SQLColAttributes(res->hstmt,i+1,SQL_COLUMN_DISPLAY_SIZE,
00414                         NULL,0,NULL,&coldesc);
00415                      res->values[i].value = (char *)emalloc(coldesc+1);
00416                      SQLBindCol(res->hstmt,i+1,SQL_C_CHAR, res->values[i].value,coldesc+1, &res->values[i].vallen);
00417               }
00418        }
00419        res->fetched = 0;
00420        indx = birdstep_add_result(list,res,conn);
00421        RETURN_LONG(indx);
00422 }
00423 /* }}} */
00424 
00425 /* {{{ proto bool birdstep_fetch(int index)
00426  */
00427 PHP_FUNCTION(birdstep_fetch)
00428 {
00429        long ind;
00430        Vresult *res;
00431        RETCODE stat;
00432        UDWORD  row;
00433        UWORD   RowStat[1];
00434 
00435        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ind) == FAILURE) {
00436               return;
00437        }
00438 
00439        PHP_GET_BIRDSTEP_RES_IDX(ind);
00440 
00441        stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);
00442        if ( stat == SQL_NO_DATA_FOUND ) {
00443               SQLFreeStmt(res->hstmt,SQL_DROP);
00444               birdstep_del_result(list,Z_LVAL_PP(ind));
00445               RETURN_FALSE;
00446        }
00447        if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00448               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLFetch return error");
00449               SQLFreeStmt(res->hstmt,SQL_DROP);
00450               birdstep_del_result(list,Z_LVAL_PP(ind));
00451               RETURN_FALSE;
00452        }
00453        res->fetched = 1;
00454        RETURN_TRUE;
00455 }
00456 /* }}} */
00457 
00458 /* {{{ proto mixed birdstep_result(int index, mixed col)
00459  */
00460 PHP_FUNCTION(birdstep_result)
00461 {
00462        zval **col;
00463        long ind;
00464        Vresult *res;
00465        RETCODE stat;
00466        int i,sql_c_type;
00467        UDWORD row;
00468        UWORD RowStat[1];
00469        SWORD indx = -1;
00470        char *field = NULL;
00471 
00472        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lZ", &ind, &col) == FAILURE) {
00473               return;
00474        }
00475 
00476        PHP_GET_BIRDSTEP_RES_IDX(ind);
00477 
00478        if ( Z_TYPE_PP(col) == IS_STRING ) {
00479               field = Z_STRVAL_PP(col);
00480        } else {
00481               convert_to_long_ex(col);
00482               indx = Z_LVAL_PP(col);
00483        }
00484        if ( field ) {
00485               for ( i = 0; i < res->numcols; i++ ) {
00486                      if ( !strcasecmp(res->values[i].name,field)) {
00487                             indx = i;
00488                             break;
00489                      }
00490               }
00491               if ( indx < 0 ) {
00492                      php_error_docref(NULL TSRMLS_CC, E_WARNING,  "Field %s not found",field);
00493                      RETURN_FALSE;
00494               }
00495        } else {
00496               if ( indx < 0 || indx >= res->numcols ) {
00497                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Field index not in range");
00498                      RETURN_FALSE;
00499               }
00500        }
00501        if ( !res->fetched ) {
00502               stat = SQLExtendedFetch(res->hstmt,SQL_FETCH_NEXT,1,&row,RowStat);
00503               if ( stat == SQL_NO_DATA_FOUND ) {
00504                      SQLFreeStmt(res->hstmt,SQL_DROP);
00505                      birdstep_del_result(list,Z_LVAL_PP(ind));
00506                      RETURN_FALSE;
00507               }
00508               if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00509                      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLFetch return error");
00510                      SQLFreeStmt(res->hstmt,SQL_DROP);
00511                      birdstep_del_result(list,Z_LVAL_PP(ind));
00512                      RETURN_FALSE;
00513               }
00514               res->fetched = 1;
00515        }
00516        switch ( res->values[indx].valtype ) {
00517               case SQL_LONGVARBINARY:
00518                      sql_c_type = SQL_C_BINARY;
00519                      goto l1;
00520               case SQL_LONGVARCHAR:
00521                      sql_c_type = SQL_C_CHAR;
00522 l1:
00523                      if ( !res->values[indx].value ) {
00524                             res->values[indx].value = emalloc(4096);
00525                      }
00526                      stat = SQLGetData(res->hstmt,indx+1,sql_c_type,
00527                             res->values[indx].value,4095,&res->values[indx].vallen);
00528                      if ( stat == SQL_NO_DATA_FOUND ) {
00529                             SQLFreeStmt(res->hstmt,SQL_DROP);
00530                             birdstep_del_result(list,Z_LVAL_PP(ind));
00531                             RETURN_FALSE;
00532                      }
00533                      if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00534                             php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: SQLGetData return error");
00535                             SQLFreeStmt(res->hstmt,SQL_DROP);
00536                             birdstep_del_result(list,Z_LVAL_PP(ind));
00537                             RETURN_FALSE;
00538                      }
00539                      if ( res->values[indx].valtype == SQL_LONGVARCHAR ) {
00540                             RETURN_STRING(res->values[indx].value,TRUE);
00541                      } else {
00542                             RETURN_LONG((long)res->values[indx].value);
00543                      }
00544               default:
00545                      if ( res->values[indx].value != NULL ) {
00546                             RETURN_STRING(res->values[indx].value,TRUE);
00547                      }
00548        }
00549 }
00550 /* }}} */
00551 
00552 /* {{{ proto bool birdstep_freeresult(int index)
00553  */
00554 PHP_FUNCTION(birdstep_freeresult)
00555 {
00556        long ind;
00557        Vresult *res;
00558 
00559        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ind) == FAILURE) {
00560               return;
00561        }
00562 
00563        PHP_GET_BIRDSTEP_RES_IDX(ind);
00564 
00565        SQLFreeStmt(res->hstmt,SQL_DROP);
00566        birdstep_del_result(list, ind);
00567        RETURN_TRUE;
00568 }
00569 /* }}} */
00570 
00571 /* {{{ proto bool birdstep_autocommit(int index)
00572  */
00573 PHP_FUNCTION(birdstep_autocommit)
00574 {
00575        long id;
00576        RETCODE stat;
00577        VConn *conn;
00578 
00579        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
00580               return;
00581        }
00582 
00583        PHP_BIRDSTEP_CHK_LNK(id);
00584 
00585        stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_ON);
00586        if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00587               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Set autocommit_on option failure");
00588               RETURN_FALSE;
00589        }
00590        RETURN_TRUE;
00591 }
00592 /* }}} */
00593 
00594 /* {{{ proto bool birdstep_off_autocommit(int index)
00595  */
00596 PHP_FUNCTION(birdstep_off_autocommit)
00597 {
00598        long id;
00599        RETCODE stat;
00600        VConn *conn;
00601 
00602        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
00603               return;
00604        }
00605 
00606        PHP_BIRDSTEP_CHK_LNK(id);
00607 
00608        stat = SQLSetConnectOption(conn->hdbc,SQL_AUTOCOMMIT,SQL_AUTOCOMMIT_OFF);
00609        if ( stat != SQL_SUCCESS && stat != SQL_SUCCESS_WITH_INFO ) {
00610               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Set autocommit_off option failure");
00611               RETURN_FALSE;
00612        }
00613        RETURN_TRUE;
00614 }
00615 /* }}} */
00616 
00617 /* {{{ proto bool birdstep_commit(int index)
00618  */
00619 PHP_FUNCTION(birdstep_commit)
00620 {
00621        long id;
00622        RETCODE stat;
00623        VConn *conn;
00624 
00625        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
00626               return;
00627        }
00628 
00629        PHP_BIRDSTEP_CHK_LNK(id)
00630 
00631        stat = SQLTransact(NULL,conn->hdbc,SQL_COMMIT);
00632        if ( stat != SQL_SUCCESS ) {
00633               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Commit failure");
00634               RETURN_FALSE;
00635        }
00636        RETURN_TRUE;
00637 }
00638 /* }}} */
00639 
00640 /* {{{ proto bool birdstep_rollback(int index)
00641  */
00642 PHP_FUNCTION(birdstep_rollback)
00643 {
00644        long id;
00645        RETCODE stat;
00646        VConn *conn;
00647 
00648        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &id) == FAILURE) {
00649               return;
00650        }
00651 
00652        PHP_BIRDSTEP_CHK_LNK(id);
00653 
00654        stat = SQLTransact(NULL,conn->hdbc,SQL_ROLLBACK);
00655        if ( stat != SQL_SUCCESS ) {
00656               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Rollback failure");
00657               RETURN_FALSE;
00658        }
00659        RETURN_TRUE;
00660 }
00661 /* }}} */
00662 
00663 /* {{{ proto string birdstep_fieldname(int index, int col)
00664  */
00665 PHP_FUNCTION(birdstep_fieldname)
00666 {
00667        long ind, col;
00668        Vresult *res;
00669        SWORD indx;
00670 
00671        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &ind, &col) == FAILURE) {
00672               return;
00673        }
00674 
00675        PHP_GET_BIRDSTEP_RES_IDX(ind);
00676 
00677        indx = col;
00678        if ( indx < 0 || indx >= res->numcols ) {
00679               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Birdstep: Field index not in range");
00680               RETURN_FALSE;
00681        }
00682        RETURN_STRING(res->values[indx].name,TRUE);
00683 }
00684 /* }}} */
00685 
00686 /* {{{ proto int birdstep_fieldnum(int index)
00687  */
00688 PHP_FUNCTION(birdstep_fieldnum)
00689 {
00690        long ind;
00691        Vresult *res;
00692 
00693        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ind) == FAILURE) {
00694               return;
00695        }
00696 
00697        PHP_GET_BIRDSTEP_RES_IDX(ind);
00698 
00699        RETURN_LONG(res->numcols);
00700 }
00701 /* }}} */
00702 
00703 #endif /* HAVE_BIRDSTEP */
00704 
00705 /*
00706  * Local variables:
00707  * tab-width: 4
00708  * c-basic-offset: 4
00709  * End:
00710  */