abies           Fri Jun  4 10:26:33 2004 EDT

  Modified files:              
    /php-src/ext/interbase      php_ibase_udf.c 
  Log:
  Added support for scaled integers
  
  
http://cvs.php.net/diff.php/php-src/ext/interbase/php_ibase_udf.c?r1=1.5&r2=1.6&ty=u
Index: php-src/ext/interbase/php_ibase_udf.c
diff -u php-src/ext/interbase/php_ibase_udf.c:1.5 
php-src/ext/interbase/php_ibase_udf.c:1.6
--- php-src/ext/interbase/php_ibase_udf.c:1.5   Fri Jun  4 09:33:56 2004
+++ php-src/ext/interbase/php_ibase_udf.c       Fri Jun  4 10:26:33 2004
@@ -16,14 +16,14 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: php_ibase_udf.c,v 1.5 2004/06/04 13:33:56 abies Exp $ */
+/* $Id: php_ibase_udf.c,v 1.6 2004/06/04 14:26:33 abies Exp $ */
 
 /**
 * This UDF library adds the ability to call PHP functions from SQL
 * statements. Because of SQL's strong typing, you will have to declare
 * an external function for every combination of input and output parameters 
 * your application requires. The types of the input arguments and the result
-* type can be either [VAR]CHARs or unscaled integers or floats.
+* type can be either [VAR]CHARs, (un)scaled integers or doubles/floats.
 * 
 * Declare the functions like this:
 * 
@@ -73,6 +73,16 @@
 
 #define min(a,b) ((a)<(b)?(a):(b))
 
+#ifdef PHP_WIN32
+#define LL_LIT(lit) lit ## I64
+#else
+#define LL_LIT(lit) lit ## ll
+#endif
+
+static ISC_INT64 const scales[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 
100000000, 1000000000,
+       1000000000, 
LL_LIT(10000000000),LL_LIT(100000000000),LL_LIT(10000000000000),LL_LIT(100000000000000),
+       LL_LIT(1000000000000000),LL_LIT(1000000000000000),LL_LIT(1000000000000000000) 
};
+
 static void call_php(char *name, PARAMDSC *r, int argc, PARAMDSC **argv)
 {
 
@@ -102,27 +112,53 @@
                        }
 
                        switch (argv[i]->dsc_dtype) {
+                               ISC_INT64 l;
+
                                case dtype_cstring:
                                        ZVAL_STRING(argp[i], 
(char*)argv[i]->dsc_address,0);
                                        break;
+
                                case dtype_text:
                                        ZVAL_STRINGL(argp[i], 
(char*)argv[i]->dsc_address, argv[i]->dsc_length,0);
                                        break;
+
                                case dtype_varying:
                                        ZVAL_STRINGL(argp[i], 
((PARAMVARY*)argv[i]->dsc_address)->vary_string,
                                                
((PARAMVARY*)argv[i]->dsc_address)->vary_length,0);
                                        break;
 
                                case dtype_short:
-                                       ZVAL_LONG(argp[i], 
*(short*)argv[i]->dsc_address);
+                                       if (argv[i]->dsc_scale == 0) {
+                                               ZVAL_LONG(argp[i], 
*(short*)argv[i]->dsc_address);
+                                       } else {
+                                               ZVAL_DOUBLE(argp[i],
+                                                       
((double)*(short*)argv[i]->dsc_address)/scales[-argv[i]->dsc_scale]);
+                                       }
                                        break;
+
                                case dtype_long:
-                                       ZVAL_LONG(argp[i], 
*(ISC_LONG*)argv[i]->dsc_address);
+                                       if (argv[i]->dsc_scale == 0) {
+                                               ZVAL_LONG(argp[i], 
*(ISC_LONG*)argv[i]->dsc_address);
+                                       } else {
+                                               ZVAL_DOUBLE(argp[i],
+                                                       
((double)*(ISC_LONG*)argv[i]->dsc_address)/scales[-argv[i]->dsc_scale]);
+                                       }
+                                       break;
+
+                               case dtype_int64:
+                                       l = *(ISC_INT64*)argv[i]->dsc_address;
+
+                                       if (argv[i]->dsc_scale == 0 && l <= LONG_MAX 
&& l >= LONG_MIN) {
+                                               ZVAL_LONG(argp[i], (long)l);
+                                       } else {
+                                               ZVAL_DOUBLE(argp[i], 
((double)l)/scales[-argv[i]->dsc_scale]);
+                                       }
                                        break;
 
                                case dtype_real:
                                        ZVAL_DOUBLE(argp[i], 
*(float*)argv[i]->dsc_address);
                                        break;
+
                                case dtype_double:
                                        ZVAL_DOUBLE(argp[i], 
*(double*)argv[i]->dsc_address);
                                        break;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to