Update database.php

This commit is contained in:
Namhyeon Go 2019-12-30 16:22:45 +09:00 committed by GitHub
parent 9b27de8c45
commit 5ec1a640e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -685,6 +685,7 @@ if(!check_function_exists("sql_query")) {
}
}
// get timediff
if(!check_function_exists("get_timediff_on_query")) {
function get_timediff_on_query($a, $b) {
@ -702,11 +703,22 @@ if(!check_function_exists("get_timediff_on_query")) {
}
}
// temporary table
if(!check_function_exists("exec_db_temp_create")) {
function exec_db_temp_create($schemes=array(), $options=array()) {
$_tablename = make_random_id();
// table creation
if(!check_function_exists("get_bind_to_sql_create")) {
function get_bind_to_sql_create($schemes, $options=array()) {
$sql = false;
$_prefix = get_value_in_array("prefix", $options, "");
$_suffix = get_value_in_array("suffix", $options, "");
$_tablename = get_value_in_array("tablename", $options, "");
$_schemes = array();
$setindex = get_value_in_array("setindex", $options, false);
$temporary = get_value_in_array("temporary", $options, false);
if(!empty($_tablename)) {
$tablename = sprintf("%s%s%s", $_prefix, $_tablename, $_suffix);
foreach($schemes as $k=>$v) {
if(is_array($v)) {
$_argc = count($v);
@ -719,8 +731,29 @@ if(!check_function_exists("exec_db_temp_create")) {
}
}
}
$_sql = sprintf("create temporary table if not exists %s (%s)", $_tablename, implode(",", $_schemes));
return (exec_db_query($_sql) ? $_tablename : false);
if($temporary !== false) {
$sql = sprintf("create temporary table if not exists %s (%s)", $tablename, implode(",", $_schemes));
} else {
$sql = sprintf("create table if not exists %s (%s)", $tablename, implode(",", $_schemes));
}
}
return $sql;
}
}
// temporary table creation
if(!check_function_exists("exec_db_temp_create")) {
function exec_db_temp_create($schemes, $options=array()) {
$tablename = make_random_id();
$sql = get_bind_to_sql_create($schemes, array(
"tablename" => $tablename,
"temporary" => true
));
return (exec_db_query($sql) ? $tablename : false);
}
}