Skip to content

sqltable_to_php.php does not always generate valid table data arrays #2702

@ddb4github

Description

@ddb4github

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';

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugUndesired behaviourresolvedA fixed issue

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions