Skip to content

Commit

Permalink
Resolving issue #2360
Browse files Browse the repository at this point in the history
When retrieving database / table / column information, schema name is not always applied.
  • Loading branch information
netniV committed Feb 8, 2019
1 parent 85bc99c commit e7b8158
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Cacti CHANGELOG
-issue#2355: Duplicated Data Sources created when Custom Data is specified
-issue#2357: Poller issuing warnings with little way to diagnose
-issue#2359: "Install/Upgrade" privilege lost, blocking upgrades
-issue#2360: When retrieving database / table / column information, schema name is not always applied
-issue#2362: No way to default an interface speed when ifSpeed and ifHighSpeed come back as zero
-issue#2365: Graphs included in aggregate that are removed are not managed properly
-issue#2372: SNMP DS with dskPath Index Type does not work
Expand Down
7 changes: 6 additions & 1 deletion cli/sqltable_to_php.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,12 @@ function sqltable_to_php($table, $create, $plugin = '') {
//exit;
}

$result = db_fetch_row("SELECT ENGINE, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_NAME = '$table'");
$result = db_fetch_row_prepared('select ENGINE, TABLE_COMMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = SCHEMA()
AND TABLE_NAME = ?',
array($table));

if (cacti_sizeof($result)) {
$text .= "\$data['type'] = '" . $result['ENGINE'] . "';\n";
$text .= "\$data['comment'] = '" . $result['TABLE_COMMENT'] . "';\n";
Expand Down
24 changes: 12 additions & 12 deletions lib/boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ function boost_file_size_display($file_size, $digits = 2) {
}

function boost_get_total_rows() {
return db_fetch_cell("SELECT SUM(TABLE_ROWS) FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema=SCHEMA()
AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')
GROUP BY table_schema");
return db_fetch_cell("SELECT SUM(TABLE_ROWS)
FROM information_schema.tables
WHERE table_schema = SCHEMA()
AND (table_name LIKE 'poller_output_boost_arch_%'
OR table_name LIKE 'poller_output_boost'");
}

function boost_error_handler($errno, $errmsg, $filename, $linenum, $vars) {
Expand Down Expand Up @@ -582,11 +583,9 @@ function boost_timer_get_overhead() {

/* boost_get_arch_table_name - returns current archive boost table or false if no arch table is present currently */
function boost_get_arch_table_name() {
global $database_default;

$tables = db_fetch_assoc("SELECT table_name AS name
FROM information_schema.tables
WHERE table_schema = '$database_default'
WHERE table_schema = SCHEMA()
AND table_name LIKE 'poller_output_boost_arch_%'");

foreach($tables as $table) {
Expand Down Expand Up @@ -653,7 +652,7 @@ function boost_process_poller_output($local_data_id = '', $rrdtool_pipe = '') {
$query_string = '';
$arch_tables = db_fetch_assoc("SELECT table_name AS name
FROM information_schema.tables
WHERE table_schema = '$database_default'
WHERE table_schema = SCHEMA()
AND table_name LIKE 'poller_output_boost_arch_%'");

if (cacti_count($arch_tables)) {
Expand Down Expand Up @@ -687,7 +686,7 @@ function boost_process_poller_output($local_data_id = '', $rrdtool_pipe = '') {
$query_string = '';
$arch_tables = db_fetch_assoc("SELECT table_name AS name
FROM information_schema.tables
WHERE table_schema = '$database_default'
WHERE table_schema = SCHEMA()
AND table_name LIKE 'poller_output_boost_arch_%'");

if (cacti_count($arch_tables)) {
Expand Down Expand Up @@ -1341,9 +1340,10 @@ function boost_update_snmp_statistics () {

/* get the boost table status */
$boost_table_status = db_fetch_assoc("SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema=SCHEMA()
AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')");
FROM information_schema.tables
WHERE table_schema = SCHEMA()
AND (table_name LIKE 'poller_output_boost_arch_%'
OR table_name LIKE 'poller_output_boost')");

$total_data_sources = db_fetch_cell('SELECT COUNT(*) FROM poller_item');

Expand Down
22 changes: 20 additions & 2 deletions lib/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,11 @@ function db_update_table($table, $data, $removecolumns = false, $log = true, $db
}
}

$info = db_fetch_row("SELECT ENGINE, TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_NAME = '$table'", $log, $db_conn);
$info = db_fetch_row("SELECT ENGINE, TABLE_COMMENT
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = SCHEMA()
AND TABLE_NAME = '$table'", $log, $db_conn);

if (isset($info['TABLE_COMMENT']) && str_replace("'", '', $info['TABLE_COMMENT']) != str_replace("'", '', $data['comment'])) {
if (!db_execute("ALTER TABLE `$table` COMMENT '" . str_replace("'", '', $data['comment']) . "'", $log, $db_conn)) {
return false;
Expand Down Expand Up @@ -1433,7 +1437,11 @@ function db_get_column_attributes($table, $columns) {
$columns = explode(',', $columns);
}

$sql = 'SELECT * FROM information_schema.columns WHERE table_name = ? and column_name IN (';
$sql = 'SELECT * FROM information_schema.columns
WHERE table_schema = SCHEMA()
AND table_name = ?
AND column_name IN (';

$column_names = array();
foreach ($columns as $column) {
if (!empty($column)) {
Expand Down Expand Up @@ -1496,3 +1504,13 @@ function db_error() {
return $database_last_error;
}

// db_get_default_database - Get the database name of the current database or return the default database name
// @returns - string - either current db name or configuration default if no connection/name
function db_get_default_database($db_conn = false) {
global $database_default;

$database = db_fetch_cell('SELECT DATABASE()', '', true, $db_conn);
if (empty($database)) {
$database = $database_default;
}
}
6 changes: 3 additions & 3 deletions poller_boost.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ function output_rrd_data($start_time, $force = false) {

$more_arch_tables = db_fetch_assoc_prepared("SELECT table_name AS name
FROM information_schema.tables
WHERE table_schema = ?
WHERE table_schema = SCHEMA()
AND table_name LIKE 'poller_output_boost_arch_%'
AND table_name != ?", array($database_default, $archive_table));
AND table_name != ?", array($archive_table));

if (cacti_count($more_arch_tables)) {
foreach($more_arch_tables as $table) {
Expand Down Expand Up @@ -336,7 +336,7 @@ function output_rrd_data($start_time, $force = false) {
/* cleanup - remove empty arch tables */
$tables = db_fetch_assoc("SELECT table_name AS name
FROM information_schema.tables
WHERE table_schema=SCHEMA()
WHERE table_schema = SCHEMA()
AND table_name LIKE 'poller_output_boost_arch_%'");

if (cacti_count($tables)) {
Expand Down
8 changes: 5 additions & 3 deletions utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function utilities_view_tech($php_info = '') {
/* Get table status */
$tables = db_fetch_assoc_prepared('SELECT *
FROM information_schema.tables
WHERE table_schema = ?', array($database_default));
WHERE table_schema = SCHEMA()');

/* Get poller stats */
$poller_item = db_fetch_assoc('SELECT action, count(action) AS total
Expand Down Expand Up @@ -2047,8 +2047,10 @@ function applyFilter() {

/* get the boost table status */
$boost_table_status = db_fetch_assoc("SELECT *
FROM INFORMATION_SCHEMA.TABLES WHERE table_schema=SCHEMA()
AND (table_name LIKE 'poller_output_boost_arch_%' OR table_name LIKE 'poller_output_boost')");
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = SCHEMA()
AND (table_name LIKE 'poller_output_boost_arch_%'
OR table_name LIKE 'poller_output_boost')");

$pending_records = 0;
$arch_records = 0;
Expand Down

0 comments on commit e7b8158

Please sign in to comment.