<?php
$result_1 = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' AND TABLE_NAME='".$config['table_prefix']."tables_log'"));
if (!$result_1) {
    run_query('CREATE TABLE ' . $config['table_prefix'] . 'tables_log (
          table_id int(11) NOT NULL,
          date datetime NOT NULL,
          time decimal(10,6) NOT NULL,
          KEY table_id (table_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
}

$result_2 = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' AND TABLE_NAME='".$config['table_prefix']."subtables_log'"));
if (!$result_2) {
    run_query('CREATE TABLE ' . $config['table_prefix'] . 'subtables_log (
          subtable_id int(11) NOT NULL,
          date datetime NOT NULL,
          time decimal(10,6) NOT NULL,
          KEY subtable_id (subtable_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
}

$result_3 = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' AND TABLE_NAME='".$config['table_prefix']."records_log'"));
if (!$result_3) {
    run_query('CREATE TABLE ' . $config['table_prefix'] . 'records_log (
          table_id int(11) NOT NULL,
          date datetime NOT NULL,
          time decimal(10,6) NOT NULL,
          KEY table_id (table_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
}

$result_4 = sql_fetch_assoc(sql_query("SELECT TABLE_NAME FROM information_schema.columns WHERE TABLE_SCHEMA='".$config['dbname']."' AND TABLE_NAME='".$config['table_prefix']."save_time_log'"));
if (!$result_4) {
    run_query('CREATE TABLE ' . $config['table_prefix'] . 'save_time_log (
          table_id int(11) NOT NULL,
          date datetime NOT NULL,
          time decimal(10,6) NOT NULL,
          KEY table_id (table_id)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
}

$result_insert_1 = sql_fetch_assoc(sql_query("SELECT name FROM ".$config['table_prefix']."config WHERE name='log_tables_runtime'"));
if (!$result_insert_1) {
    run_query("INSERT INTO " . $config['table_prefix'] . "config (name, value) VALUES ('log_tables_runtime', '0')");
}

$result_insert_2 = sql_fetch_assoc(sql_query("SELECT name FROM ".$config['table_prefix']."config WHERE name='log_subtables_runtime'"));
if (!$result_insert_2) {
    run_query("INSERT INTO " . $config['table_prefix'] . "config (name, value) VALUES ('log_subtables_runtime', '0')");
}

$result_insert_3 = sql_fetch_assoc(sql_query("SELECT name FROM ".$config['table_prefix']."config WHERE name='log_records_runtime'"));
if (!$result_insert_3) {
    run_query("INSERT INTO " . $config['table_prefix'] . "config (name, value) VALUES ('log_records_runtime', '0')");
}

$result_insert_4 = sql_fetch_assoc(sql_query("SELECT name FROM ".$config['table_prefix']."config WHERE name='log_save_runtime'"));
if (!$result_insert_4) {
    run_query("INSERT INTO " . $config['table_prefix'] . "config (name, value) VALUES ('log_save_runtime', '0')");
}