Delay creation of exec handle til it's needed

This commit is contained in:
Frank M. Kromann 2004-02-09 17:58:04 +00:00
parent a55f6cb66c
commit d7961b69e2

View File

@ -83,30 +83,28 @@ typedef struct PHPFBLink PHPFBLink;
required buffereing from of results. required buffereing from of results.
In the PHP code the 3 above a data structures are referenced by means of integers in the 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 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 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. 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 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. 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 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 */ /* Some functions which should be exported from FBCAccess */
void* fbaObjectAtIndex(); void* fbaObjectAtIndex();
void fbaRelease(); void fbaRelease();
unsigned int fbaCount(); unsigned int fbaCount();
struct FBCAutoStartInfo { struct FBCAutoStartInfo {
FBArray* infoLines; FBArray* infoLines;
}; };
struct PHPFBResult struct PHPFBResult
{ {
PHPFBLink* link; /* The link for the result, may be NULL if no link */ PHPFBLink* link; /* The link for the result, may be NULL if no link */
@ -115,7 +113,7 @@ struct PHPFBResult
FBCMetaData* ResultmetaData; /* The metadata describing the result */ FBCMetaData* ResultmetaData; /* The metadata describing the result */
FBCRowHandler* rowHandler; /* The row handler, the Frontbase structure used for accessing rows in 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 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 /* 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 to figure out how many row you got. When the rowCount is unknown the value is
0x7ffffffff */ 0x7ffffffff */
@ -266,9 +264,9 @@ ZEND_GET_MODULE(fbsql)
} \ } \
} }
static void phpfbReleaseResult (zend_rsrc_list_entry *rsrc TSRMLS_DC); static void phpfbReleaseResult(zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void phpfbReleaseLink (zend_rsrc_list_entry *rsrc TSRMLS_DC); static void phpfbReleaseLink(zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void phpfbReleasePLink (zend_rsrc_list_entry *rsrc TSRMLS_DC); static void phpfbReleasePLink(zend_rsrc_list_entry *rsrc TSRMLS_DC);
static void phpfbReleaseResult(zend_rsrc_list_entry *rsrc TSRMLS_DC) static void phpfbReleaseResult(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{ {
@ -280,10 +278,10 @@ static void phpfbReleaseResult(zend_rsrc_list_entry *rsrc TSRMLS_DC)
FBCMetaData *md = fbcdcCancelFetch(result->link->connection, result->fetchHandle); FBCMetaData *md = fbcdcCancelFetch(result->link->connection, result->fetchHandle);
fbcmdRelease(md); fbcmdRelease(md);
} }
if (result->rowHandler) fbcrhRelease(result->rowHandler); if (result->rowHandler) fbcrhRelease(result->rowHandler);
if (result->ResultmetaData) fbcmdRelease(result->ResultmetaData); if (result->ResultmetaData) fbcmdRelease(result->ResultmetaData);
if (result->list) fbcplRelease(result->list); if (result->list) fbcplRelease(result->list);
if (result->array) fbaRelease(result->array); if (result->array) fbaRelease(result->array);
efree(result); efree(result);
} }
} }
@ -389,7 +387,7 @@ static void php_fbsql_init_globals(zend_fbsql_globals *fbsql_globals)
fbsql_globals->persistentCount = 0; fbsql_globals->persistentCount = 0;
fbsql_globals->linkCount = 0; fbsql_globals->linkCount = 0;
} }
PHP_MINIT_FUNCTION(fbsql) PHP_MINIT_FUNCTION(fbsql)
{ {
ZEND_INIT_MODULE_GLOBALS(fbsql, php_fbsql_init_globals, NULL); ZEND_INIT_MODULE_GLOBALS(fbsql, php_fbsql_init_globals, NULL);
@ -397,7 +395,7 @@ PHP_MINIT_FUNCTION(fbsql)
REGISTER_INI_ENTRIES(); REGISTER_INI_ENTRIES();
fbcInitialize(); fbcInitialize();
fbcehSetMultiThreaded(True);
le_result = zend_register_list_destructors_ex(phpfbReleaseResult, NULL, "fbsql result", module_number); 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_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); le_plink = zend_register_list_destructors_ex(NULL, phpfbReleasePLink, "fbsql plink", module_number);
@ -497,12 +495,12 @@ static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
if (argc >= 2) if (argc >= 2)
{ {
convert_to_string_ex(argv[1]); convert_to_string_ex(argv[1]);
userName = Z_STRVAL_PP(argv[1]); userName = Z_STRVAL_PP(argv[1]);
} }
if (argc == 3) if (argc == 3)
{ {
convert_to_string_ex(argv[2]); 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); if (hostName == NULL) hostName = FB_SQL_G(hostName);
@ -543,7 +541,7 @@ static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
phpLink->userPassword = strdup(userPassword); phpLink->userPassword = strdup(userPassword);
phpLink->databasePassword = strdup(FB_SQL_G(databasePassword)); phpLink->databasePassword = strdup(FB_SQL_G(databasePassword));
phpLink->databaseName = NULL; phpLink->databaseName = NULL;
phpLink->execHandler = fbcehHandlerForHost(hostName, 128); phpLink->execHandler = NULL;
phpLink->affectedRows = 0; phpLink->affectedRows = 0;
phpLink->autoCommit = FB_SQL_G(autoCommit); phpLink->autoCommit = FB_SQL_G(autoCommit);
phpLink->errorNo = 0; phpLink->errorNo = 0;
@ -551,7 +549,7 @@ static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
phpLink->connection = NULL; phpLink->connection = NULL;
le.ptr = phpLink; le.ptr = phpLink;
Z_TYPE(le) = le_plink; Z_TYPE(le) = le_plink;
if (zend_hash_update(&EG(persistent_list), name, strlen(name) + 1, &le, sizeof(le), NULL)==FAILURE) if (zend_hash_update(&EG(persistent_list), name, strlen(name) + 1, &le, sizeof(le), NULL)==FAILURE)
{ {
@ -604,7 +602,7 @@ static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
phpLink->userPassword = strdup(userPassword); phpLink->userPassword = strdup(userPassword);
phpLink->databasePassword = strdup(FB_SQL_G(databasePassword)); phpLink->databasePassword = strdup(FB_SQL_G(databasePassword));
phpLink->databaseName = NULL; phpLink->databaseName = NULL;
phpLink->execHandler = fbcehHandlerForHost(hostName, 128); phpLink->execHandler = NULL;
phpLink->affectedRows = 0; phpLink->affectedRows = 0;
phpLink->autoCommit = FB_SQL_G(autoCommit); phpLink->autoCommit = FB_SQL_G(autoCommit);
phpLink->errorNo = 0; phpLink->errorNo = 0;
@ -613,7 +611,7 @@ static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
ZEND_REGISTER_RESOURCE(return_value, phpLink, le_link); 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; Z_TYPE(le) = le_index_ptr;
if (zend_hash_update(&EG(regular_list), name, strlen(name) + 1, &le, sizeof(le), NULL)==FAILURE) if (zend_hash_update(&EG(regular_list), name, strlen(name) + 1, &le, sizeof(le), NULL)==FAILURE)
{ {
@ -723,7 +721,7 @@ static int php_fbsql_select_db(char *databaseName, PHPFBLink *link TSRMLS_DC)
{ {
unsigned port; unsigned port;
FBCDatabaseConnection* c; FBCDatabaseConnection* c;
FBCMetaData* md; FBCMetaData* md;
if (!link->databaseName || strcmp(link->databaseName, databaseName)) if (!link->databaseName || strcmp(link->databaseName, databaseName))
{ {
@ -751,7 +749,7 @@ static int php_fbsql_select_db(char *databaseName, PHPFBLink *link TSRMLS_DC)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No message"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "No message");
} }
link->errorText = strdup(emg); link->errorText = strdup(emg);
link->errorNo = fbcemdErrorCodeAtIndex(emd, 0);; link->errorNo = fbcemdErrorCodeAtIndex(emd, 0);;
free(emg); free(emg);
fbcemdRelease(emd); fbcemdRelease(emd);
fbcmdRelease(md); fbcmdRelease(md);
@ -786,7 +784,7 @@ static int php_fbsql_select_db(char *databaseName, PHPFBLink *link TSRMLS_DC)
void phpfbestrdup(const char * s, int* length, char** value) void phpfbestrdup(const char * s, int* length, char** value)
{ {
int l = s?strlen(s):0; int l = s?strlen(s):0;
if (value) if (value)
{ {
char* r = emalloc(l+1); char* r = emalloc(l+1);
@ -794,7 +792,7 @@ void phpfbestrdup(const char * s, int* length, char** value)
strcpy(r, s); strcpy(r, s);
else else
r[0] = 0; r[0] = 0;
*value = r; *value = r;
} }
*length = l; *length = l;
} }
@ -1290,7 +1288,7 @@ PHP_FUNCTION(fbsql_username)
/* {{{ proto string fbsql_password(resource link_identifier [, string password]) /* {{{ proto string fbsql_password(resource link_identifier [, string password])
Get or set the user password used with a connection */ Get or set the user password used with a connection */
PHP_FUNCTION(fbsql_password) PHP_FUNCTION(fbsql_password)
{ {
PHPFBLink* phpLink = NULL; PHPFBLink* phpLink = NULL;
zval **fbsql_link_index = NULL, **password = NULL; zval **fbsql_link_index = NULL, **password = NULL;
@ -1326,9 +1324,9 @@ PHP_FUNCTION(fbsql_password)
PHP_FUNCTION(fbsql_select_db) PHP_FUNCTION(fbsql_select_db)
{ {
PHPFBLink* phpLink = NULL; PHPFBLink* phpLink = NULL;
zval **fbsql_link_index = NULL, **dbname; zval **fbsql_link_index = NULL, **dbname;
int id; int id;
char* name = NULL; char* name = NULL;
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 0: case 0:
@ -1359,17 +1357,6 @@ PHP_FUNCTION(fbsql_select_db)
} }
ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, "FrontBase-Link", le_link, le_plink); 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)) { if (!php_fbsql_select_db(name, phpLink TSRMLS_CC)) {
RETURN_FALSE; RETURN_FALSE;
} }
@ -1469,6 +1456,7 @@ PHP_FUNCTION(fbsql_create_db)
convert_to_string_ex(database_name); convert_to_string_ex(database_name);
databaseName = Z_STRVAL_PP(database_name); databaseName = Z_STRVAL_PP(database_name);
if (phpLink->execHandler == NULL) phpLink->execHandler = fbcehHandlerForHost(phpLink->hostName, 128);
status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName); status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName);
if (status != FBUnknownStatus) if (status != FBUnknownStatus)
{ {
@ -1542,6 +1530,7 @@ PHP_FUNCTION(fbsql_drop_db)
convert_to_string_ex(database_name); convert_to_string_ex(database_name);
databaseName = Z_STRVAL_PP(database_name); databaseName = Z_STRVAL_PP(database_name);
if (phpLink->execHandler == NULL) phpLink->execHandler = fbcehHandlerForHost(phpLink->hostName, 128);
status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName); status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName);
if (status != FBStopped) if (status != FBStopped)
{ {
@ -1557,7 +1546,7 @@ PHP_FUNCTION(fbsql_drop_db)
RETURN_FALSE; RETURN_FALSE;
} }
if (! fbcehDeleteDatabaseNamed (phpLink->execHandler, databaseName)) if (!fbcehDeleteDatabaseNamed(phpLink->execHandler, databaseName))
{ {
char* error = fbechErrorMessage(phpLink->execHandler); char* error = fbechErrorMessage(phpLink->execHandler);
if (FB_SQL_G(generateWarnings)) if (FB_SQL_G(generateWarnings))
@ -1616,6 +1605,7 @@ PHP_FUNCTION(fbsql_start_db)
convert_to_string_ex(database_name); convert_to_string_ex(database_name);
databaseName = Z_STRVAL_PP(database_name); databaseName = Z_STRVAL_PP(database_name);
if (phpLink->execHandler == NULL) phpLink->execHandler = fbcehHandlerForHost(phpLink->hostName, 128);
status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName); status = fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName);
if ((status != FBStopped) && (status != FBRunning) && (status != FBStarting)) if ((status != FBStopped) && (status != FBRunning) && (status != FBStarting))
{ {
@ -1752,6 +1742,7 @@ PHP_FUNCTION(fbsql_db_status)
convert_to_string_ex(database_name); convert_to_string_ex(database_name);
databaseName = Z_STRVAL_PP(database_name); databaseName = Z_STRVAL_PP(database_name);
if (phpLink->execHandler == NULL) phpLink->execHandler = fbcehHandlerForHost(phpLink->hostName, 128);
if (phpLink->execHandler) { if (phpLink->execHandler) {
RETURN_LONG(fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName)); RETURN_LONG(fbcehStatusForDatabaseNamed(phpLink->execHandler, databaseName));
} }
@ -1795,7 +1786,7 @@ int mdOk(PHPFBLink* link, FBCMetaData* md, char* sql)
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No message"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "No message");
} }
link->errorText = strdup(emg); link->errorText = strdup(emg);
link->errorNo = fbcemdErrorCodeAtIndex(emd, 0);; link->errorNo = fbcemdErrorCodeAtIndex(emd, 0);;
free(emg); free(emg);
fbcemdRelease(emd); fbcemdRelease(emd);
result = 0; result = 0;
@ -1806,13 +1797,13 @@ int mdOk(PHPFBLink* link, FBCMetaData* md, char* sql)
static void phpfbQuery(INTERNAL_FUNCTION_PARAMETERS, char* sql, PHPFBLink* link) static void phpfbQuery(INTERNAL_FUNCTION_PARAMETERS, char* sql, PHPFBLink* link)
{ {
PHPFBResult* result = NULL; PHPFBResult* result = NULL;
FBCMetaData* md, *meta; FBCMetaData* md, *meta;
char* tp; char* tp;
char* fh; char* fh;
unsigned int sR = 1, cR = 0; unsigned int sR = 1, cR = 0;
meta = fbcdcExecuteDirectSQL(link->connection, sql); meta = fbcdcExecuteDirectSQL(link->connection, sql);
if (!mdOk(link, meta, sql)) if (!mdOk(link, meta, sql))
{ {
@ -1827,7 +1818,7 @@ static void phpfbQuery(INTERNAL_FUNCTION_PARAMETERS, char* sql, PHPFBLink* link)
else else
md = meta; md = meta;
tp = fbcmdStatementType(md); tp = fbcmdStatementType(md);
if ((tp[0] == 'C') || (tp[0] == 'R')) if ((tp[0] == 'C') || (tp[0] == 'R'))
{ {
@ -1866,7 +1857,7 @@ static void phpfbQuery(INTERNAL_FUNCTION_PARAMETERS, char* sql, PHPFBLink* link)
fbcrhConvertToOutputCharSet(fbcdcOutputCharacterSet(link->connection), (unsigned char *)r); fbcrhConvertToOutputCharSet(fbcdcOutputCharacterSet(link->connection), (unsigned char *)r);
if ((result->list = fbcplParse(r))) if ((result->list = fbcplParse(r)))
{ {
result->rowCount = fbcplCount(result->list); result->rowCount = fbcplCount(result->list);
result->columnCount = 7; result->columnCount = 7;
} }
} }
@ -1964,7 +1955,7 @@ PHP_FUNCTION(fbsql_db_query)
Retreive a list of all databases on the server */ Retreive a list of all databases on the server */
PHP_FUNCTION(fbsql_list_dbs) PHP_FUNCTION(fbsql_list_dbs)
{ {
PHPFBResult* phpResult; PHPFBResult* phpResult;
PHPFBLink* phpLink = NULL; PHPFBLink* phpLink = NULL;
zval **fbsql_link_index = NULL; zval **fbsql_link_index = NULL;
int id; int id;
@ -1986,6 +1977,7 @@ PHP_FUNCTION(fbsql_list_dbs)
} }
ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, "FrontBase-Link", le_link, le_plink); 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 = emalloc(sizeof(PHPFBResult));
phpResult->link = phpLink; phpResult->link = phpLink;
phpResult->fetchHandle = NULL; phpResult->fetchHandle = NULL;
@ -2053,10 +2045,10 @@ PHP_FUNCTION(fbsql_list_tables)
PHP_FUNCTION(fbsql_list_fields) PHP_FUNCTION(fbsql_list_fields)
{ {
PHPFBLink* phpLink = NULL; PHPFBLink* phpLink = NULL;
zval **fbsql_link_index = NULL, **database_name, **table_name; zval **fbsql_link_index = NULL, **database_name, **table_name;
int id; int id;
char *databaseName, *tableName; char *databaseName, *tableName;
char sql[1024]; char sql[1024];
switch (ZEND_NUM_ARGS()) { switch (ZEND_NUM_ARGS()) {
case 2: case 2:
@ -2265,12 +2257,12 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
phpfbestrdup("True", length, value); phpfbestrdup("True", length, value);
} }
break; break;
case FB_PrimaryKey: case FB_PrimaryKey:
case FB_Integer: case FB_Integer:
{ {
int v = *((int*)data); int v = *((int*)data);
char b[128]; char b[128];
sprintf(b, "%d", v); sprintf(b, "%d", v);
phpfbestrdup(b, length, value); phpfbestrdup(b, length, value);
} }
@ -2278,8 +2270,8 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
#ifdef FB_TinyInteger #ifdef FB_TinyInteger
case FB_TinyInteger: case FB_TinyInteger:
{ {
short int v = *((FBTinyInteger*)data); short int v = *((FBTinyInteger*)data);
char b[128]; char b[128];
sprintf(b, "%d", v); sprintf(b, "%d", v);
phpfbestrdup(b, length, value); phpfbestrdup(b, length, value);
} }
@ -2289,7 +2281,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
case FB_LongInteger: case FB_LongInteger:
{ {
FBLongInteger v = *((FBLongInteger*)data); FBLongInteger v = *((FBLongInteger*)data);
char b[128]; char b[128];
#ifdef PHP_WIN32 #ifdef PHP_WIN32
sprintf(b, "%I64i", v); sprintf(b, "%I64i", v);
#else #else
@ -2302,7 +2294,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
case FB_SmallInteger: case FB_SmallInteger:
{ {
short v = *((short*)data); short v = *((short*)data);
char b[128]; char b[128];
sprintf(b, "%d", v); sprintf(b, "%d", v);
phpfbestrdup(b, length, value); phpfbestrdup(b, length, value);
} }
@ -2315,7 +2307,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
case FB_Decimal: case FB_Decimal:
{ {
double v = *((double*)data); double v = *((double*)data);
char b[128]; char b[128];
sprintf(b, "%f", v); sprintf(b, "%f", v);
phpfbestrdup(b, length, value); phpfbestrdup(b, length, value);
} }
@ -2332,13 +2324,13 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
case FB_Bit: case FB_Bit:
case FB_VBit: case FB_VBit:
{ {
const FBCColumnMetaData* clmd = fbcmdColumnMetaDataAtIndex(md, column); const FBCColumnMetaData* clmd = fbcmdColumnMetaDataAtIndex(md, column);
struct bitValue struct bitValue
{ {
unsigned int nBytes; unsigned int nBytes;
unsigned char* bytes; unsigned char* bytes;
}; };
struct bitValue* ptr = data; struct bitValue* ptr = data;
unsigned nBits = ptr->nBytes * 8; unsigned nBits = ptr->nBytes * 8;
if (dtc == FB_Bit) nBits = fbcdmdLength(fbccmdDatatype(clmd)); if (dtc == FB_Bit) nBits = fbcdmdLength(fbccmdDatatype(clmd));
@ -2349,7 +2341,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
*length = l*2+3+1; *length = l*2+3+1;
if (value) if (value)
{ {
char* r = safe_emalloc(l, 2, 4); char* r = safe_emalloc(l, 2, 4);
r[0] = 'X'; r[0] = 'X';
r[1] = '\''; r[1] = '\'';
for (i = 0; i < nBits / 8; i++) for (i = 0; i < nBits / 8; i++)
@ -2361,7 +2353,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
} }
r[i*2+2] = '\''; r[i*2+2] = '\'';
r[i*2+3] = 0; r[i*2+3] = 0;
*value = r; *value = r;
} }
} }
else else
@ -2371,7 +2363,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
*length = l*2+3+1; *length = l*2+3+1;
if (value) if (value)
{ {
char* r = safe_emalloc(l, 2, 1); char* r = safe_emalloc(l, 2, 1);
r[0] = 'B'; r[0] = 'B';
r[1] = '\''; r[1] = '\'';
for (i = 0; i < nBits; i++) for (i = 0; i < nBits; i++)
@ -2382,7 +2374,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
} }
r[i*2+2] = '\''; r[i*2+2] = '\'';
r[i*2+3] = 0; r[i*2+3] = 0;
*value = r; *value = r;
} }
} }
} }
@ -2402,7 +2394,7 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
case FB_YearMonth: case FB_YearMonth:
{ {
char b[128]; char b[128];
int v = *((unsigned int*)data); int v = *((unsigned int*)data);
sprintf(b, "%d", v); sprintf(b, "%d", v);
phpfbestrdup(b, length, value); phpfbestrdup(b, length, value);
} }
@ -2455,14 +2447,14 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng
/* {{{ phpfbSqlResult /* {{{ 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; void** row;
if (result->list) if (result->list)
{ {
FBCPList* columns = (FBCPList*)fbcplValueForKey(result->list, "COLUMNS"); FBCPList* columns = (FBCPList*)fbcplValueForKey(result->list, "COLUMNS");
FBCPList* column = (FBCPList*)fbcplValueAtIndex(columns, result->rowIndex); FBCPList* column = (FBCPList*)fbcplValueAtIndex(columns, result->rowIndex);
if (columnIndex == 0) if (columnIndex == 0)
{ /* Name */ { /* Name */
FBCPList* name = (FBCPList*)fbcplValueForKey(column, "NAME"); FBCPList* name = (FBCPList*)fbcplValueForKey(column, "NAME");
RETURN_STRING((char *)fbcplString((FBCPList*)name), 1); RETURN_STRING((char *)fbcplString((FBCPList*)name), 1);
@ -2521,7 +2513,7 @@ void phpfbSqlResult(INTERNAL_FUNCTION_PARAMETERS, PHPFBResult* result, int rowIn
} }
} }
/* }}} */ /* }}} */
/* {{{ proto mixed fbsql_result(int result [, int row [, mixed field]]) /* {{{ proto mixed fbsql_result(int result [, int row [, mixed field]])
??? */ ??? */
PHP_FUNCTION(fbsql_result) PHP_FUNCTION(fbsql_result)
@ -2560,7 +2552,7 @@ PHP_FUNCTION(fbsql_result)
rowIndex = Z_LVAL_PP(row); rowIndex = Z_LVAL_PP(row);
} }
columnIndex = result->columnIndex; columnIndex = result->columnIndex;
if (field) if (field)
{ {
if ((Z_TYPE_PP(field) == IS_STRING) && (result->metaData)) if ((Z_TYPE_PP(field) == IS_STRING) && (result->metaData))
@ -2584,8 +2576,8 @@ PHP_FUNCTION(fbsql_result)
RETURN_FALSE; RETURN_FALSE;
} }
} }
} }
phpfbSqlResult(INTERNAL_FUNCTION_PARAM_PASSTHRU, result, rowIndex, columnIndex); phpfbSqlResult(INTERNAL_FUNCTION_PARAM_PASSTHRU, result, rowIndex, columnIndex);
result->columnIndex++; result->columnIndex++;
@ -2616,9 +2608,9 @@ PHP_FUNCTION(fbsql_next_result)
} }
ZEND_FETCH_RESOURCE(result, PHPFBResult *, fbsql_result_index, -1, "FrontBase-Result", le_result); ZEND_FETCH_RESOURCE(result, PHPFBResult *, fbsql_result_index, -1, "FrontBase-Result", le_result);
result->currentResult++; result->currentResult++;
if (result->currentResult < result->selectResults) { if (result->currentResult < result->selectResults) {
if (result->fetchHandle) { if (result->fetchHandle) {
FBCMetaData *md = fbcdcCancelFetch(result->link->connection, result->fetchHandle); FBCMetaData *md = fbcdcCancelFetch(result->link->connection, result->fetchHandle);
fbcmdRelease(md); fbcmdRelease(md);
} }
@ -2924,7 +2916,7 @@ static void php_fbsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type,
{ {
if (row[i]) if (row[i])
{ {
char* value; char* value;
unsigned int length; unsigned int length;
unsigned int c = 0; unsigned int c = 0;
phpfbColumnAsString(result, i, row[i], &length, &value TSRMLS_CC); phpfbColumnAsString(result, i, row[i], &length, &value TSRMLS_CC);
@ -3020,7 +3012,7 @@ PHP_FUNCTION(fbsql_fetch_lengths)
array_init(return_value); array_init(return_value);
for (i=0; i < result->columnCount; i++) 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); if (result->row[i]) phpfbColumnAsString(result, i, result->row[i], &length, NULL TSRMLS_CC);
add_index_long(return_value, i, length); add_index_long(return_value, i, length);
} }
@ -3409,9 +3401,9 @@ PHP_FUNCTION(fbsql_field_flags)
PHP_FUNCTION(fbsql_table_name) PHP_FUNCTION(fbsql_table_name)
{ {
PHPFBResult* result = NULL; PHPFBResult* result = NULL;
zval **fbsql_result_index = NULL, **table_index; zval **fbsql_result_index = NULL, **table_index;
unsigned index; unsigned index;
char* value; char* value;
unsigned int length; unsigned int length;
void** row; void** row;
@ -3497,6 +3489,7 @@ PHP_FUNCTION(fbsql_get_autostart_info)
} }
ZEND_FETCH_RESOURCE2(phpLink, PHPFBLink *, fbsql_link_index, id, "FrontBase-Link", le_link, le_plink); 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 (phpLink->execHandler == NULL) {
if (FB_SQL_G(generateWarnings)) if (FB_SQL_G(generateWarnings))
php_error_docref(NULL TSRMLS_CC, E_WARNING, "No valid Exec handler available for this connection"); php_error_docref(NULL TSRMLS_CC, E_WARNING, "No valid Exec handler available for this connection");