Column default values are not replaced by placeholders when creating new tables. This means curly brackets will have the table prefix added to it, and an exception will be thrown if a semicolon appears in the default.
Potential solution is to use placeholders for default values in CREATE TABLE queries, but this would require Schema::createTableSQL()
to return an array of arrays, where each element is a query string and an array of placeholders/values.
Alternatively, the table name can be prefixed prior to creating the query string, and the query can be prepared without calling prefixTables()
This bug is likely also an issue with Schema::changeField()
.
Comment | File | Size | Author |
---|---|---|---|
#12 | reroll_diff_3130333_3-12.txt | 3.4 KB | ankithashetty |
#12 | 3130333-12.patch | 2.39 KB | ankithashetty |
#3 | 3130333-3.patch | 1.95 KB | Beakerboy |
Comments
Comment #2
BeakerboyAdded tests to see if these conditions lead to failures.
Comment #3
Beakerboyrevised patch with correct function and white-space.
Comment #4
BeakerboyComment #5
BeakerboyLooks like the curly brace problem has already been reported.
Comment #6
BeakerboyComment #7
daffie CreditAttribution: daffie commentedHi @Beakerboy: In both cases you are right. Only fixing either one of them is a lot of work. My question to you is: is it necessary for your SQL-server database driver or do you have some use-case where one or both cases are necessary? If the answer is no, shall we then put our time and effort in something more usefull?
If you however want to fix this problem, then add the fixes for the by core supported databases and I will review the patch.
Comment #8
BeakerboyMy motivation is to simplify the sqlsrv driver. The
createTable()
function has some code which fixes the curly brace bug, and includes the comment:my thought on this is, if that situation is a bug that affects users, It should be fixed in core not at the sqlsrv level. Now that I have verified that it is an issue in core, I plan on dropping the special handling in sqlsrv to make it simpler.
The semicolon bug doesn’t affect me either. For some reason Microsoft insists that any merge statement must terminate with a semicolon. To accommodate this I had to change the way the query function trims the end of the query string, and I imagined that semicolons in default values would probably lead to an exception.
I’m not itching to fix these myself, but since there has been a lot of very good discussion about the database abstraction layer lately, I figured we could have some smart people brainstorm on the best solution to at least have a plan in place.
My thought is to move all of the table creation code out of the Schema class and into a Create class, similar to Select, Insert, Delete, etc. this would shrink the Schema class, and allow each driver to manage its own toString() and execute() process.
Comment #10
daffie CreditAttribution: daffie commentedYes, these are bugs. Not sure if these can be fixed. Maybe relate to #3130579: Make Drupal\Core\Database\Schema work with reserved keywords for naming.
Can we change this to
$this->connection->select()
Comment #11
daffie CreditAttribution: daffie commentedComment #12
ankithashettyRe-rolled the patch in #3 and made the following changes to it:
$this->connection->query('SELECT
to$this->connection->select()
as mentioned in #10.drupal_get_module_schema()
as directed in https://www.drupal.org/node/2970993.$this->assertEqual()
with $this->assertSame() as done in #2908886: Split off schema management out of schema.incThank you!