summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Boeren <mboeren@php.net>2001-04-09 11:53:39 +0000
committerMarc Boeren <mboeren@php.net>2001-04-09 11:53:39 +0000
commit066547a220b460fcd92a9174734a4dea1f0cfb3f (patch)
treeb300f972870a97b99a13b8122a15acc1aec43d95
parent7ee542a524b997f628cd65b7d2fa0dc376bb19de (diff)
downloadphp-git-066547a220b460fcd92a9174734a4dea1f0cfb3f.tar.gz
Added optional 'comparison_type' parameter to compare functions, to force
either text or number comparison. (Mc)
-rw-r--r--ext/dbx/dbx.c72
1 files changed, 40 insertions, 32 deletions
diff --git a/ext/dbx/dbx.c b/ext/dbx/dbx.c
index f750bc3ba7..5e3b5fe1aa 100644
--- a/ext/dbx/dbx.c
+++ b/ext/dbx/dbx.c
@@ -536,14 +536,18 @@ ZEND_FUNCTION(dbx_error)
*/
ZEND_FUNCTION(dbx_cmp_asc)
{
- int number_of_arguments=3;
+ int min_number_of_arguments=3;
+ int max_number_of_arguments=4;
+ int number_of_arguments=-1;
+ int comparison_type=0;
double dtemp;
long ltemp;
- zval ** arguments[3];
+ zval ** arguments[4];
zval ** zv_a;
zval ** zv_b;
int result=0;
- if (ZEND_NUM_ARGS() !=number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
+ number_of_arguments=ZEND_NUM_ARGS();
+ if (number_of_arguments<min_number_of_arguments || number_of_arguments>max_number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -553,6 +557,11 @@ ZEND_FUNCTION(dbx_cmp_asc)
RETURN_LONG(0);
}
convert_to_string_ex(arguments[2]); /*/ field name /*/
+ comparison_type = 0; // default, text
+ if (number_of_arguments>3) {
+ convert_to_string_ex(arguments[3]); /*/ comparison type /*/
+ if (!strcmp((*arguments[3])->value.str.val, "number")) comparison_type=1;
+ }
if (zend_hash_find((*arguments[0])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_a)==FAILURE
|| zend_hash_find((*arguments[1])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_b)==FAILURE) {
@@ -560,24 +569,19 @@ ZEND_FUNCTION(dbx_cmp_asc)
RETURN_LONG(0);
}
- if ((*zv_a)->type != (*zv_b)->type) {
- convert_to_string_ex(zv_a);
- convert_to_string_ex(zv_b);
- }
- switch ((*zv_a)->type) {
- case IS_LONG:
- case IS_BOOL:
- ltemp = (*zv_a)->value.lval - (*zv_b)->value.lval;
+ switch (comparison_type) {
+ case 0:
+ convert_to_string_ex(zv_a);
+ convert_to_string_ex(zv_b);
+ ltemp = strcmp((*zv_a)->value.str.val, (*zv_b)->value.str.val);
result = (ltemp==0?0: (ltemp>0?1:-1));
break;
- case IS_DOUBLE:
+ case 1:
+ convert_to_double_ex(zv_a);
+ convert_to_double_ex(zv_b);
dtemp = ((*zv_a)->value.dval - (*zv_b)->value.dval);
result = (dtemp==0?0: (dtemp>0?1:-1));
break;
- case IS_STRING:
- ltemp = strcmp((*zv_a)->value.str.val, (*zv_b)->value.str.val);
- result = (ltemp==0?0: (ltemp>0?1:-1));
- break;
default:
result=0;
break;
@@ -591,14 +595,18 @@ ZEND_FUNCTION(dbx_cmp_asc)
*/
ZEND_FUNCTION(dbx_cmp_desc)
{
- int number_of_arguments=3;
+ int min_number_of_arguments=3;
+ int max_number_of_arguments=4;
+ int number_of_arguments=-1;
+ int comparison_type=0;
double dtemp;
long ltemp;
- zval ** arguments[3];
+ zval ** arguments[4];
zval ** zv_a;
zval ** zv_b;
int result=0;
- if (ZEND_NUM_ARGS() !=number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
+ number_of_arguments=ZEND_NUM_ARGS();
+ if (number_of_arguments<min_number_of_arguments || number_of_arguments>max_number_of_arguments || zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
WRONG_PARAM_COUNT;
}
@@ -608,6 +616,11 @@ ZEND_FUNCTION(dbx_cmp_desc)
RETURN_LONG(0);
}
convert_to_string_ex(arguments[2]); /*/ field name /*/
+ comparison_type = 0; // default, text
+ if (number_of_arguments>3) {
+ convert_to_string_ex(arguments[3]); /*/ comparison type /*/
+ if (!strcmp((*arguments[3])->value.str.val, "number")) comparison_type=1;
+ }
if (zend_hash_find((*arguments[0])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_a)==FAILURE
|| zend_hash_find((*arguments[1])->value.ht, (*arguments[2])->value.str.val, (*arguments[2])->value.str.len+1, (void **) &zv_b)==FAILURE) {
@@ -615,24 +628,19 @@ ZEND_FUNCTION(dbx_cmp_desc)
RETURN_LONG(0);
}
- if ((*zv_a)->type != (*zv_b)->type) {
- convert_to_string_ex(zv_a);
- convert_to_string_ex(zv_b);
- }
- switch ((*zv_a)->type) {
- case IS_LONG:
- case IS_BOOL:
- ltemp = (*zv_b)->value.lval - (*zv_a)->value.lval;
+ switch (comparison_type) {
+ case 0:
+ convert_to_string_ex(zv_a);
+ convert_to_string_ex(zv_b);
+ ltemp = strcmp((*zv_b)->value.str.val, (*zv_a)->value.str.val);
result = (ltemp==0?0: (ltemp>0?1:-1));
break;
- case IS_DOUBLE:
+ case 1:
+ convert_to_double_ex(zv_a);
+ convert_to_double_ex(zv_b);
dtemp = ((*zv_b)->value.dval - (*zv_a)->value.dval);
result = (dtemp==0?0: (dtemp>0?1:-1));
break;
- case IS_STRING:
- ltemp = strcmp((*zv_b)->value.str.val, (*zv_a)->value.str.val);
- result = (ltemp==0?0: (ltemp>0?1:-1));
- break;
default:
result=0;
break;