the shorthand 'status & :status' doesn't work on postgres. Postgres needs the comparison operator ' > 0' appended on the end

currently, File validator tests throws an Exception due to this.

patch simply appends the comparison on the end

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaotien’s picture

Clean Drupal 7 install on MySQL

File -> File Validator tests

Pre-patch: 27 passes, 0 fails, and 0 exceptions
Post-patch: 27 passes, 0 fails, and 0 exceptions

serenecloud’s picture

Status: Needs review » Reviewed & tested by the community

Testing with CVS HEAD and PostgreSQL 8.1

Without Patch:

SELECT SUM(filesize) FROM {files} WHERE uid = :uid AND status & :status - Array ( [:uid] => 3 [:status] => 1 ) SQLSTATE[42804]: Datatype mismatch: 7 ERROR: argument of AND must be type boolean, not type integer

After patch I ran the File SimpleTest:

215 passes, 0 fails, and 0 exceptions

Happy to mark this as reviewed.

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs work

Please use diff -up to create patches for core. See http://drupal.org/patch/create for more details.

Dave Reid’s picture

Plus, are bitwise operators a SQL standard? I can't find if they are and if they're not, they should be replaced.

Dave Reid’s picture

From system_schema, the {files}.status is simply an integer, so what reason do we have to do status & status > 0 instead of simply status > 0?

Josh Waihi’s picture

Status: Needs work » Needs review
FileSize
1.01 KB

we couldn't do status > 0 because you should be able to find the filesize sum of a group of file with a particular status. FILE_STATUS_TEMPORARY = 0 which means with bitwise comparison, you could never find the total filesize for temporary files with this function. so I think a simple WHERE status = :status would be better and from testing that I've done, it faster than bitwise comparison not to mention easier to understand for most people.

Dave Reid’s picture

Status: Needs review » Reviewed & tested by the community

That's a much better, more easily understood solution. The bitwise was just too confusing. Passed tests, looks good and RTBC.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

drewish’s picture

Status: Closed (fixed) » Needs work

Actually this is totally incorrect. The status field is documented as a bitmapped field not a simple integer I've been trying to get #330633: Temporary file cleanup needs some love (UnitTest included!) updated to check it correctly.

drewish’s picture

Dave Reid, grrrrr... just realized you'd been commenting on the other issue. i wish you'd have linked the two up but at least now i've got a pgsql fix for the other issue.

Dave Reid’s picture

Sorry drewish.

drewish’s picture

no, i apologize. it's really my fault for keeping an eye on the queue and for not installing pgsql and addressing #330633: Temporary file cleanup needs some love (UnitTest included!) a month ago. seems like #339588: Column type of int_unsigned causing pdoexception might be at the root of this.

drewish’s picture

Title: file_space_used SQL fails on Postgres » file_space_used() not checking properly checking bitmapped status value.
Status: Needs work » Postponed
FileSize
1.03 KB

marking this as postponed pending #339588: Column type of int_unsigned causing pdoexception. the attached patch works with pgsql once it's applied.

drewish’s picture

Status: Postponed » Needs review
Dries’s picture

Would be great if someone using PostgreSQL could run the tests with and without the latest patch. If this is PostgreSQL specific, I recommend adding PostgreSQL to the title.

drewish’s picture

Dries, I ended up figuring out how to setup pgsql just to test this patch so I can say clearly that it works with both MySQL and PostgreSQL. At this point it's not a pgsql specific fix since the pgsql "fix" reverted the desired behavior.

Dries’s picture

Well, but on MySQL there is no test failing with or without this patch. Does it mean that we don't have test coverage for this problem?

drewish’s picture

Status: Needs review » Needs work

Right the tests don't create files with multiple statues. I'll expand the function's test.

drewish’s picture

Status: Needs work » Needs review
FileSize
4.22 KB
drewish’s picture

Title: file_space_used() not checking properly checking bitmapped status value. » file_space_used() not checking properly checking bitmapped status value (adds unit tests)

oh, forgot to add that the current code has zero tests for file_space_used(). I'm not sure how it was over looked. The current patch adds tests.

Dries’s picture

Status: Needs review » Needs work

In the test code, can we stick to using the defines instead of integers? It would make the tests a lot easier to read/review, and it makes for better example code.

drewish’s picture

Assigned: Josh Waihi » drewish

Dries, 1 is the only core defined status and its constant is used. The other status values were arbitrarily selected for testing purposes. Are you suggesting that I should define constants in the test case? Or in core?

drewish’s picture

Status: Needs work » Needs review

bumping back to CNR since i think the current tests are correct.

Dries’s picture

Status: Needs review » Needs work

Nope, I'm not suggesting that you define constants for testing purpose. Maybe just add some more code comments to the test code. Explain why you are testing things this way, and mention that these values are arbitrarily selected. That should do it for me. Thanks!

drewish’s picture

just a note that this issue needs to keep any eye on #352956: PDOException on install and use a similar fix.

drewish’s picture

Status: Needs work » Needs review
FileSize
4.91 KB

Went ahead and converted this into a full DBTNG query. Added tests to the comments.

Dries’s picture

Status: Needs review » Needs work

When I run the tests, I get 2 failures:

Found the size of the first user's files with status 8.1	Other	file.test	188	FileSpaceUsedTest->testUserAndStatus()	
Found the size of the first user's files with status 2.	1	file.test	189	FileSpaceUsedTest->testUserAndStatus()
drewish’s picture

Status: Needs work » Needs review
FileSize
4.76 KB

sorry about that. it looks like i'd just re-submitted the last patch. here's the correct version.

Dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. Thanks all!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.