downpouring / csharp-sqlite

Automatically exported from code.google.com/p/csharp-sqlite
Other
0 stars 0 forks source link

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

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 chwiela...@gmail.com on 31 Mar 2014 at 9:36

GoogleCodeExporter commented 9 years ago
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 chwiela...@gmail.com on 31 Mar 2014 at 9:39