r47085 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47084‎ | r47085 | r47086 >
Date:13:47, 10 February 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
integrated postgres compatibility patch by Marcel Gsteiger with some modifications
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -648,7 +648,7 @@
649649 $sql = 'p_id=smw_id AND o_id=' . $db->addQuotes($oid) .
650650 ' AND smw_iw=' . $db->addQuotes('') . // only local, non-internal properties
651651 $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',
653653 $sql, 'SMW::getInProperties', $this->getSQLOptions($requestoptions,'smw_sortkey') );
654654 while($row = $db->fetchObject($res)) {
655655 $result[] = SMWPropertyValue::makeProperty($row->smw_title);
@@ -937,18 +937,18 @@
938938 $options .= ' OFFSET ' . $requestoptions->offset;
939939 }
940940 // 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 ' .
942942 $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 ' .
945945 $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 ' .
948948 $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 ' .
951951 $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,
953953 'SMW::getPropertySubjects');
954954 $result = array();
955955 while($row = $db->fetchObject($res)) {
@@ -960,6 +960,7 @@
961961 }
962962
963963 function getUnusedPropertiesSpecial($requestoptions = NULL) {
 964+ global $wgDBtype;
964965 wfProfileIn("SMWSQLStore2::getUnusedPropertiesSpecial (SMW)");
965966 $db =& wfGetDB( DB_SLAVE );
966967 /// TODO: some db-calls in here can use better wrapper functions,
@@ -973,8 +974,23 @@
974975 }
975976 extract( $db->tableNames('page', 'smw_rels2', 'smw_atts2', 'smw_text2', 'smw_subs2', 'smw_ids', 'smw_tmp_unusedprops', 'smw_redi2') );
976977
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');
979995 $db->query( "INSERT INTO $smw_tmp_unusedprops SELECT page_title FROM $page" .
980996 " WHERE page_namespace=" . SMW_NS_PROPERTY , 'SMW::getUnusedPropertySubjects');
981997 foreach (array($smw_rels2,$smw_atts2,$smw_text2) as $table) {

Status & tagging log