Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mssql schema parase throws warning in addForeignKeys #737

Open
danomatic opened this issue Aug 9, 2013 · 2 comments
Open

Mssql schema parase throws warning in addForeignKeys #737

danomatic opened this issue Aug 9, 2013 · 2 comments

Comments

@danomatic
Copy link

a key in rows is not defined. this snippet should fix it:

    $stmt = $this->dbh->query("SELECT ccu1.TABLE_NAME, ccu1.COLUMN_NAME, ccu2.TABLE_NAME AS FK_TABLE_NAME, ccu2.COLUMN_NAME AS FK_COLUMN_NAME, ccu2.CONSTRAINT_NAME AS FK_NAME
                                FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu1 INNER JOIN
                                        INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc1 ON tc1.CONSTRAINT_NAME = ccu1.CONSTRAINT_NAME AND
                                        CONSTRAINT_TYPE = 'Foreign Key' INNER JOIN
                                        INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1 ON rc1.CONSTRAINT_NAME = tc1.CONSTRAINT_NAME INNER JOIN
                                        INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu2 ON ccu2.CONSTRAINT_NAME = rc1.UNIQUE_CONSTRAINT_NAME
                                WHERE (ccu1.table_name = '".$table->getName()."')");

    $foreignKeys = array(); // local store to avoid duplicates
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

        $lcol = $row['COLUMN_NAME'];
        $ftbl = $row['FK_TABLE_NAME'];
        $fcol = $row['FK_COLUMN_NAME'];
        $name = $row['FK_NAME'];
@staabm
Copy link
Member

staabm commented Aug 9, 2013

When do you see a warning? How to reproduce? Which line is fixed with your snippet in whichfile?

@danomatic
Copy link
Author

The current source is below. The variable $name is not defined. My code selects an extra column, FK_NAME, and assigns the variable.

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {

        $lcol = $this->cleanDelimitedIdentifiers($row['COLUMN_NAME']);
        $ftbl = $this->cleanDelimitedIdentifiers($row['FK_TABLE_NAME']);
        $fcol = $this->cleanDelimitedIdentifiers($row['FK_COLUMN_NAME']);

        $foreignTable = $database->getTable($ftbl);
        $foreignColumn = $foreignTable->getColumn($fcol);
        $localColumn = $table->getColumn($lcol);

        if (!isset($foreignKeys[$name])) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants