Update database.php
This commit is contained in:
parent
57f0937590
commit
f0d7b5af80
|
@ -355,7 +355,7 @@ if(!check_function_exists("get_bind_to_sql_select")) {
|
|||
$s1 = "";
|
||||
if(!array_key_empty("fieldnames", $options)) {
|
||||
$s1 .= (check_array_length($options['fieldnames'], 0) > 0) ? implode(", ", $options['fieldnames']) : "*";
|
||||
} elseif(!array_key_empty("getcnt", $options)) {
|
||||
} elseif(array_key_equals("getcnt", $options, true)) {
|
||||
$s1 .= sprintf("count(%s) as cnt", ($options['getcnt'] === true ? "*" : $options['getcnt']));
|
||||
} elseif(!array_key_empty("getsum", $options)) {
|
||||
$s1 .= sprintf("sum(%s) as sum", $options['getsum']);
|
||||
|
@ -366,20 +366,29 @@ if(!check_function_exists("get_bind_to_sql_select")) {
|
|||
// s1a: s1 additonal (set new fields)
|
||||
$s1a = array();
|
||||
if(array_key_is_array("setfields", $options)) {
|
||||
$addfields = $options['setfields'];
|
||||
$setfields = $options['setfields'];
|
||||
|
||||
foreach($addfields as $k=>$v) {
|
||||
foreach($setfields as $k=>$v) {
|
||||
// concat and delimiter
|
||||
if(!array_keys_empty(array("concat", "delimiter"), $v)) {
|
||||
// add to s1a
|
||||
$s1a[$k] = sprintf("concat(%s)", implode(sprintf(", '%s', ", $v['delimiter']), $v['concat']));
|
||||
if(!array_keys_empty("concat", $v)) {
|
||||
$delimiter = get_value_in_array("delimiter", $v, " ");
|
||||
$s1a[$k] = sprintf("concat(%s)", implode(sprintf(", '%s', ", $delimiter), $v['concat']));
|
||||
}
|
||||
|
||||
// use function
|
||||
if(!array_key_empty("call_func", $v)) {
|
||||
if(check_array_length($v['call_func'], 1) > 0) {
|
||||
// use mysql function
|
||||
if(!array_key_empty("sql_function", $v)) {
|
||||
if(check_array_length($v['sql_function'], 1) > 0) {
|
||||
// add to s1a
|
||||
$s1a[$k] = sprintf("%s(%s)", $v['call_func'][0], implode(", ", array_slice($v['call_func'], 1)));
|
||||
$s1a[$k] = sprintf("%s(%s)", $v['sql_function'][0], implode(", ", array_slice($v['sql_function'], 1)));
|
||||
}
|
||||
}
|
||||
|
||||
// use simple distance
|
||||
if(!array_key_empty("simple_distance", $v)) {
|
||||
if(check_array_length($v['simple_distance'], 2) == 0) {
|
||||
$a = floatval($v['simple_distance'][1]); // percentage (range 0 to 1)
|
||||
$b = $v['simple_distance'][0]; // field or number
|
||||
$s1a[$k] = sprintf("abs(1.0 - (abs(%s - %s) / %s))", $b, $a, $a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -411,11 +420,11 @@ if(!check_function_exists("get_bind_to_sql_select")) {
|
|||
if(check_array_length($opts[1][2], 0) > 0) {
|
||||
$s3a = array();
|
||||
foreach($opts[1][2] as $word) {
|
||||
$s3a[] = sprintf("%s like '%s'", $s1a[$opts[1][1]], "%{$word}%");
|
||||
$s3a[] = sprintf("%s like '%s'", get_value_in_array($opts[1][1], $s1a, $opts[1][1]), "%{$word}%");
|
||||
}
|
||||
$s3 .= sprintf(" %s (%s)", $opts[0], implode(" and ", $s3a));
|
||||
} else {
|
||||
$s3 .= sprintf(" %s (%s like %s)", $opts[0], $s1a[$opts[1][1]], "'%{$opts[1][2]}%'");
|
||||
$s3 .= sprintf(" %s (%s like %s)", $opts[0], get_value_in_array($opts[1][1], $s1a, $opts[1][1]), "'%{$opts[1][2]}%'");
|
||||
}
|
||||
} elseif($opts[1][0] == "in") {
|
||||
if(check_array_length($opts[1][2], 0) > 0) {
|
||||
|
@ -453,7 +462,7 @@ if(!check_function_exists("get_bind_to_sql_select")) {
|
|||
$s4a[] = $opts;
|
||||
} elseif(check_array_length($opts, 2) == 0) {
|
||||
// example: array("desc", "datetime")
|
||||
$s4a[] = sprintf("%s %s", $opts[1], $opts[0]);
|
||||
$s4a[] = sprintf("%s %s", get_value_in_array($opts[1], $s1a, $opts[1]), $opts[0]);
|
||||
}
|
||||
}
|
||||
$s4 .= implode(", ", $s4a);
|
||||
|
|
Loading…
Reference in New Issue
Block a user