Update database.php
This commit is contained in:
parent
a99d81acaf
commit
c2b9b431a0
|
@ -381,6 +381,13 @@ if(!is_fn("get_bind_to_sql_where")) {
|
|||
}
|
||||
}
|
||||
|
||||
// s1a: s1 additonal (set new fields)
|
||||
$s1a = array();
|
||||
if(array_key_is_array("setfields", $options)) {
|
||||
$setfields = $options['setfields'];
|
||||
$s1a = get_bind_to_sql_fields($setfields);
|
||||
}
|
||||
|
||||
if(!array_keys_empty(array("settimefield", "setminutes"), $options)) {
|
||||
$s3 .= get_bind_to_sql_past_minutes($options['settimefield'], $options['setminutes']);
|
||||
}
|
||||
|
@ -546,30 +553,9 @@ if(!is_fn("get_db_tablenames")) {
|
|||
}
|
||||
}
|
||||
|
||||
if(!is_fn("get_bind_to_sql_select")) {
|
||||
// warning: variable k is not protected. do not use variable k and external variable without filter
|
||||
function get_bind_to_sql_select($tablename, $bind=array(), $options=array()) {
|
||||
$sql = "select %s from `%s` where %s %s %s";
|
||||
|
||||
// is_separated: check it is seperated table
|
||||
$is_separated = check_table_is_separated($tablename);
|
||||
|
||||
// s1: select fields
|
||||
$s1 = "";
|
||||
if(!array_key_empty("fieldnames", $options)) {
|
||||
$s1 .= (check_array_length($options['fieldnames'], 0) > 0) ? implode(", ", $options['fieldnames']) : "*";
|
||||
} elseif(array_key_equals("getcount", $options, true)) {
|
||||
$s1 .= sprintf("count(%s) as value", ($options['getcount'] === true ? "*" : $options['getcount']));
|
||||
} elseif(!array_key_empty("getsum", $options)) {
|
||||
$s1 .= sprintf("sum(%s) as value", $options['getsum']);
|
||||
} else {
|
||||
$s1 .= "*";
|
||||
}
|
||||
|
||||
// s1a: s1 additonal (set new fields)
|
||||
$s1a = array();
|
||||
if(array_key_is_array("setfields", $options)) {
|
||||
$setfields = $options['setfields'];
|
||||
if(!is_fn("get_bind_to_sql_fields")) {
|
||||
function get_bind_to_sql_fields($fields) {
|
||||
$s1a = array()
|
||||
|
||||
foreach($setfields as $k=>$v) {
|
||||
// add
|
||||
|
@ -627,15 +613,37 @@ if(!is_fn("get_bind_to_sql_select")) {
|
|||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
return $s1a;
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_fn("get_bind_to_sql_select")) {
|
||||
// warning: variable k is not protected. do not use variable k and external variable without filter
|
||||
function get_bind_to_sql_select($tablename, $bind=array(), $options=array()) {
|
||||
$sql = "select %s from `%s` where %s %s %s";
|
||||
|
||||
// is_separated: check it is seperated table
|
||||
$is_separated = check_table_is_separated($tablename);
|
||||
|
||||
// s1: select fields
|
||||
$s1 = "";
|
||||
if(!array_key_empty("fieldnames", $options)) {
|
||||
$s1 .= (check_array_length($options['fieldnames'], 0) > 0) ? implode(", ", $options['fieldnames']) : "*";
|
||||
} elseif(array_key_equals("getcount", $options, true)) {
|
||||
$s1 .= sprintf("count(%s) as value", ($options['getcount'] === true ? "*" : $options['getcount']));
|
||||
} elseif(!array_key_empty("getsum", $options)) {
|
||||
$s1 .= sprintf("sum(%s) as value", $options['getsum']);
|
||||
} else {
|
||||
$s1 .= "*";
|
||||
}
|
||||
|
||||
// s1a: s1 additonal (set new fields)
|
||||
$s1a = array();
|
||||
if(array_key_is_array("setfields", $options)) {
|
||||
$setfields = $options['setfields'];
|
||||
$s1a = get_bind_to_sql_fields($setfields);
|
||||
}
|
||||
|
||||
// s2: set table name
|
||||
|
|
Loading…
Reference in New Issue
Block a user