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

Alter table rename to always fails if foreign keys are present #184

Open
GoogleCodeExporter opened this issue Jun 24, 2015 · 1 comment
Open

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1.open a db,
2.create a couple tables
3.add some foreign keys and enable them
4 attempt to alter table by renaming it. you'll get an SQL Error or database 
not loaded.

What is the expected output? What do you see instead?
Success! failure :(

What version of the product are you using? On what operating system?
Not sure. OSX

Please provide any additional information below.

Problem is in alter_cs line 588 (currently)
    if ( ( zWhere = whereForeignKeys( pParse, pTab ) ) != null )

and the whereForeignKeys:

static string whereForeignKeys( Parse pParse, Table pTab )
{
  FKey p;
  string zWhere = "";
  for ( p = sqlite3FkReferences( pTab ); p != null; p = p.pNextTo )
  {
    zWhere = whereOrName( pParse.db, zWhere, p.pFrom.zName );
  }
  return zWhere;
}

where zWhere will never ever be null! it will enter the if statement and will 
attempt to update nested foreign keys:

sqlite3NestedParse( pParse,
          "UPDATE \"%w\".%s SET " +
              "sql = sqlite_rename_parent(sql, %Q, %Q) " +
              "WHERE %s;", zDb, SCHEMA_TABLE( iDb ), zTabName, zName, zWhere );

These don't even exist and cause a crash.

To fix set zWhere to null on whereForeignKeys


Original issue reported on code.google.com by [email protected] on 31 Mar 2014 at 9:36

@GoogleCodeExporter
Copy link
Author

temptriggers probably had this problem and it switched to compare with the 
empty string. another possible solution although I prefer setting things to 
null.

Original comment by [email protected] on 31 Mar 2014 at 9:39

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

No branches or pull requests

1 participant