Postgresql support
samuelet - July 10, 2008 - 08:18
| Project: | Private Upload |
| Version: | 6.x-1.0-beta2 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | starbow |
| Status: | needs review |
Description
It seems that postgresql backend is not supported.
For example i get this error:
SELECT COUNT(fid) FROM files WHERE filepath REGEXP '^private_upload';
and i think that in psql should be:
SELECT COUNT(fid) FROM files WHERE filepath like 'private_upload%';

#1
Bummer. If someone wants to create a patch, or event just give me equivalent sql querys that work for postgres for all the lines with REGEXP in them, I will roll them into a future version, but I don't have a postgres setup myself to test with.
#2
The standard (SQL-99) operators for regular expression pattern matching are LIKE and SIMILAR TO. The following changes should do:
line 185:
$old_file_count = db_result( db_query("SELECT COUNT(fid) FROM {files} WHERE filepath LIKE 'private_upload%'") );
line 508:
$db_private_file_count = db_result( db_query("SELECT COUNT(fid) FROM {files} WHERE filepath LIKE '%s%'", $private_path) );
lines 527-529:
$count = db_result( db_query('SELECT COUNT(DISTINCT(f.fid)) '.
'FROM {files} f INNER JOIN {upload} u ON f.fid=u.fid INNER JOIN {node_access} na ON u.nid=na.nid '.
"WHERE na.gid != 0 AND f.filepath NOT LIKE '%s%'", $private_path));
line 584-586:
$result = db_query('SELECT f.* FROM {files} f, {node_access} na '.
" WHERE f.nid = na.nid AND na.gid != 0 AND f.filepath NOT LIKE '%s%' ".
' GROUP BY f.fid', $private_path );
For the differences between LIKE and REGEXP, take a look at http://bugs.mysql.com/bug.php?id=746.
Regards
#3
Will this use of LIKE work in both mysql and postgres?
#4
As far as I am aware, yes, LIKE is supported by both MySQL and PostgreSQL.
http://dev.mysql.com/doc/refman/4.1/en/string-comparison-functions.html
#5
#6
I believe this is a bug report, not a feature request.
Anyway, very simple patch against version 6.x-1.0-beta2 attached. I haven't tested this on MySQL, but it works great in PostgreSQL, and the patch uses standard SQL so it should work on MySQL as well. LIKE may be slightly faster than REGEXP as well.
Thanks for a great module!
#7
#8
Thanks to webchick and davereid, a bug in my patch is now fixed. Attached should be correct.
[edit: Accidentally uploaded the original patch again -- sorry -- please ignore patch attached to this post]
#9
Wow -- sorry, I'm new at this. One last try.