to duplicate this, create an order and then go to fulfill it. (I was working through the examples in "Using Drupal" by Byron et. al. from O'Reilly). When you hit the "packages" tab, you get an error:

warning: pg_query() [function.pg-query]: Query failed: ERROR: type "unsigned" does not exist LINE 1: ...r_product_id, CAST(SUM(op.qty) / COUNT(pp.qty) AS UNSIGNED) ... ^ in /var/www/drupal-6.8/includes/database.pgsql.inc on line 139.

user warning: query: SELECT op.order_product_id, CAST(SUM(op.qty) / COUNT(pp.qty) AS UNSIGNED) AS total, SUM(pp.qty) AS packaged FROM uc_order_products AS op LEFT JOIN uc_packaged_products AS pp ON op.order_product_id = pp.order_product_id WHERE op.order_id = 1 AND op.data LIKE '%s:9:"shippable";s:1:"1";%' GROUP BY op.order_product_id HAVING SUM(pp.qty) IS NULL OR CAST(SUM(op.qty) / COUNT(pp.qty) AS INTEGER) > SUM(pp.qty) in /var/www/drupal-6.8/sites/all/modules/ubercart/shipping/uc_shipping/uc_shipping.admin.inc on line 48.

I tried changing casts to UNSIGNED to be casts to INTEGER, but then got a division by zero error. Looking at this further, the query doesn't make sense to me (divide the total number of items by the count of non-zero package values?), so I replaced the query on line 48 with :

$result = db_query("SELECT op.order_product_id
, SUM(op.qty) AS total
, SUM(pp.qty) AS packaged
FROM {uc_order_products} AS op
LEFT JOIN {uc_packaged_products} AS pp
ON op.order_product_id = pp.order_product_id
WHERE op.order_id = %d
AND op.data LIKE '%%%s%%'
GROUP BY op.order_product_id
HAVING SUM(pp.qty) IS NULL
OR CAST(SUM(op.qty) - SUM(pp.qty) AS INTEGER) >
SUM(pp.qty)", $order->order_id, 's:9:"shippable";s :1:"1";');

And this seems to work (it got me through the example in the book), but I really don't understand the semantics of what the query is trying to do.

CommentFileSizeAuthor
#1 pg_div_by_0.patch1.44 KBIsland Usurper

Comments

Island Usurper’s picture

Assigned: Unassigned » Island Usurper
Status: Active » Fixed
StatusFileSize
new1.44 KB

Basically it's figuring out if there are any unpackaged products by counting up how many of each kind of product are in packages. MySQL apparently deals with division by 0 by returning NULL. I've committed this patch to check for rows in uc_packaged_products before dividing. CAST() appears to be one of those functions that you can't use in portable code. :(

Status: Fixed » Closed (fixed)

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