Update database.php

This commit is contained in:
Namhyeon Go 2020-01-09 17:48:37 +09:00 committed by GitHub
parent c446db7ebb
commit 815d9488ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -323,6 +323,8 @@ if(!check_function_exists("get_bind_to_sql_insert")) {
// get number of duplicated rows // get number of duplicated rows
$num_duplicates = 0; $num_duplicates = 0;
// do process
$_bind_T = array(); $_bind_T = array();
$_bind_F = array(); $_bind_F = array();
foreach($bind as $k=>$v) { foreach($bind as $k=>$v) {
@ -338,7 +340,7 @@ if(!check_function_exists("get_bind_to_sql_insert")) {
)); ));
$rows = exec_db_fetch_all($sql, $du_bind); $rows = exec_db_fetch_all($sql, $du_bind);
foreach($rows as $row) { foreach($rows as $row) {
$num_duplicates = intval($row['cnt']); $num_duplicates += intval($row['cnt']);
} }
// make statements // make statements
@ -513,7 +515,7 @@ if(!check_function_exists("get_db_tablenames")) {
if(!$is_separated) { if(!$is_separated) {
$tablenames[] = $tablename; $tablenames[] = $tablename;
} else { } else {
$sql = sprintf("select table_name from `%s.tables`", $tablename); $sql = sprintf("select table_name from `%s.tables` order by datetime desc", $tablename);
$rows = exec_db_fetch_all($sql); $rows = exec_db_fetch_all($sql);
foreach($rows as $row) { foreach($rows as $row) {
$tablenames[] = $row['table_name'] $tablenames[] = $row['table_name']
@ -918,6 +920,33 @@ if(!check_function_exists("exec_db_table_update")) {
} }
} }
if(!check_function_exists("exec_db_table_insert")) {
function exec_db_table_insert($tablename, $bind=array(), $options=array()) {
$flag = true;
// set replica
$replica = get_value_in_array("setreplica", $options, 1);
// get tablenames
$tablenames = get_db_tablenames($tablename);
if($replica > 0) {
$_num_tables = count($tablenames);
$_replica = min($replica, $_num_tables);
if($replica < $_num_tables) {
$tablenames = array_slice(get_db_tablenames($tablename), 0, $replica);
}
}
// do process
foreach($tablenames as $_tablename) {
$sql = get_bind_to_sql_insert($tablename, $bind, $options);
$flag &= exec_db_query($sql);
}
return $flag;
}
}
// temporary table creation // temporary table creation
if(!check_function_exists("exec_db_temp_create")) { if(!check_function_exists("exec_db_temp_create")) {
function exec_db_temp_create($schemes, $options=array()) { function exec_db_temp_create($schemes, $options=array()) {