diff options
-rw-r--r-- | ext/fbsql/php_fbsql.c | 60 | ||||
-rw-r--r-- | ext/fbsql/php_fbsql.h | 34 | ||||
-rw-r--r-- | php.ini-dist | 1 | ||||
-rw-r--r-- | php.ini-recommended | 1 |
4 files changed, 76 insertions, 20 deletions
diff --git a/ext/fbsql/php_fbsql.c b/ext/fbsql/php_fbsql.c index e78d14bffe..9070fb890d 100644 --- a/ext/fbsql/php_fbsql.c +++ b/ext/fbsql/php_fbsql.c @@ -58,6 +58,10 @@ #define HAVE_FBSQL 1 +#ifndef min +# define min(a,b) ((a)<(b)?(a):(b)) +#endif + #if HAVE_FBSQL #include "php_fbsql.h" #include <signal.h> @@ -737,6 +741,7 @@ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN ("fbsql.allow_persistent", "1", PHP_INI_SYSTEM, OnUpdateBool, allowPersistent, zend_fbsql_globals, fbsql_globals) STD_PHP_INI_BOOLEAN ("fbsql.generate_warnings", "0", PHP_INI_SYSTEM, OnUpdateBool, generateWarnings, zend_fbsql_globals, fbsql_globals) STD_PHP_INI_BOOLEAN ("fbsql.autocommit", "1", PHP_INI_SYSTEM, OnUpdateBool, autoCommit, zend_fbsql_globals, fbsql_globals) + STD_PHP_INI_BOOLEAN ("fbsql.show_timestamp_decimals", "0", PHP_INI_SYSTEM, OnUpdateBool, showTimestampDecimals, zend_fbsql_globals, fbsql_globals) STD_PHP_INI_ENTRY_EX ("fbsql.max_persistent", "-1", PHP_INI_SYSTEM, OnUpdateLong, maxPersistent, zend_fbsql_globals, fbsql_globals, display_link_numbers) STD_PHP_INI_ENTRY_EX ("fbsql.max_links", "128", PHP_INI_SYSTEM, OnUpdateLong, maxLinks, zend_fbsql_globals, fbsql_globals, display_link_numbers) STD_PHP_INI_ENTRY_EX ("fbsql.max_connections", "128", PHP_INI_SYSTEM, OnUpdateLong, maxConnections, zend_fbsql_globals, fbsql_globals, display_link_numbers) @@ -896,7 +901,26 @@ static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent) if (persistent) { if (zend_hash_find(&EG(persistent_list), name, strlen(name) + 1, (void **)&lep) == SUCCESS) { + FBCMetaData *md; phpLink = (PHPFBLink*)lep->ptr; + // Check if connection still there. + md = fbcdcRollback(phpLink->connection); + if ( !mdOk(phpLink, md, "Rollback;") ) { + if (FB_SQL_G(generateWarnings)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "FrontBase link is not connected, ty to reconnect."); + } + // Make sure select_db will reconnect. + fbcmdRelease(md); + fbcdcClose(phpLink->connection); + fbcdcRelease(phpLink->connection); + free(phpLink->connection); + phpLink->connection = NULL; + if (phpLink->databaseName) free(phpLink->databaseName); + phpLink->databaseName = NULL; + } + else { + fbcmdRelease(md); + } } else { zend_rsrc_list_entry le; @@ -2866,8 +2890,6 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng case FB_Float: case FB_Real: case FB_Double: - case FB_Numeric: - case FB_Decimal: { double v = *((double*)data); char b[128]; @@ -2876,6 +2898,18 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng } break; + case FB_Numeric: + case FB_Decimal: + { + unsigned precision = fbcdmdPrecision(dtmd); + unsigned scale = fbcdmdScale(dtmd); + double v = *((double*)data); + char b[128]; + snprintf(b, sizeof(b), "%.*f", scale, v); + phpfbestrdup(b, length, value); + } + break; + case FB_Character: case FB_VCharacter: { @@ -2946,7 +2980,6 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng case FB_Date: case FB_Time: case FB_TimeTZ: - case FB_Timestamp: case FB_TimestampTZ: { char* v = (char*)data; @@ -2954,6 +2987,27 @@ void phpfbColumnAsString(PHPFBResult* result, int column, void* data , int* leng } break; + case FB_Timestamp: + { + char* v = (char*)data; + if (FB_SQL_G(showTimestampDecimals)) { + phpfbestrdup(v, length, value); + } + // Copy only YYYY-MM-DD HH:MM:SS + else { + int stringLength = strlen(v); + stringLength = min(stringLength, 19); + if (value) { + char* r = emalloc(stringLength+1); + memcpy(r, v, stringLength); + r[stringLength] = 0; + *value = r; + } + *length = stringLength; + } + } + break; + case FB_YearMonth: { char b[128]; diff --git a/ext/fbsql/php_fbsql.h b/ext/fbsql/php_fbsql.h index 6b0b36d38c..c1fcf6eced 100644 --- a/ext/fbsql/php_fbsql.h +++ b/ext/fbsql/php_fbsql.h @@ -108,23 +108,23 @@ static void php_fbsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type, static void php_fbsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent); ZEND_BEGIN_MODULE_GLOBALS(fbsql) - zend_bool allowPersistent; - zend_bool generateWarnings; - zend_bool autoCommit; - long maxPersistent; - long maxLinks; - long maxConnections; - long maxResults; - long batchSize; - char *hostName; - char *databaseName; - char *databasePassword; - char *userName; - char *userPassword; - long persistentCount; - long linkCount; - long linkIndex; - + zend_bool allowPersistent; + zend_bool generateWarnings; + zend_bool autoCommit; + zend_bool showTimestampDecimals; + long maxPersistent; + long maxLinks; + long maxConnections; + long maxResults; + long batchSize; + char *hostName; + char *databaseName; + char *databasePassword; + char *userName; + char *userPassword; + long persistentCount; + long linkCount; + long linkIndex; ZEND_END_MODULE_GLOBALS(fbsql) #ifdef ZTS diff --git a/php.ini-dist b/php.ini-dist index 0bb253929a..f5ec38ed4c 100644 --- a/php.ini-dist +++ b/php.ini-dist @@ -1072,6 +1072,7 @@ pfpro.defaulttimeout = 30 [FrontBase] ;fbsql.allow_persistent = On ;fbsql.autocommit = On +;fbsql.show_timestamp_decimals = Off ;fbsql.default_database = ;fbsql.default_database_password = ;fbsql.default_host = diff --git a/php.ini-recommended b/php.ini-recommended index 8f20cc2bc1..86c25f8da2 100644 --- a/php.ini-recommended +++ b/php.ini-recommended @@ -1103,6 +1103,7 @@ pfpro.defaulttimeout = 30 [FrontBase] ;fbsql.allow_persistent = On ;fbsql.autocommit = On +;fbsql.show_timestamp_decimals = Off ;fbsql.default_database = ;fbsql.default_database_password = ;fbsql.default_host = |