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

starbow - July 10, 2008 - 19:31

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

druido - October 24, 2008 - 17:59

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

starbow - October 25, 2008 - 00:57
Status:active» postponed (maintainer needs more info)

Will this use of LIKE work in both mysql and postgres?

#4

druido - October 25, 2008 - 16:49

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

starbow - October 27, 2008 - 17:36
Assigned to:Anonymous» starbow
Status:postponed (maintainer needs more info)» patch (to be ported)

#6

claar - October 21, 2009 - 21:25
Category:feature request» bug report
Status:patch (to be ported)» active

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!

AttachmentSize
postgresfix.patch 2.75 KB

#7

claar - October 21, 2009 - 21:38
Status:active» needs review

#8

claar - October 22, 2009 - 15:49

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]

AttachmentSize
postgresfix.patch 2.75 KB

#9

claar - October 21, 2009 - 21:44

Wow -- sorry, I'm new at this. One last try.

AttachmentSize
postgresfix.patch 2.75 KB
 
 

Drupal is a registered trademark of Dries Buytaert.