Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
ANSI-92 suggest database should return table/column/constraint name as upper case, but most open source database allow the mix use with lower case (lossy mode). On the other hand, some high-end database engine will force upper case (strict ANSI standard) for all table/column/constraint name, unless escape with escape characters.
PDO provide an ability for forcing return table/column/constraint name with upper/natural/lower case. This patch will force all database connection with PDO::CASE_LOWER so keep SQL compatibility for all database engine.
Comment | File | Size | Author |
---|---|---|---|
#30 | 337926-followup.patch | 7.45 KB | Damien Tournoud |
#28 | 337926-followup.patch | 7.25 KB | Damien Tournoud |
#27 | 337926-followup.patch | 6.59 KB | Damien Tournoud |
#25 | 337929-followup-sqlite-D7.patch | 5.65 KB | hswong3i |
#22 | 337929-followup-sqlite-D7.patch | 5.78 KB | hswong3i |
Comments
Comment #1
Crell CreditAttribution: Crell commentedI'm not entirely sure I follow. SQL is supposed to be case-insensitive, per the spec. MySQL does it a bit wrong and is case-sensitive for table names if and only if it's running on a case-sensitive file system. By just always using lowercase table and field names in all code, everything just works fine.
So what do we need here? Remember we could be dealing with foreign databases as well, which may not be as controlled as Drupal database.
Comment #2
hswong3i CreditAttribution: hswong3i commentedThis is a conventions that we used for many year. Seems there is no conflict with foreign database as well. From http://drupal.org/node/2497:
On the other hand, PDO::CASE_LOWER will only affect column name when fetching data. It have no duty for RAW SQL input. So standardize fetch mode with lower-case only can simplify our code implementation. Other system can still dealing with Drupal's database without any problem.
Comment #3
Dries CreditAttribution: Dries commentedI think this looks reasonable. Not Crell?
Comment #4
Crell CreditAttribution: Crell commentedIf I'm understanding the issue correctly and it just does case-folding on fetch, the only place we'd still have an issue is if we run into a 3rd party database table with columns foo and Foo, which would then get corrupted when loading. If we're OK with that limitation (I am, since making a DB like that is a moronic idea to begin with) then I'm OK with this patch.
We should make sure to document the case handling in the handbook, too.
Comment #5
hswong3i CreditAttribution: hswong3i commentedIMHO we should keep focus on ourselves before consider for 3rd party integration. We are able to change ourselves, but there is no way to enforce other party to follow our standard. In case we need to connect with those moronic system, just let people work for it and find a suitable solution :D
+1 for documentation, or we can even give an additional check case in Coder module, too.
Comment #6
Crell CreditAttribution: Crell commentedOK, here's my statement on it. +1 to forcing lower-case, but let's do it in a way that allows it to be over-ridden by a specific driver. That way, if someone really needs to connect to a 3rd party database where they do care about case they can clone their own custom driver and override the case handling, then connect to the external database with that driver instead.
That should be an easy change here and give us the most flexibility.
Comment #7
hswong3i CreditAttribution: hswong3i commentedHere is the revamp. I am not so sure why SQLite looks a bit different from MySQL and PostgreSQL, but I clone the handling for it. Please correct me if that's not work :S
Comment #9
hswong3i CreditAttribution: hswong3i commentedSilly mistake...
Comment #10
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD.
Comment #11
hswong3i CreditAttribution: hswong3i commentedThanks :D
Comment #12
Dave ReidThis broke sqlite support. Note that the $connection_options array is no longer passed to parent::__construct().
Comment #13
Damien Tournoud CreditAttribution: Damien Tournoud commentedIn #7, hswong3i said "I am not so sure why SQLite looks a bit different from MySQL and PostgreSQL, but I clone the handling for it. Please correct me if that's not work :S". Well, it was right, he wasn't sure.
Dries, could you give us more time to review those patches more carefully from now on?
Dave fix is sane.
Comment #14
hswong3i CreditAttribution: hswong3i commentedYes, I am not sure, so I ask. Seem this break SQLite because it need a manual hack with DatabaseStatement_sqlite which is now skipped :S
BTW, another question is: why PostgreSQL don't need this handling for
$connection_options['transactions']
?In case, should PostgreSQL look like this way?
Comment #15
Dave ReidThat would make sense to do, I'm testing it right now.
Comment #16
Dave ReidIn response to #14, it will fail for PostgreSQL. I literally had to code the following to get it to work in the pgsql driver:
Comment #17
Dave ReidWe should just bring the sqlite driver in line with the mysql/postgresql driver. This also brings the default port for postgresql in line with the mysql driver.
Comment #18
Damien Tournoud CreditAttribution: Damien Tournoud commentedFair enough.
The confusion comes from the fact that: $connection_options (our Drupal-specific options) != $driver_options (PDO driver options).
Comment #19
Dave ReidNevermind...#17 will break postgresql. Revised patch that just fixes the sqlite driver and brings it in line with the mysql and pgsql drivers' __construct functions.
Comment #20
Dave ReidAnother quick rewrite. Standardizing the drivers __construct function will be a separate issue. This just simply fixes the HEAD sqlite breakage.
Comment #21
Damien Tournoud CreditAttribution: Damien Tournoud commentedOk, this is the good one, thanks Dave.
Comment #22
hswong3i CreditAttribution: hswong3i commentedI give some similar tries as Dave Reid and coming with same conclusion as #19.
Maybe we can implement as this way? Move away
$connection_options['statement_class']
as driver specific$this->statementClass
, and clearly document that SQLite need to usePDOStatement
as default, with semi-private PDOPrepare()? With this model we can always keep PDO's $driver_options as different with Drupal's private $connection_options, they don't need to mix together.Patch tested with both MySQL, PostgreSQL and SQLite, all pass.
Comment #24
Dave ReidHow about we focus on the patch in #20 to fix the HEAD broken-ness and create a separate issue for synchronizing the __contstruct functions
Comment #25
hswong3i CreditAttribution: hswong3i commentedSorry for the delay of this issue, but this patch is now working for me. I am now running simpletest with both MySQL and SQLite, seems functioning. Hope test bot can catch if there is any error message.
Comment #26
Dries CreditAttribution: Dries commentedCommitted to CVS HEAD. Thanks, and sorry if I pulled the trigger on this one too fast.
Comment #27
Damien Tournoud CreditAttribution: Damien Tournoud commentedOk, let's do this properly, then.
Comment #28
Damien Tournoud CreditAttribution: Damien Tournoud commentedFixed spelling.
Comment #29
hswong3i CreditAttribution: hswong3i commented@Damien Tournoud: IMHO this issue is now get fix with its original target. Should clean up belongs to another new issue?
Comment #30
Damien Tournoud CreditAttribution: Damien Tournoud commented@hswong3i: you made the mess here, let's fix it here.
Comment #31
hswong3i CreditAttribution: hswong3i commentedI am not responsible for the mess of this issue. This is your doing...
Comment #32
Dries CreditAttribution: Dries commentedIt is a good clean up, indeed. Committed to CVS HEAD.
Comment #34
sunThis change broke third-party integration for no good reason: #1171866: Enforced fetching of fields/columns in lowercase breaks third-party integration
Comment #35
sphism CreditAttribution: sphism commentedForcing lowercase field names completely breaks connections to any other data... can this at least be optional?
Comment #36
marcingy CreditAttribution: marcingy commentedPlease see the issue referenced by Sun for follow up.