fmk             Mon Feb  9 12:58:25 2004 EDT

  Modified files:              (Branch: PHP_4_3)
    /php-src/ext/fbsql  php_fbsql.c 
  Log:
  Delay creation of exec handle til it's needed
  
http://cvs.php.net/diff.php/php-src/ext/fbsql/php_fbsql.c?r1=1.86.2.7&r2=1.86.2.8&ty=u
Index: php-src/ext/fbsql/php_fbsql.c
diff -u php-src/ext/fbsql/php_fbsql.c:1.86.2.7 php-src/ext/fbsql/php_fbsql.c:1.86.2.8
--- php-src/ext/fbsql/php_fbsql.c:1.86.2.7      Thu Oct  2 14:48:18 2003
+++ php-src/ext/fbsql/php_fbsql.c       Mon Feb  9 12:58:24 2004
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_fbsql.c,v 1.86.2.7 2003/10/02 18:48:18 fmk Exp $ */
+/* $Id: php_fbsql.c,v 1.86.2.8 2004/02/09 17:58:24 fmk Exp $ */
 
 /* TODO:
  *
@@ -83,30 +83,28 @@
        required buffereing from of results.
 
        In the PHP code the 3 above a data structures are referenced by means of 
integers in the
-       range from 1 to som configurable maximum.  You can put a limit to the number 
of links, databases
-       and results.  The integer identifications is implemented by insertion in the 
list, which is passed
+       range from 1 to som configurable maximum. You can put a limit to the number of 
links, databases
+       and results. The integer identifications is implemented by insertion in the 
list, which is passed
        as an argument to all the functions, please note the list is polymorph.
 
        Database objects and link objects are all reused, base on the host name user 
name, host name database name 
-       user name.  So connecting twice to the same database as the same user will 
return the same database id.
+       user name. So connecting twice to the same database as the same user will 
return the same database id.
        We use the same coding for that as fbsql does, explioiting the underlying 
implementation of the lists.
 
        Persistent objects are put in the persistent list as well, but only by name, 
if you connect to a persistent object
-       and it is not in the list it is simply added and get a new index, and 
refcounted.  Tricky, tricky ...
+       and it is not in the list it is simply added and get a new index, and 
refcounted. Tricky, tricky ...
 */
 
 /* Some functions which should be exported from FBCAccess */
 
-void*        fbaObjectAtIndex();
-void         fbaRelease();
-unsigned int fbaCount();
+void*                  fbaObjectAtIndex();
+void                   fbaRelease();
+unsigned int   fbaCount();
 
 struct FBCAutoStartInfo {
-   FBArray* infoLines;
+       FBArray* infoLines;
 };
 
-
-
 struct PHPFBResult
 {
        PHPFBLink*                              link;                           /* The 
link for the result, may be NULL if no link  */
@@ -115,7 +113,7 @@
        FBCMetaData*                    ResultmetaData;         /* The metadata 
describing the result */
        FBCRowHandler*                  rowHandler;                     /* The row 
handler, the Frontbase structure used for accessing rows in the result */
        unsigned int                    batchSize;                      /* The number 
of row to fetch when expanding the number of rows in the row handler */
-       unsigned int                    rowCount;                       /* The number 
of rows in the results set.  The number of row is not in */
+       unsigned int                    rowCount;                       /* The number 
of rows in the results set. The number of row is not in */
                                                /* general known when the select is 
done, one typically needs to fetch all the row
                                                   to figure out how many row you got. 
When the rowCount is unknown the value is
                                                   0x7ffffffff */
@@ -280,10 +278,10 @@
                        FBCMetaData *md = fbcdcCancelFetch(result->link->connection, 
result->fetchHandle);
                        fbcmdRelease(md);
                }
-               if (result->rowHandler)  fbcrhRelease(result->rowHandler);
-               if (result->ResultmetaData)    fbcmdRelease(result->ResultmetaData);
-               if (result->list)        fbcplRelease(result->list);
-               if (result->array)       fbaRelease(result->array);
+               if (result->rowHandler)         fbcrhRelease(result->rowHandler);
+               if (result->ResultmetaData)     fbcmdRelease(result->ResultmetaData);
+               if (result->list)                       fbcplRelease(result->list);
+               if (result->array)                      fbaRelease(result->array);
                efree(result);
        }
 }
@@ -389,7 +387,7 @@
        fbsql_globals->persistentCount  = 0;
        fbsql_globals->linkCount                = 0;
 }
-                                        
+
 PHP_MINIT_FUNCTION(fbsql)
 {
        ZEND_INIT_MODULE_GLOBALS(fbsql, php_fbsql_init_globals, NULL);
@@ -397,7 +395,7 @@
        REGISTER_INI_ENTRIES();
 
        fbcInitialize();
-
+       fbcehSetMultiThreaded(True);
        le_result       = zend_register_list_destructors_ex(phpfbReleaseResult, NULL, 
"fbsql result", module_number);
        le_link         = zend_register_list_destructors_ex(phpfbReleaseLink, NULL, 
"fbsql link", module_number);
        le_plink        = zend_register_list_destructors_ex(NULL, phpfbReleasePLink, 
"fbsql plink", module_number);
@@ -497,12 +495,12 @@
        if (argc >= 2)
        {
                convert_to_string_ex(argv[1]);
-               userName =  Z_STRVAL_PP(argv[1]);
-       }   
+               userName = Z_STRVAL_PP(argv[1]);
+       }
        if (argc == 3)
        {
                convert_to_string_ex(argv[2]);
-               userPassword =  Z_STRVAL_PP(argv[2]);
+               userPassword = Z_STRVAL_PP(argv[2]);
        }
 
        if (hostName     == NULL) hostName     = FB_SQL_G(hostName);
@@ -543,7 +541,7 @@
                        phpLink->userPassword     = strdup(userPassword);
                        phpLink->databasePassword = strdup(FB_SQL_G(databasePassword));
                        phpLink->databaseName     = NULL;
-                       phpLink->execHandler      = fbcehHandlerForHost(hostName, 128);
+                       phpLink->execHandler      = NULL;
                        phpLink->affectedRows     = 0;
                        phpLink->autoCommit               = FB_SQL_G(autoCommit);
                        phpLink->errorNo          = 0;
@@ -604,7 +602,7 @@
                phpLink->userPassword     = strdup(userPassword);
                phpLink->databasePassword = strdup(FB_SQL_G(databasePassword));
                phpLink->databaseName     = NULL;
-               phpLink->execHandler      = fbcehHandlerForHost(hostName, 128);
+               phpLink->execHandler      = NULL;
                phpLink->affectedRows     = 0;
                phpLink->autoCommit               = FB_SQL_G(autoCommit);
                phpLink->errorNo          = 0;
@@ -613,7 +611,7 @@
 
                ZEND_REGISTER_RESOURCE(return_value, phpLink, le_link);
 
-               le.ptr  = (void *)Z_LVAL_P(return_value);
+               le.ptr = (void *)Z_LVAL_P(return_value);
                Z_TYPE(le) = le_index_ptr;
                if (zend_hash_update(&EG(regular_list), name, strlen(name) + 1, &le, 
sizeof(le), NULL)==FAILURE)
                {
@@ -751,7 +749,7 @@
                                        php_error_docref(NULL TSRMLS_CC, E_WARNING, 
"No message");
                        }
                        link->errorText = strdup(emg);
-                       link->errorNo  = fbcemdErrorCodeAtIndex(emd, 0);;
+                       link->errorNo = fbcemdErrorCodeAtIndex(emd, 0);;
                        free(emg);
                        fbcemdRelease(emd);
                        fbcmdRelease(md);
@@ -786,7 +784,7 @@
 
 void phpfbestrdup(const char * s, int* length, char** value)
 {
-       int   l = s?strlen(s):0;
+       int l = s?strlen(s):0;
        if (value)
        {
                char* r = emalloc(l+1);
@@ -794,7 +792,7 @@
                        strcpy(r, s);
                else
                        r[0] = 0;
-               *value  = r;
+               *value = r;
        }
        *length = l;
 }
@@ -1290,7 +1288,7 @@
 /* {{{ proto string fbsql_password(resource link_identifier [, string password])
    Get or set the user password used with a connection */
 PHP_FUNCTION(fbsql_password)
-{   
+{
        PHPFBLink* phpLink = NULL;
        zval **fbsql_link_index = NULL, **password = NULL;
 
@@ -1359,17 +1357,6 @@
        }
        ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, 
"FrontBase-Link", le_link, le_plink);
 
-       if (phpLink->execHandler == NULL)
-       {
-               int port = atoi(name);
-               if (port == 0 || port > 64535) {
-                       if (FB_SQL_G(generateWarnings)) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot 
connect to FBExec for database '%s'. (%s)", name, fbcehClassErrorMessage());
-                       }
-                       RETURN_FALSE;
-               }
-       }
-
        if (!php_fbsql_select_db(name, phpLink TSRMLS_CC)) {
                RETURN_FALSE;
        }
@@ -1469,6 +1456,7 @@
        convert_to_string_ex(database_name);
        databaseName = Z_STRVAL_PP(database_name);
 
+       if (phpLink->execHandler == NULL) phpLink->execHandler = 
fbcehHandlerForHost(phpLink->hostName, 128);
        status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName);
        if (status != FBUnknownStatus)
        {
@@ -1542,6 +1530,7 @@
        convert_to_string_ex(database_name);
        databaseName = Z_STRVAL_PP(database_name);
 
+       if (phpLink->execHandler == NULL) phpLink->execHandler = 
fbcehHandlerForHost(phpLink->hostName, 128);
        status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName);
        if (status != FBStopped)
        {
@@ -1616,6 +1605,7 @@
        convert_to_string_ex(database_name);
        databaseName = Z_STRVAL_PP(database_name);
 
+       if (phpLink->execHandler == NULL) phpLink->execHandler = 
fbcehHandlerForHost(phpLink->hostName, 128);
        status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName);
        if ((status != FBStopped) && (status != FBRunning) && (status != FBStarting))
        {
@@ -1752,6 +1742,7 @@
        convert_to_string_ex(database_name);
        databaseName = Z_STRVAL_PP(database_name);
 
+       if (phpLink->execHandler == NULL) phpLink->execHandler = 
fbcehHandlerForHost(phpLink->hostName, 128);
        if (phpLink->execHandler) {
                RETURN_LONG(fbcehStatusForDatabaseNamed(phpLink->execHandler, 
databaseName));
        }
@@ -1795,7 +1786,7 @@
                                php_error_docref(NULL TSRMLS_CC, E_WARNING, "No 
message");
                }
                link->errorText = strdup(emg);
-               link->errorNo  = fbcemdErrorCodeAtIndex(emd, 0);;
+               link->errorNo = fbcemdErrorCodeAtIndex(emd, 0);;
                free(emg);
                fbcemdRelease(emd);
                result = 0;
@@ -1806,7 +1797,7 @@
 
 static void phpfbQuery(INTERNAL_FUNCTION_PARAMETERS, char* sql, PHPFBLink* link)
 {
-       PHPFBResult*  result = NULL;
+       PHPFBResult* result = NULL;
        FBCMetaData*   md, *meta;
        char*          tp;
        char*          fh; 
@@ -1827,7 +1818,7 @@
                else
                        md = meta;
 
-               tp     = fbcmdStatementType(md);
+               tp = fbcmdStatementType(md);
 
                if ((tp[0] == 'C') || (tp[0] == 'R'))
                {
@@ -1866,7 +1857,7 @@
                                
fbcrhConvertToOutputCharSet(fbcdcOutputCharacterSet(link->connection), (unsigned char 
*)r);
                                if ((result->list = fbcplParse(r)))
                                {
-                                       result->rowCount    = fbcplCount(result->list);
+                                       result->rowCount = fbcplCount(result->list);
                                        result->columnCount = 7;
                                }
                        }
@@ -1964,7 +1955,7 @@
    Retreive a list of all databases on the server */
 PHP_FUNCTION(fbsql_list_dbs)
 {
-       PHPFBResult*    phpResult;
+       PHPFBResult* phpResult;
        PHPFBLink* phpLink = NULL;
        zval    **fbsql_link_index = NULL;
        int id;
@@ -1986,6 +1977,7 @@
        }
        ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, 
"FrontBase-Link", le_link, le_plink);
 
+       if (phpLink->execHandler == NULL) phpLink->execHandler = 
fbcehHandlerForHost(phpLink->hostName, 128);
        phpResult = emalloc(sizeof(PHPFBResult));
        phpResult->link        = phpLink;
        phpResult->fetchHandle = NULL;
@@ -2053,10 +2045,10 @@
 PHP_FUNCTION(fbsql_list_fields)
 {
        PHPFBLink* phpLink = NULL;
-       zval    **fbsql_link_index = NULL, **database_name, **table_name;
+       zval **fbsql_link_index = NULL, **database_name, **table_name;
        int id;
        char *databaseName, *tableName;
-       char             sql[1024];
+       char sql[1024];
 
        switch (ZEND_NUM_ARGS()) {
                case 2:
@@ -2160,8 +2152,8 @@
    Enable or disable FrontBase warnings */
 PHP_FUNCTION(fbsql_warnings)
 {
-       int   argc     = ARG_COUNT(ht);
-       zval    **argv[1];
+       int argc = ARG_COUNT(ht);
+       zval **argv[1];
 
        if ((argc < 0) || (argc > 1)) WRONG_PARAM_COUNT;
        if (zend_get_parameters_ex(argc, &argv[0])==FAILURE) RETURN_FALSE;
@@ -2265,12 +2257,12 @@
                                phpfbestrdup("True", length, value);
                }
                break;
-        
+
                case FB_PrimaryKey:
                case FB_Integer:
                { 
-                       int   v = *((int*)data);
-                       char  b[128];
+                       int v = *((int*)data);
+                       char b[128];
                        sprintf(b, "%d", v);
                        phpfbestrdup(b, length, value);
                }
@@ -2278,8 +2270,8 @@
 #ifdef FB_TinyInteger
                case FB_TinyInteger:
                { 
-                       short int   v = *((FBTinyInteger*)data);
-                       char  b[128];
+                       short int v = *((FBTinyInteger*)data);
+                       char b[128];
                        sprintf(b, "%d", v);
                        phpfbestrdup(b, length, value);
                }
@@ -2289,7 +2281,7 @@
                case FB_LongInteger:
                { 
                        FBLongInteger v = *((FBLongInteger*)data);
-                       char  b[128];
+                       char b[128];
 #ifdef PHP_WIN32
                        sprintf(b, "%I64i", v);
 #else
@@ -2302,7 +2294,7 @@
                case FB_SmallInteger:
                {
                        short v = *((short*)data);
-                       char  b[128];
+                       char b[128];
                        sprintf(b, "%d", v);
                        phpfbestrdup(b, length, value);
                }
@@ -2315,7 +2307,7 @@
                case FB_Decimal:
                {
                        double v = *((double*)data);
-                       char  b[128];
+                       char b[128];
                        sprintf(b, "%f", v);
                        phpfbestrdup(b, length, value);
                }
@@ -2332,13 +2324,13 @@
                case FB_Bit:
                case FB_VBit:
                {
-                       const FBCColumnMetaData* clmd  =  
fbcmdColumnMetaDataAtIndex(md, column);
+                       const FBCColumnMetaData* clmd = fbcmdColumnMetaDataAtIndex(md, 
column);
                        struct bitValue
                        {
-                               unsigned int   nBytes;
+                               unsigned int nBytes;
                                unsigned char* bytes;
                        };
-                       struct bitValue*  ptr = data;
+                       struct bitValue* ptr = data;
                        unsigned nBits = ptr->nBytes * 8;
 
                        if (dtc == FB_Bit) nBits = fbcdmdLength(fbccmdDatatype(clmd));
@@ -2349,7 +2341,7 @@
                                *length = l*2+3+1;
                                if (value)
                                {
-                                       char*        r = emalloc(l*2+3+1);
+                                       char* r = emalloc(l*2+3+1);
                                        r[0] = 'X';
                                        r[1] = '\'';
                                        for (i = 0; i < nBits / 8; i++)
@@ -2361,7 +2353,7 @@
                                        }
                                        r[i*2+2] = '\'';
                                        r[i*2+3] = 0;
-                                       *value  = r;
+                                       *value = r;
                                }
                        }
                        else
@@ -2371,7 +2363,7 @@
                                *length = l*2+3+1;
                                if (value)
                                {
-                                       char*        r = emalloc(l*2+3+1);
+                                       char* r = emalloc(l*2+3+1);
                                        r[0] = 'B';
                                        r[1] = '\'';
                                        for (i = 0; i < nBits; i++)
@@ -2382,7 +2374,7 @@
                                        }
                                        r[i*2+2] = '\'';
                                        r[i*2+3] = 0;
-                                       *value  = r;
+                                       *value = r;
                                }
                        }
                }
@@ -2402,7 +2394,7 @@
                case FB_YearMonth:
                {
                        char b[128];
-                       int  v = *((unsigned int*)data);
+                       int v = *((unsigned int*)data);
                        sprintf(b, "%d", v);
                        phpfbestrdup(b, length, value);
                }
@@ -2455,14 +2447,14 @@
 
 /* {{{ phpfbSqlResult 
  */
-void phpfbSqlResult(INTERNAL_FUNCTION_PARAMETERS, PHPFBResult* result, int rowIndex, 
int  columnIndex)
+void phpfbSqlResult(INTERNAL_FUNCTION_PARAMETERS, PHPFBResult* result, int rowIndex, 
int columnIndex)
 {
        void** row;
        if (result->list)
        {
                FBCPList* columns = (FBCPList*)fbcplValueForKey(result->list, 
"COLUMNS");
                FBCPList* column  = (FBCPList*)fbcplValueAtIndex(columns, 
result->rowIndex);
-               if (columnIndex == 0)  
+               if (columnIndex == 0)
                { /* Name */
                        FBCPList* name = (FBCPList*)fbcplValueForKey(column, "NAME");
                        RETURN_STRING((char *)fbcplString((FBCPList*)name), 1);
@@ -2521,7 +2513,7 @@
        }
 }
 /* }}} */
-                       
+
 /* {{{ proto mixed fbsql_result(int result [, int row [, mixed field]])
    ??? */
 PHP_FUNCTION(fbsql_result)
@@ -2560,7 +2552,7 @@
                rowIndex = Z_LVAL_PP(row);
        }
 
-       columnIndex  = result->columnIndex;
+       columnIndex = result->columnIndex;
        if (field)
        {
                if ((Z_TYPE_PP(field) == IS_STRING) && (result->metaData))
@@ -2584,8 +2576,8 @@
                                RETURN_FALSE;
                        }
                }
-    }
-   
+       }
+
        phpfbSqlResult(INTERNAL_FUNCTION_PARAM_PASSTHRU, result, rowIndex, 
columnIndex);
 
        result->columnIndex++;
@@ -2616,9 +2608,9 @@
        }
        ZEND_FETCH_RESOURCE(result, PHPFBResult *, fbsql_result_index, -1, 
"FrontBase-Result", le_result);
 
-    result->currentResult++;
+       result->currentResult++;
        if (result->currentResult < result->selectResults) {
-        if (result->fetchHandle) {
+               if (result->fetchHandle) {
                        FBCMetaData *md = fbcdcCancelFetch(result->link->connection, 
result->fetchHandle);
                        fbcmdRelease(md);
                }
@@ -2927,7 +2919,7 @@
                {
                        if (row[i])
                        {
-                               char*        value;
+                               char* value;
                                unsigned int length;
                                unsigned int c = 0;
                                phpfbColumnAsString(result, i, row[i], &length, &value 
TSRMLS_CC);
@@ -3023,7 +3015,7 @@
        if (array_init(return_value)==FAILURE) RETURN_FALSE;
        for (i=0; i < result->columnCount; i++)
        {
-               unsigned  length = 0;
+               unsigned length = 0;
                if (result->row[i]) phpfbColumnAsString(result, i, result->row[i], 
&length, NULL TSRMLS_CC);
                add_index_long(return_value, i, length);
        }
@@ -3414,9 +3406,9 @@
 PHP_FUNCTION(fbsql_table_name)
 {
        PHPFBResult* result = NULL;
-       zval    **fbsql_result_index = NULL, **table_index;
+       zval **fbsql_result_index = NULL, **table_index;
        unsigned index;
-       char*        value;     
+       char* value;    
        unsigned int length;
        void** row;
 
@@ -3502,6 +3494,7 @@
        }
        ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, 
"FrontBase-Link", le_link, le_plink);
 
+       if (phpLink->execHandler == NULL) phpLink->execHandler = 
fbcehHandlerForHost(phpLink->hostName, 128);
        if (phpLink->execHandler == NULL) {
                if (FB_SQL_G(generateWarnings)) 
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "No valid Exec 
handler available for this connection");

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to