Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, if you define a foreign key constraint with
ON UPDATE
andON DELETE
statements in SQLite, under specific circumstances, the constraint drop results in an error as the new table is not created.Take the example I added in the SQLiteAdapterTest file.
Given how the constraints are added, the create script is :
When this query is fed to the
preg_replace()
call that was modified in the SQLiteAdapter if adropForeignKey('table', array('ref_table_field'))
is done, it will result in :Which is invalid and will not "re-create" the table, having the consequence to simply dropping the table.
This PR aims to fix this by modifying the regex in two parts :
REFERENCES
$reftable(
$refcolumn)
part by making the regex go down to a,
or a)
which makes the regex eat up theON DELETE
andON UPDATE
part as well.FOREIGN KEY ($column
part by allowing other columns to be defined in case of composite foreign key constraints (which would mean that any constraints that column is bound to, whether simple or composite, will be dropped)This covers the need I have (and fix the bug I had), so feel free to test this and give me feedback in case there are things I did not considered before merging.