Closed (fixed)
Project:
Drupal core
Version:
7.x-dev
Component:
sqlite database
Priority:
Major
Category:
Bug report
Assigned:
Reporter:
Created:
21 Dec 2010 at 09:05 UTC
Updated:
5 Jan 2011 at 01:20 UTC
Jump to comment: Most recent file
SQLite update queries using expressions (like UPDATE ... SET count = count + 1) are failing, because of the way SQLite is rewriting the queries. This patch may or may not be the correct solution, but that's for chx to figure out. I think $data['expression'] is a db-safe value, but I don't know for sue
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | sqlite_update_query_expression.patch | 2.64 KB | dmitrig01 |
| #17 | sqlite_update_query_expression.patch | 2.64 KB | dmitrig01 |
| #16 | sqlite_update_query_expression.patch | 2.64 KB | dmitrig01 |
| #15 | sqlite_update_query_expression.patch | 3.39 KB | dmitrig01 |
| #14 | sqlite_update_query_expression.patch | 3.39 KB | dmitrig01 |
Comments
Comment #1
dmitrig01 commentedComment #2
dmitrig01 commentedAlso, whether or not it's the right solution, it fixes two of the five failing SQLite tests.
Comment #3
chx commentedWhile the patch is correct (I surely had a brain damaged moment when I wrote this if it was me who wrote this :) )...
Edit: yes the expression is safe, see how arguments can be passed into an expression.
Comment #4
dmitrig01 commentedTest will pass in MySQL but fail in SQLite w/o patch.
Comment #5
dmitrig01 commentedThe test is very ugly. Basically, I initially discovered this bug because of the fact that mergequery was using the same condition twice, with two separate queries. Here's what happens in MergeQuery:
So, this is an ugly bug, without an obvious solution. I think it would require an API change, and chx told me that it was already quite hard getting the placeholder incrementing correct.
HOWEVER, this also uncovered another bug (specific to SQLite), addressed by this patch: placeholders are used for expressions where the expression should just be inserted straight into SQL, and that's what this patch addresses. Thus, the test for this patch uses the fact that the above case fails to test it's own functionality: if the expression is inserted into as a placeholder, the placeholder will be a duplicate, and that will fail. If the expression is inserted as SQL, the placeholder won't be inserted, and it won't duplicate (and fail). I haven't thought of a better way to test this, as, so far as I've thought it through, it would have to look at SQL directly.
Comment #6
chx commentedLet me say this another way.
Comment #7
dmitrig01 commentedDamien is brilliant. 1*1 = 1, everything else is different. New tests which don't depend on the other bug. patch for that bug coming shortly
Comment #8
dmitrig01 commentedwrong patch (solves the other problem :P)
Comment #9
dmitrig01 commentedNow without a literal update
Comment #10
dmitrig01 commentedNow with comments:
There are 4 rows total. We update one of them to have age = 1. Then, they're squared. This should update three of them, as 1^2 doesn't change. This only actually fails in SQLite, as SQLite inverts the expression (age <> age * age) to only match rows it will change, and age <> "age * age" will match all 4 rows, even though only 3 will be updated.
Comment #11
dmitrig01 commentedNow with comments:
There are 4 rows total. We update one of them to have age = 1. Then, they're squared. This should update three of them, as 1^2 doesn't change. This only actually fails in SQLite, as SQLite inverts the expression (age <> age * age) to only match rows it will change, and age <> "age * age" will match all 4 rows, even though only 3 will be updated.
Comment #12
dmitrig01 commented.
Comment #13
dmitrig01 commentedThe other issue, btw, has been split out into #1004794: Adding a DatabaseCondition object to two queries fails
Comment #14
dmitrig01 commentedBetter comment, from Crell
Comment #15
dmitrig01 commentedBetter comment, from Crell
Comment #16
dmitrig01 commentedARGH i don't like managing multiple patches from a single drupal install
Comment #17
dmitrig01 commentedbetter assertion, from damz
Comment #18
dmitrig01 commentedgah
Comment #19
damien tournoud commentedI like it this way. And I like progress toward making SQLite 100% pass.
Comment #20
webchickSince #18 is just #8 with comments (which somehow took 11,000 follow-ups to get right ;)), committed to HEAD.
Yay SQLite passing!