rendered paste bodyIndex: modules/core/classes/GalleryStorage/MySqlStorage.class
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryStorage/MySqlStorage.class,v
retrieving revision 1.3
diff -u -w -r1.3 MySqlStorage.class
--- modules/core/classes/GalleryStorage/MySqlStorage.class 10 Feb 2006 17:02:00 -0000 1.3
+++ modules/core/classes/GalleryStorage/MySqlStorage.class 20 Feb 2006 19:00:21 -0000
@@ -175,6 +175,10 @@
$sql .= ') VALUES ' . $rowList;
break;
+ case 'AVG':
+ $sql = sprintf('AVG(%s)', $args[0]);
+ break;
+
default:
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__,
$functionName . ' ' . implode(' ', $args)), null);
Index: modules/core/classes/GalleryStorage/Db2Storage.class
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryStorage/Db2Storage.class,v
retrieving revision 1.11
diff -u -w -r1.11 Db2Storage.class
--- modules/core/classes/GalleryStorage/Db2Storage.class 17 Feb 2006 23:47:08 -0000 1.11
+++ modules/core/classes/GalleryStorage/Db2Storage.class 20 Feb 2006 19:00:21 -0000
@@ -311,6 +311,14 @@
$sql .= ') VALUES ' . $rowList;
break;
+ case 'AVG':
+ /*
+ * DB2's AVG's return value is of the same type as the input value. To get the same
+ * behavior that we expect from MySQL and PostgreSQL, cast the input to double
+ */
+ $sql = sprintf('AVG(double(%s))', $args[0]);
+ break;
+
default:
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__,
$functionName . ' ' . implode(' ', $args)), null);
Index: modules/core/classes/GalleryStorage/OracleStorage.class
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryStorage/OracleStorage.class,v
retrieving revision 1.5
diff -u -w -r1.5 OracleStorage.class
--- modules/core/classes/GalleryStorage/OracleStorage.class 10 Feb 2006 17:02:00 -0000 1.5
+++ modules/core/classes/GalleryStorage/OracleStorage.class 20 Feb 2006 19:00:21 -0000
@@ -147,6 +147,10 @@
$sql .= ') ' . $rowList;
break;
+ case 'AVG':
+ $sql = sprintf('AVG(%s)', $args[0]);
+ break;
+
default:
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__,
$functionName . ' ' . implode(' ', $args)), null);
Index: modules/core/classes/GalleryStorage/PostgreSqlStorage.class
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/core/classes/GalleryStorage/PostgreSqlStorage.class,v
retrieving revision 1.8
diff -u -w -r1.8 PostgreSqlStorage.class
--- modules/core/classes/GalleryStorage/PostgreSqlStorage.class 10 Feb 2006 17:02:00 -0000 1.8
+++ modules/core/classes/GalleryStorage/PostgreSqlStorage.class 20 Feb 2006 19:00:21 -0000
@@ -228,6 +228,10 @@
$sql .= ') ' . $rowList;
break;
+ case 'AVG':
+ $sql = sprintf('AVG(%s)', $args[0]);
+ break;
+
default:
return array(GalleryCoreApi::error(ERROR_UNIMPLEMENTED, __FILE__, __LINE__,
$functionName . ' ' . implode(' ', $args)), null);
Index: modules/rating/classes/RatingHelper.class
===================================================================
RCS file: /cvsroot/gallery/gallery2/modules/rating/classes/RatingHelper.class,v
retrieving revision 1.5
diff -u -w -r1.5 RatingHelper.class
--- modules/rating/classes/RatingHelper.class 3 Feb 2006 21:48:03 -0000 1.5
+++ modules/rating/classes/RatingHelper.class 20 Feb 2006 19:00:21 -0000
@@ -219,9 +219,13 @@
}
/* Compute average and update cache table */
+ list ($ret, $avg) = $storage->getFunctionSql('AVG', array('[RatingMap::rating]'));
+ if ($ret) {
+ return array($ret->wrap(__FILE__, __LINE__), null);
+ }
$query = '
SELECT
- AVG([RatingMap::rating]),
+ ' . $avg . ',
COUNT([RatingMap::rating])
FROM
[RatingMap]