Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -648,7 +648,7 @@ |
649 | 649 | $sql = 'p_id=smw_id AND o_id=' . $db->addQuotes($oid) . |
650 | 650 | ' AND smw_iw=' . $db->addQuotes('') . // only local, non-internal properties |
651 | 651 | $this->getSQLConditions($requestoptions,'smw_sortkey','smw_sortkey'); |
652 | | - $res = $db->select( array('smw_rels2','smw_ids'), 'DISTINCT smw_title', |
| 652 | + $res = $db->select( array('smw_rels2','smw_ids'), 'DISTINCT smw_title, smw_sortkey', |
653 | 653 | $sql, 'SMW::getInProperties', $this->getSQLOptions($requestoptions,'smw_sortkey') ); |
654 | 654 | while($row = $db->fetchObject($res)) { |
655 | 655 | $result[] = SMWPropertyValue::makeProperty($row->smw_title); |
— | — | @@ -937,18 +937,18 @@ |
938 | 938 | $options .= ' OFFSET ' . $requestoptions->offset; |
939 | 939 | } |
940 | 940 | // NOTE: the query needs to do the fitlering of internal properties, else LIMIT is wrong |
941 | | - $res = $db->query('(SELECT smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
| 941 | + $res = $db->query('(SELECT smw_id, smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
942 | 942 | $db->tableName('smw_rels2') . ' INNER JOIN ' . $db->tableName('smw_ids') . ' ON p_id=smw_id WHERE smw_iw=' . |
943 | | - $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY p_id) UNION ' . |
944 | | - '(SELECT smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
| 943 | + $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY smw_id) UNION ' . |
| 944 | + '(SELECT smw_id, smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
945 | 945 | $db->tableName('smw_spec2') . ' INNER JOIN ' . $db->tableName('smw_ids') . ' ON p_id=smw_id WHERE smw_iw=' . |
946 | | - $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY p_id) UNION ' . |
947 | | - '(SELECT smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
| 946 | + $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY smw_id) UNION ' . |
| 947 | + '(SELECT smw_id, smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
948 | 948 | $db->tableName('smw_atts2') . ' INNER JOIN ' . $db->tableName('smw_ids') . ' ON p_id=smw_id WHERE smw_iw=' . |
949 | | - $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY p_id) UNION ' . |
950 | | - '(SELECT smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
| 949 | + $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY smw_id) UNION ' . |
| 950 | + '(SELECT smw_id, smw_title, COUNT(*) as count, smw_sortkey FROM ' . |
951 | 951 | $db->tableName('smw_text2') . ' INNER JOIN ' . $db->tableName('smw_ids') . ' ON p_id=smw_id WHERE smw_iw=' . |
952 | | - $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY p_id)' . $options, |
| 952 | + $db->addQuotes('') . ' OR smw_iw=' . $db->addQuotes(SMW_SQL2_SMWPREDEFIW) . ' GROUP BY smw_id) ' . $options, |
953 | 953 | 'SMW::getPropertySubjects'); |
954 | 954 | $result = array(); |
955 | 955 | while($row = $db->fetchObject($res)) { |
— | — | @@ -960,6 +960,7 @@ |
961 | 961 | } |
962 | 962 | |
963 | 963 | function getUnusedPropertiesSpecial($requestoptions = NULL) { |
| 964 | + global $wgDBtype; |
964 | 965 | wfProfileIn("SMWSQLStore2::getUnusedPropertiesSpecial (SMW)"); |
965 | 966 | $db =& wfGetDB( DB_SLAVE ); |
966 | 967 | /// TODO: some db-calls in here can use better wrapper functions, |
— | — | @@ -973,8 +974,23 @@ |
974 | 975 | } |
975 | 976 | extract( $db->tableNames('page', 'smw_rels2', 'smw_atts2', 'smw_text2', 'smw_subs2', 'smw_ids', 'smw_tmp_unusedprops', 'smw_redi2') ); |
976 | 977 | |
977 | | - $db->query( "CREATE TEMPORARY TABLE $smw_tmp_unusedprops" . |
978 | | - ' ( title VARCHAR(255) ) TYPE=MEMORY', 'SMW::getUnusedPropertiesSpecial' ); |
| 978 | + if ($wgDBtype=='postgres') { // PostgresQL: no in-memory tables available |
| 979 | + $sql = "CREATE OR REPLACE FUNCTION create_" . $smw_tmp_unusedprops . "() RETURNS void AS " |
| 980 | + ."$$ " |
| 981 | + ."BEGIN " |
| 982 | + ." IF EXISTS(SELECT NULL FROM pg_tables WHERE tablename='" . $smw_tmp_unusedprops . "' AND schemaname = ANY (current_schemas(true))) " |
| 983 | + ." THEN DELETE FROM " . $smw_tmp_unusedprops ."; " |
| 984 | + ." ELSE " |
| 985 | + ." CREATE TEMPORARY TABLE " . $smw_tmp_unusedprops . " ( title text ); " |
| 986 | + ." END IF; " |
| 987 | + ."END; " |
| 988 | + ."$$ " |
| 989 | + ."LANGUAGE 'plpgsql'; " |
| 990 | + ."SELECT create_" . $smw_tmp_unusedprops . "(); "; |
| 991 | + } else { // MySQL: use temporary in-memory table |
| 992 | + $sql = "CREATE TEMPORARY TABLE " . $smw_tmp_unusedprops . "( title VARCHAR(255) ) TYPE=MEMORY"; |
| 993 | + } |
| 994 | + $db->query($sql, 'SMW::getUnusedPropertiesSpecial'); |
979 | 995 | $db->query( "INSERT INTO $smw_tmp_unusedprops SELECT page_title FROM $page" . |
980 | 996 | " WHERE page_namespace=" . SMW_NS_PROPERTY , 'SMW::getUnusedPropertySubjects'); |
981 | 997 | foreach (array($smw_rels2,$smw_atts2,$smw_text2) as $table) { |