php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11530 PATCH: InterBase/Firebird Decimal/Numeric type returns incorrect value type
Submitted: 2001-06-18 00:53 UTC Modified: 2002-04-13 14:52 UTC
From: watanabe at obcis dot com Assigned:
Status: Closed Package: InterBase related
PHP Version: 4.0.5 OS: Debian Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: watanabe at obcis dot com
New email:
PHP Version: OS:

 

 [2001-06-18 00:53 UTC] watanabe at obcis dot com
ibase_query() returns incorrect value about Decimal/Numeric type on
InterBase6/Firebird.

--- interbase.c.orig	Fri Jun 15 11:32:31 2001
+++ interbase.c	Tue Jun 12 18:09:07 2001
@@ -1741,7 +1741,22 @@
 			val->value.str.len = len;
 			break;
 		case SQL_LONG:
-			if (scale) {
+			if (scale < 0) {
+				int j;
+				long dt, dth, dtl, pow_scale = 1;
+				for (j = 0; j < -scale; j++) pow_scale *= 10;
+				dt = *(long *)data;
+				dth = dt / pow_scale;
+				dtl = dt % pow_scale;
+				if (dtl < 0) dtl *= -1;
+				if ((dt < 0) && (dth == 0)) {
+					val->value.str.len = sprintf(string_data, "-0.%0*ld", -scale, dtl);
+				} else {
+					val->value.str.len = sprintf(string_data, "%ld.%0*ld", dth, -scale, dtl);
+				}
+				val->type = IS_STRING;
+				val->value.str.val = estrdup(string_data);
+				/*
 				int j, f = 1;
 				float n = (float) *(long *)(data);
 				
@@ -1750,18 +1765,36 @@
 				val->type = IS_STRING;
 				val->value.str.len = sprintf(string_data, "%.*f", -scale, n / f);
 				val->value.str.val = estrdup(string_data);
+				*/
 			} else {
 				val->type = IS_LONG;
 				val->value.lval = *(long *)(data);
 			}
 			break;
 		case SQL_SHORT:
-			val->type = IS_LONG;
-			val->value.lval = *(short *)(data);
+			if (scale < 0) {
+				int j;
+				short dt, dth, dtl, pow_scale = 1;
+				for (j = 0; j < -scale; j++) pow_scale *= 10;
+				dt = *(short *)data;
+				dth = dt / pow_scale;
+				dtl = dt % pow_scale;
+				if (dtl < 0) dtl *= -1;
+				if ((dt < 0) && (dth == 0)) {
+					val->value.str.len = sprintf(string_data, "-0.%0*hd", -scale, (int)dtl);
+				} else {
+					val->value.str.len = sprintf(string_data, "%hd.%0*hd", (int)dth, -scale, (int)dtl);
+				}
+				val->type = IS_STRING;
+				val->value.str.val = estrdup(string_data);
+			} else {
+				val->type = IS_LONG;
+				val->value.lval = *(short *)(data);
+			}
 			break;
 		case SQL_FLOAT:
 			val->type = IS_DOUBLE;
-			val->value.dval = *(float *)(data);
+			val->value.dval = (double) *(float *)(data);
 			break;
 		case SQL_DOUBLE:
 			if (scale) {
@@ -1778,11 +1811,31 @@
 			break;
 #ifdef SQL_INT64
 		case SQL_INT64:
-			val->type = IS_STRING;
+			if (scale) {
+				int j;
+				ISC_INT64 dt, dth, dtl, pow_scale = 1;
+				for (j = 0; j < -scale; j++) pow_scale *= 10;
+				dt = *(ISC_INT64 *)data;
+				dth = (ISC_INT64) (dt / pow_scale);
+				dtl = (ISC_INT64) (dt % pow_scale);
+				if (dtl < 0) dtl *= -1;
+				if ((dt < 0) && (dth == 0)) {
+					val->value.str.len = sprintf(string_data, "-0.%0*Ld", -scale, dtl);
+				} else {
+					val->value.str.len = sprintf(string_data, "%Ld.%0*Ld", dth, -scale, dtl);
+				}
+				val->type = IS_STRING;
+				val->value.str.val = estrdup(string_data);
+			/*
 			val->value.str.len = sprintf(string_data, "%Ld.%Ld",
 										 (ISC_INT64) (*((ISC_INT64 *)data) / (int) pow(10.0, (double) -scale)),
 										 (ISC_INT64) abs((int) (*((ISC_INT64 *)data) % (int) pow(10.0, (double) -scale))));
-			val->value.str.val = estrdup(string_data);
+			*/
+			} else {
+				val->type = IS_STRING;
+				val->value.str.len = sprintf(string_data, "%Ld", *(ISC_INT64 *)data);
+				val->value.str.val = estrdup(string_data);
+			}
 			break;
 #endif
 #ifndef SQL_TIMESTAMP

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-04-13 14:52 UTC] daniela@php.net
This is already be fixed.

The version of PHP that this bug was reported in is too old.
Please try the php-4.2.0RC3 from http://www.php.net/~derick/ 
and if you are still able to reproduce this bug feel free to reopen it
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 13 22:01:27 2024 UTC