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 */
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 */
} \
}
-static void phpfbReleaseResult (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 phpfbReleaseResult(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 phpfbReleaseResult(zend_rsrc_list_entry *rsrc TSRMLS_DC)
{
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);
}
}
fbsql_globals->persistentCount = 0;
fbsql_globals->linkCount = 0;
}
-
+
PHP_MINIT_FUNCTION(fbsql)
{
ZEND_INIT_MODULE_GLOBALS(fbsql, php_fbsql_init_globals, NULL);
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);
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);
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;
phpLink->connection = NULL;
- le.ptr = phpLink;
+ le.ptr = phpLink;
Z_TYPE(le) = le_plink;
if (zend_hash_update(&EG(persistent_list), name, strlen(name) + 1, &le, sizeof(le), NULL)==FAILURE)
{
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;
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)
{
{
unsigned port;
FBCDatabaseConnection* c;
- FBCMetaData* md;
+ FBCMetaData* md;
if (!link->databaseName || strcmp(link->databaseName, databaseName))
{
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);
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);
strcpy(r, s);
else
r[0] = 0;
- *value = r;
+ *value = r;
}
*length = l;
}
/* {{{ 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;
PHP_FUNCTION(fbsql_select_db)
{
PHPFBLink* phpLink = NULL;
- zval **fbsql_link_index = NULL, **dbname;
+ zval **fbsql_link_index = NULL, **dbname;
int id;
- char* name = NULL;
+ char* name = NULL;
switch (ZEND_NUM_ARGS()) {
case 0:
}
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;
}
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)
{
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)
{
RETURN_FALSE;
}
- if (! fbcehDeleteDatabaseNamed (phpLink->execHandler, databaseName))
+ if (!fbcehDeleteDatabaseNamed(phpLink->execHandler, databaseName))
{
char* error = fbechErrorMessage(phpLink->execHandler);
if (FB_SQL_G(generateWarnings))
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))
{
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));
}
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;
static void phpfbQuery(INTERNAL_FUNCTION_PARAMETERS, char* sql, PHPFBLink* link)
{
- PHPFBResult* result = NULL;
+ PHPFBResult* result = NULL;
FBCMetaData* md, *meta;
char* tp;
char* fh;
unsigned int sR = 1, cR = 0;
- meta = fbcdcExecuteDirectSQL(link->connection, sql);
+ meta = fbcdcExecuteDirectSQL(link->connection, sql);
if (!mdOk(link, meta, sql))
{
else
md = meta;
- tp = fbcmdStatementType(md);
+ tp = fbcmdStatementType(md);
if ((tp[0] == 'C') || (tp[0] == 'R'))
{
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;
}
}
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;
}
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;
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:
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);
}
#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);
}
case FB_LongInteger:
{
FBLongInteger v = *((FBLongInteger*)data);
- char b[128];
+ char b[128];
#ifdef PHP_WIN32
sprintf(b, "%I64i", v);
#else
case FB_SmallInteger:
{
short v = *((short*)data);
- char b[128];
+ char b[128];
sprintf(b, "%d", v);
phpfbestrdup(b, length, value);
}
case FB_Decimal:
{
double v = *((double*)data);
- char b[128];
+ char b[128];
sprintf(b, "%f", v);
phpfbestrdup(b, length, value);
}
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));
*length = l*2+3+1;
if (value)
{
- char* r = safe_emalloc(l, 2, 4);
+ char* r = safe_emalloc(l, 2, 4);
r[0] = 'X';
r[1] = '\'';
for (i = 0; i < nBits / 8; i++)
}
r[i*2+2] = '\'';
r[i*2+3] = 0;
- *value = r;
+ *value = r;
}
}
else
*length = l*2+3+1;
if (value)
{
- char* r = safe_emalloc(l, 2, 1);
+ char* r = safe_emalloc(l, 2, 1);
r[0] = 'B';
r[1] = '\'';
for (i = 0; i < nBits; i++)
}
r[i*2+2] = '\'';
r[i*2+3] = 0;
- *value = r;
+ *value = r;
}
}
}
case FB_YearMonth:
{
char b[128];
- int v = *((unsigned int*)data);
+ int v = *((unsigned int*)data);
sprintf(b, "%d", v);
phpfbestrdup(b, length, value);
}
/* {{{ 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);
}
}
/* }}} */
-
+
/* {{{ proto mixed fbsql_result(int result [, int row [, mixed field]])
??? */
PHP_FUNCTION(fbsql_result)
rowIndex = Z_LVAL_PP(row);
}
- columnIndex = result->columnIndex;
+ columnIndex = result->columnIndex;
if (field)
{
if ((Z_TYPE_PP(field) == IS_STRING) && (result->metaData))
RETURN_FALSE;
}
}
- }
-
+ }
+
phpfbSqlResult(INTERNAL_FUNCTION_PARAM_PASSTHRU, result, rowIndex, columnIndex);
result->columnIndex++;
}
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);
}
{
if (row[i])
{
- char* value;
+ char* value;
unsigned int length;
unsigned int c = 0;
phpfbColumnAsString(result, i, row[i], &length, &value TSRMLS_CC);
array_init(return_value);
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);
}
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;
}
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");