Update database.php

This commit is contained in:
Namhyeon Go 2020-02-13 11:04:14 +09:00 committed by GitHub
parent a99d81acaf
commit c2b9b431a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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