RE: [PHP-DEV] [PATCH] bug 12655: datetime format in mssql extens ion

From: Date: Wed, 17 Apr 2002 15:17:46 +0000
Subject: RE: [PHP-DEV] [PATCH] bug 12655: datetime format in mssql extens ion
Groups: php.dev 
Request: Send a blank email to php-dev+get-82908@lists.php.net to get a copy of this message
Here is the diff -u. I couldn't figure out how to get diff to use a different tab size so some of the column spacing looks whacked. (I was rather suprised that the code uses tabs, perhaps CVS does a spaces to tabs conversion). Also.. I might have gotten #$*@#& MS Outlook not to html format this eMail. Steve Dillon --- php_mssql.orig Sun Dec 02 16:17:55 2001 +++ php_mssql.c Tue Apr 16 17:00:24 2002 @@ -42,8 +42,8 @@ static int le_result, le_link, le_plink, le_statement; -static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type); -static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type); +static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type,long longdatetime); +static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type,long longdatetime); static void _mssql_bind_hash_dtor(void *data); static unsigned char a3_arg_force_ref[] = { 3, BYREF_NONE, BYREF_NONE, BYREF_FORCE }; @@ -134,6 +134,7 @@ STD_PHP_INI_ENTRY_EX("mssql.textsize", "-1", PHP_INI_ALL, OnUpdateInt, textsize, zend_mssql_globals, mssql_globals, display_text_size) STD_PHP_INI_ENTRY_EX("mssql.textlimit", "-1", PHP_INI_ALL, OnUpdateInt, textlimit, zend_mssql_globals, mssql_globals, display_text_size) STD_PHP_INI_ENTRY_EX("mssql.batchsize", "0", PHP_INI_ALL, OnUpdateInt, batchsize, zend_mssql_globals, mssql_globals, display_link_numbers) + STD_PHP_INI_BOOLEAN("mssql.longdatetime", "0", PHP_INI_ALL, OnUpdateBool, longdatetime, zend_mssql_globals, mssql_globals) PHP_INI_END() /* error handler */ @@ -736,7 +737,7 @@ /* }}} */ -static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type) +static void php_mssql_get_column_content_with_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type,long longdatetime) { if (dbdatlen(mssql_ptr->link,offset) == 0) { ZVAL_NULL(result); @@ -792,13 +793,34 @@ case SQLNUMERIC: default: { if (dbwillconvert(column_type,SQLCHAR)) { - char *res_buf; - int res_length = dbdatlen(mssql_ptr->link,offset); - if (column_type == SQLDATETIM4) res_length += 14; - if (column_type == SQLDATETIME) res_length += 10; - - res_buf = (char *) emalloc(res_length + 1); - res_length = dbconvert(NULL,column_type,dbdata(mssql_ptr->link,offset), res_length,SQLCHAR,res_buf,-1); + char *res_buf; + int res_length; + + if (column_type == SQLDATETIME && longdatetime ) { + /* if it is the long date time format and user wants the extended date/time (with seconds and millis)*/ + /* then output: 2001-03-15 23:06:36.000 */ + DBDATEREC dr; + + if (dbdatecrack(mssql_ptr->link,&dr,(DBDATETIME *)dbdata(mssql_ptr->link,offset)) != SUCCEED) { + php_error(E_ERROR,"MS SQL: column %d unable to convert datetime field", offset); + ZVAL_FALSE(result); + /* no further processing */ + return; + } + + res_length = 23; + res_buf = (char *) emalloc(res_length+1); + sprintf(res_buf,"%4d-%02d-%02d %02d:%02d:%02d.%03d", + dr.year,dr.month,dr.day,dr.hour,dr.minute,dr.second,dr.millisecond); + + } else { + res_length = dbdatlen(mssql_ptr->link,offset); + if (column_type == SQLDATETIM4) res_length += 14; + if (column_type == SQLDATETIME) res_length += 10; + + res_buf = (char *) emalloc(res_length + 1); + res_length = dbconvert(NULL,column_type,dbdata(mssql_ptr->link,offset), res_length,SQLCHAR,res_buf,-1); + } result->value.str.val = res_buf; result->value.str.len = res_length; @@ -811,7 +833,7 @@ } } -static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type) +static void php_mssql_get_column_content_without_type(mssql_link *mssql_ptr,int offset,zval *result, int column_type, long unused) { if (dbdatlen(mssql_ptr->link,offset) == 0) { ZVAL_NULL(result); @@ -856,6 +878,11 @@ int i, j = 0; int *column_types; char computed_buf[16]; + /* Ugh.. It would be cleaner to fetch the longdatetime in */ + /* get_column_content_with_type, but doing the thread-safe lookup */ + /* for every row that has a datetime field seems bad also. So get it */ + /* here and pass the value in */ + long longdatetime = MS_SQL_G(longdatetime); column_types = (int *) emalloc(sizeof(int) * result->num_fields); for (i=0; i<result->num_fields; i++) { @@ -913,7 +940,7 @@ result->data[i] = (zval *) emalloc(sizeof(zval)*result->num_fields); for (j=0; j<result->num_fields; j++) { INIT_ZVAL(result->data[i][j]); - MS_SQL_G(get_column_content(mssql_ptr, j+1, &result->data[i][j], column_types[j])); + MS_SQL_G(get_column_content(mssql_ptr, j+1, &result->data[i][j], column_types[j],longdatetime)); } if (i<result->batchsize || result->batchsize==0) { i++; -----Original Message----- From: derick@php.net [mailto:derick@php.net] Sent: Wednesday, April 17, 2002 1:15 AM To: steve dillon Cc: 'php-dev@lists.php.net' Subject: Re: [PHP-DEV] [PATCH] bug 12655: datetime format in mssql extension Hello Steve, can you please make a unified diff (diff -u)? That is much more readable. Derick

« previous php.dev (#82908) next »