mirror of
https://github.com/php/php-src.git
synced 2026-04-11 10:03:18 +02:00
Fixing the use of compatibility_mode setting in php.ini.
Nuking trailing spaces when returning a string.
This commit is contained in:
@@ -226,11 +226,15 @@ static void _close_mssql_plink(zend_rsrc_list_entry *rsrc)
|
||||
|
||||
static void php_mssql_init_globals(zend_mssql_globals *mssql_globals)
|
||||
{
|
||||
long compatability_mode;
|
||||
|
||||
MS_SQL_G(num_persistent) = 0;
|
||||
if (MS_SQL_G(compatability_mode)) {
|
||||
MS_SQL_G(get_column_content) = php_mssql_get_column_content_with_type;
|
||||
} else {
|
||||
MS_SQL_G(get_column_content) = php_mssql_get_column_content_without_type;
|
||||
if (cfg_get_long("mssql.compatability_mode", &compatability_mode) == SUCCESS) {
|
||||
if (compatability_mode) {
|
||||
MS_SQL_G(get_column_content) = php_mssql_get_column_content_with_type;
|
||||
} else {
|
||||
MS_SQL_G(get_column_content) = php_mssql_get_column_content_without_type;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +243,7 @@ PHP_MINIT_FUNCTION(mssql)
|
||||
ZEND_INIT_MODULE_GLOBALS(mssql, php_mssql_init_globals, NULL);
|
||||
|
||||
REGISTER_INI_ENTRIES();
|
||||
|
||||
le_result = zend_register_list_destructors_ex(_free_mssql_result, NULL, "mssql result", module_number);
|
||||
le_link = zend_register_list_destructors_ex(_close_mssql_link, NULL, "mssql link", module_number);
|
||||
le_plink = zend_register_list_destructors_ex(NULL, _close_mssql_plink, "mssql link persistent", module_number);
|
||||
@@ -247,6 +252,7 @@ PHP_MINIT_FUNCTION(mssql)
|
||||
if (dbinit()==FAIL) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
dberrhandle((DBERRHANDLE_PROC) php_mssql_error_handler);
|
||||
dbmsghandle((DBMSGHANDLE_PROC) php_mssql_message_handler);
|
||||
|
||||
@@ -754,11 +760,15 @@ static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int off
|
||||
if (column_type == SQLDATETIME) res_length += 10;
|
||||
|
||||
res_buf = (char *) emalloc(res_length);
|
||||
memset(res_buf, 0, res_length);
|
||||
memset(res_buf, 0, res_length + 1);
|
||||
dbconvert(NULL,column_type,dbdata(mssql_ptr->link,offset), res_length,SQLCHAR,res_buf,-1);
|
||||
|
||||
result->value.str.len = res_length;
|
||||
while (res_length>0 && (res_buf[res_length-1] == ' ' || res_buf[res_length-1] == 0)) { /* nuke trailing whitespace */
|
||||
res_length--;
|
||||
}
|
||||
res_buf[res_length] = 0;
|
||||
result->value.str.val = res_buf;
|
||||
result->value.str.len = res_length;
|
||||
result->type = IS_STRING;
|
||||
} else {
|
||||
php_error(E_WARNING,"MS SQL: column %d has unknown data type (%d)", offset, coltype(offset));
|
||||
@@ -792,14 +802,20 @@ static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int
|
||||
}
|
||||
else if (dbwillconvert(coltype(offset),SQLCHAR)) {
|
||||
unsigned char *res_buf;
|
||||
int res_length = dbdatlen(mssql_ptr->link,offset);
|
||||
int res_length = dbdatlen(mssql_ptr->link,offset) + 1;
|
||||
if (column_type == SQLDATETIM4) res_length += 14;
|
||||
if (column_type == SQLDATETIME) res_length += 10;
|
||||
|
||||
res_buf = (unsigned char *) emalloc(res_length+1 + 19);
|
||||
memset(res_buf, 0, res_length+1 + 10);
|
||||
res_buf = (unsigned char *) emalloc(res_length+1);
|
||||
memset(res_buf, 0, res_length + 1);
|
||||
dbconvert(NULL,coltype(offset),dbdata(mssql_ptr->link,offset), res_length, SQLCHAR,res_buf,-1);
|
||||
|
||||
result->value.str.len = strlen(res_buf);
|
||||
while (res_length>0 && (res_buf[res_length-1] == ' ' || res_buf[res_length-1] == 0)) { /* nuke trailing whitespace */
|
||||
res_length--;
|
||||
}
|
||||
res_buf[res_length] = 0;
|
||||
result->value.str.val = res_buf;
|
||||
result->value.str.len = res_length;
|
||||
result->type = IS_STRING;
|
||||
} else {
|
||||
php_error(E_WARNING,"MS SQL: column %d has unknown data type (%d)", offset, coltype(offset));
|
||||
@@ -843,6 +859,7 @@ int _mssql_fetch_batch(mssql_link *mssql_ptr, mssql_result *result, int retvalue
|
||||
case SQLINT1:
|
||||
case SQLINT2:
|
||||
case SQLINT4:
|
||||
case SQLINTN:
|
||||
case SQLFLT8:
|
||||
case SQLNUMERIC:
|
||||
case SQLDECIMAL:
|
||||
|
||||
Reference in New Issue
Block a user