Commit 357fd017 authored by Clare Lenihan's avatar Clare Lenihan Committed by Clare Lenihan
Browse files

removing casts except exactly where needed

parent 788ef565
......@@ -96,17 +96,17 @@ if ($groups['data']) {
LEFT JOIN {group_member} gm ON (gm.group = g.id)
LEFT JOIN {group_member_request} gmr ON (gmr.group = g.id)
LEFT JOIN (
SELECT g.id, CAST(\'owner\' AS VARCHAR(7)) AS type
SELECT g.id, \'owner\' AS type
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, CAST(\'member\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'member\' AS type
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
UNION SELECT g.id, CAST(\'invite\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'invite\' AS type
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, CAST(\'request\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'request\' AS type
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id
......
......@@ -39,11 +39,22 @@ $offset = param_integer('offset', 'all');
$groupsperpage = 20;
$offset = (int)($offset / $groupsperpage) * $groupsperpage;
// casting is only needed for invite, request and owner and only in postgres
if (is_mysql()) {
$invitesql = "'invite'";
$requestsql = "'request'";
$ownersql = "'owner'";
}
else {
$invitesql = "CAST('invite' AS TEXT)";
$requestsql = "CAST('request' AS TEXT)";
$ownersql = "CAST('owner' AS TEXT)";
}
// different filters join on the different kinds of association
if ($filter == 'owner') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'owner\' AS VARCHAR(7)) AS type
SELECT g.id, ' . $ownersql . ' AS type
FROM {group} g
WHERE g.owner = ?
) t ON t.id = g.id';
......@@ -52,10 +63,10 @@ if ($filter == 'owner') {
else if ($filter == 'member') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'owner\' AS VARCHAR(7)) AS type
SELECT g.id, \'owner\' AS type
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, CAST(\'member\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'member\' AS type
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
......@@ -65,7 +76,7 @@ else if ($filter == 'member') {
else if ($filter == 'invite') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'invite\' AS VARCHAR(7)) AS type
SELECT g.id, ' . $invitesql . ' AS type
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
) t ON t.id = g.id';
......@@ -74,7 +85,7 @@ else if ($filter == 'invite') {
else if ($filter == 'request') {
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'request\' AS VARCHAR(7)) AS type
SELECT g.id, ' . $requestsql . ' AS type
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id';
......@@ -84,17 +95,17 @@ else { // all or some other text
$filter = 'all';
$sql = '
INNER JOIN (
SELECT g.id, CAST(\'owner\' AS VARCHAR(7)) AS type
SELECT g.id, \'owner\' AS type
FROM {group} g
WHERE g.owner = ?
UNION SELECT g.id, CAST(\'member\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'member\' AS type
FROM {group} g
INNER JOIN {group_member} gm ON (g.id = gm.group AND gm.member = ?)
WHERE g.owner != gm.member
UNION SELECT g.id, CAST(\'invite\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'invite\' AS type
FROM {group} g
INNER JOIN {group_member_invite} gmi ON (gmi.group = g.id AND gmi.member = ?)
UNION SELECT g.id, CAST(\'request\' AS VARCHAR(7)) AS type
UNION SELECT g.id, \'request\' AS type
FROM {group} g
INNER JOIN {group_member_request} gmr ON (gmr.group = g.id AND gmr.member = ?)
) t ON t.id = g.id';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment