Closed (duplicate)
Project:
Drupal core
Version:
9.3.x-dev
Component:
database system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
27 Sep 2011 at 23:51 UTC
Updated:
13 Aug 2021 at 11:16 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
mattconnolly commentedAttaching patch. Setting to needs review so I can see what the testbot thinks.
Comment #2
mattconnolly commentedJust to clarify the issue, this is for a field that is `'serialize' => TRUE` in its specification when calling `db_add_field`, attempting to use a value of "a:0:{}" (equivalent of `serialize(array())` as the default value. When doing this the '{}' gets stripped out as if it was a table name between the curly braces. This should not happen because it's in a string literal.
Comment #3
yvmarques commentedThe bug affects also Drupal 7 and I guess Drupal 8.
Comment #4
damien tournoud commentedEw. That's not really nice of us.
Comment #5
yvmarques commentedYou should remove your debug log from the patch.
Comment #6
mattconnolly commentedOh yeah - that was clever NOT. Whoops. Here's another patch for D6 without my debuglog in it :)
Comment #7
mattconnolly commentedA better solution ?? might be to support using args from `update_sql` but that looks like quite a bit more work, I needed this resolved quickly, so that's what I came up with. I'm glad it passed all the tests on D6, though. Good work test bot.
Comment #8
mattconnolly commentedBumping to needs review so the last D6 patch can be tested by testbot.
Comment #9
xjmTestbot only tests against the current branch for the issue. Also, we need an 8.x patch first. :)
Comment #10
yvmarques commentedI agree to contribute to this issue, but I need some hints from experts, like what is the best solution and where is the best place to make some code changes ?
Thanks,
-- Yvan
Comment #11
mike.roberts commentedJust an update to this issue as I've been experiencing this problem lately. It seems that curly braces are only stripped in something related to the default value, not during writing to the database. The documentation for the Schema API is wrong as well, since it states that you can use 'serialize' => TRUE and pass your schema an unserialized array of information. After some research it appears that this only works with drupal_write_record().
Here are my observations:
This does not work:
The value that gets saved is a:2:i:0;s:9:"Value One";i:1;s:9:"Value Two"; (missing the curly braces).
This also does not work:
This is a database syntax error.
But this does work:
and the value that gets saved to the database is a:2:{i:0;s:9:"Value One";i:1;s:9:"Value Two";} with the curly braces.
A workaround for now would be to define your schema with a blank default value, then run a hook_update() to write your default value since the braces are not stripped in db_update.
Comment #20
quietone commentedI suspect this was fixed in Oct 2014, in #2232425: Database Schema field/column default value is not properly quoted via PDO::quote() and this is now outdated.
I'll ask in #bugsmash to be sure.
Comment #21
daffie commentedDuplicate of #3130333: Column Default Values can not contain curly brackets or semicolons.