Index: ext/sybase_ct/php_sybase_ct.c
===================================================================
RCS file: /repository/php-src/ext/sybase_ct/php_sybase_ct.c,v
retrieving revision 1.97
diff -u -r1.97 php_sybase_ct.c
--- ext/sybase_ct/php_sybase_ct.c	10 Jul 2004 07:46:08 -0000	1.97
+++ ext/sybase_ct/php_sybase_ct.c	11 Jul 2004 13:10:37 -0000
@@ -1087,6 +1087,19 @@
 	return retcode;
 }
 
+#define RETURN_DOUBLE_VAL(result, buf, length)          \
+	if ((length - 1) <= EG(precision)) {                \
+		errno = 0;                                      \
+		Z_DVAL(result) = strtod(buf, NULL);             \
+		if (errno != ERANGE) {                          \
+			Z_TYPE(result) = IS_DOUBLE;                 \
+		} else {                                        \
+			ZVAL_STRINGL(&result, buf, length- 1, 1);   \
+		}                                               \
+	} else {                                            \
+		ZVAL_STRINGL(&result, buf, length- 1, 1);       \
+	}
+
 static int php_sybase_fetch_result_row (sybase_result *result, int numrows)
 {
 	int i, j;
@@ -1107,7 +1120,6 @@
 		}
 		*/
 		
-		/* i= result->num_rows++; */
 		result->num_rows++;
 		i= result->store ? result->num_rows- 1 : 0;
 		if (i >= result->blocks_initialized*SYBASE_ROWS_BLOCK) {
@@ -1117,27 +1129,42 @@
 			result->data[i] = (zval *) safe_emalloc(sizeof(zval), result->num_fields, 0);
 		}
 
-		for (j=0; j<result->num_fields; j++) {
+		for (j = 0; j < result->num_fields; j++) {
 			if (result->indicators[j] == -1) { /* null value */
 				ZVAL_NULL(&result->data[i][j]);
 			} else {
-				Z_STRLEN(result->data[i][j]) = result->lengths[j]-1;  /* we don't need the NULL in the length */
-				Z_STRVAL(result->data[i][j]) = estrndup(result->tmp_buffer[j], result->lengths[j]);
-				Z_TYPE(result->data[i][j]) = IS_STRING;
-				
 				switch (result->numerics[j]) {
-					case 1:
-						convert_to_long(&result->data[i][j]);
+					case 1: {
+						/* This indicates a long */
+						ZVAL_LONG(&result->data[i][j], strtol(result->tmp_buffer[j], NULL, 10));
+						break;
+					}
+					
+					case 2: {
+						/* This indicates a float */
+						RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); 
 						break;
-					case 2:
-						convert_to_double(&result->data[i][j]);
+					}
+
+					case 3: {
+						/* This indicates either a long or a float, which ever fits */
+						errno = 0;
+						Z_LVAL(result->data[i][j]) = strtol(result->tmp_buffer[j], NULL, 10);
+						if (errno == ERANGE) {
+						
+							/* An overflow occurred, so try to fit it into a double */
+							RETURN_DOUBLE_VAL(result->data[i][j], result->tmp_buffer[j], result->lengths[j]); 
+							break;
+						}
+						Z_TYPE(result->data[i][j]) = IS_LONG;
 						break;
-					case 3:
-						/* This signals we have an integer datatype, but we need to convert to double if we 
-						 * overflow. 
-						 */
-						convert_scalar_to_number(&result->data[i][j] TSRMLS_CC);
+					}
+					
+					default: {
+						/* This indicates anything else, return it as string */
+						ZVAL_STRINGL(&result->data[i][j], result->tmp_buffer[j], result->lengths[j]- 1, 1);
 						break;
+					}	   
 				}
 			}
 		}
