Describe the bug
db_update_table function does not support table data array that is generated by sqltable_to_php.php with args '--plugin' and '--update'
- In lib/database.php: function db_update_table(...):
$data['primary'] is always considered as array:
if (isset($data['primary'])) {
if (!isset($allindexes['PRIMARY'])) {
// No current primary key, so add it
if (!db_execute("ALTER TABLE `$table` ADD PRIMARY KEY(" . db_format_index_create($data['primary']) . ')', $log, $db_conn)) {
return false;
}
} else {
$add = array_diff($data['primary'], $allindexes['PRIMARY']);
$del = array_diff($allindexes['PRIMARY'], $data['primary']);
if (!empty($add) || !empty($del)) {
if (!db_execute("ALTER TABLE `$table` DROP PRIMARY KEY", $log, $db_conn) ||
!db_execute("ALTER TABLE `$table` ADD PRIMARY KEY(" . db_format_index_create($data['primary']) . ')', $log, $db_conn)) {
return false;
}
}
}
}
- sqltable_to_php.php output
$data['primary'] depend arg '--plugin'
if (!empty($pri)) {
if ($plugin != '') {
$text .= "\$data['primary'] = '" . implode("`,`", $pri) . "';\n";
} else {
$text .= "\$data['primary'] = array('" . implode("','", $pri) . "');\n";
}
}
Expected behavior
sqltable_to_php.php always output primary key as below if '--update' is specified:
$data['primary'] = 'host,graph';
Describe the bug
db_update_table function does not support table data array that is generated by
sqltable_to_php.phpwith args '--plugin' and '--update'$data['primary']is always considered as array:$data['primary']depend arg '--plugin'Expected behavior
sqltable_to_php.php always output primary key as below if '--update' is specified:
$data['primary'] = 'host,graph';