Update database.php

This commit is contained in:
Namhyeon Go 2018-06-13 17:50:07 +09:00 committed by GitHub
parent 585a09b7e6
commit bbb49dcf3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -273,17 +273,19 @@ if(!function_exists("get_bind_to_sql_update_set")) {
if(!function_exists("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, $options=array()) {
$sql = "select %s from %s where 1" . get_bind_to_sql_where($bind);
$sql = "select %s from %s where 1 %s";
$s1 = "*";
if(!array_key_empty("fieldnames", $options)) {
$s1 = (count($options['fieldnames']) > 0) ? implode(", ", $options['fieldnames']) : "*";
} elseif(array_key_equals("getcnt", $options, true)) {
$s1 = "count(*) as cnt";
} elseif(!array_key_empty("getsum", $options)) {
$s1 = sprintf("sum(%s) as sum", $options['getsum']);
}
$s2 = $tablename;
$sql = sprintf($sql, $s1, $s2);
$s3 = get_bind_to_sql_where($bind);
$sql = sprintf($sql, $s1, $s2, $s3);
return $sql;
}
@ -338,6 +340,21 @@ if(!function_exists("get_bind_to_sql_past_minutes")) {
}
}
// SQL eXtensible
if(!function_exists("get_bind_to_sqlx")) {
function get_bind_to_sqlx($filename, $bind, $options=array()) {
$result = false;
$sql = read_storage_file(get_file_name($filename, "sqlx"), array(
"storage_type" => "sqlx"
));
if(!empty($sql)) {
$result = get_db_binded_sql($sql, $bind);
}
return $result;
}
}
// alias sql_query from exec_db_query
if(!function_exists("sql_query")) {
function sql_query($sql, $bind=array()) {