Re: cvs: php4 /ext/mssql php_mssql.c
| From: | Andi Gutmans | Date: | Tue, 08 May 2001 18:15:04 +0000 |
| Subject: | Re: cvs: php4 /ext/mssql php_mssql.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-5600@lists.php.net to get a copy of this message | ||
Frank,
Are you sure you need to use the memset()'s? Can't you get the length from the mssql functions? It's a bit slow.
Also if you emalloc a string of length x you need to do memset(str, 0, x) and not memset(str, 0, x+1);. You are overwriting memory which isn't yours (line 763).
Andi
At 06:10 PM 5/8/2001 +0000, Frank M. Kromann wrote:
fmk Tue May 8 11:10:25 2001 EDTModified files:/php4/ext/mssql php_mssql.cLog: Fixing the use of compatibility_mode setting in php.ini. Nuking trailing spaces when returning a string. Index: php4/ext/mssql/php_mssql.c diff -u php4/ext/mssql/php_mssql.c:1.42 php4/ext/mssql/php_mssql.c:1.43--- php4/ext/mssql/php_mssql.c:1.42 Tue May 1 11:13:59 2001+++ php4/ext/mssql/php_mssql.c Tue May 8 11:10:25 2001 @@ -16,7 +16,7 @@+----------------------------------------------------------------------+*/ -/* $Id: php_mssql.c,v 1.42 2001/05/01 18:13:59 andi Exp $ */ +/* $Id: php_mssql.c,v 1.43 2001/05/08 18:10:25 fmk Exp $ */ #ifdef COMPILE_DL_MSSQL #define HAVE_MSSQL 1 @@ -226,11 +226,15 @@ 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 @@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 @@if (dbinit()==FAIL) { return FAILURE; }+dberrhandle((DBERRHANDLE_PROC) php_mssql_error_handler); dbmsghandle((DBMSGHANDLE_PROC) php_mssql_message_handler);@@ -754,11 +760,15 @@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 @@} 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 @@case SQLINT1: case SQLINT2: case SQLINT4: + case SQLINTN: case SQLFLT8: case SQLNUMERIC: case SQLDECIMAL:-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-cvs-unsubscribe@lists.php.net For additional commands, e-mail: php-cvs-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net