r23227 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23226‎ | r23227 | r23228 >
Date:14:56, 22 June 2007
Author:mkroetzsch
Status:old
Tags:
Comment:
Removed old commented-out code.
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore.php
@@ -961,171 +961,6 @@
962962 }
963963
964964 /**
965 - * Create an SQL query for a given description. The query is defined by call-by-ref
966 - * parameters for conditions (WHERE) and tables (FROM). Further condistions are not
967 - * encoded in the description. If the parameter $jointable is given, the function will
968 - * insert conditions for joining its conditions with the given table. It is assumed
969 - * that the $jointable has an appropriate signature. If no $jointable is given, the
970 - * function returns the name of a table field that contains the *title ids* for the
971 - * possible result values, if this is meaningful (i.e. if no datavalues are selected).
972 - * In all other cases the return value is undefined.
973 - *
974 - * Some notes on sorting: sorting is applied only to fields that appear in the query
975 - * by verifying conditions and the sorting conditions thus operate on the values that
976 - * satisfy the given conditions. This may have side effects in cases where one porperty
977 - * that shall be sorted has multiple values. If no condition other than existence applies
978 - * to such a property, the value that is relevant for sorting is not really dertermined and
979 - * the behaviour of SQL is not clear (I think). If the condition preselects larger or smaller
980 - * values, however, then these would probably be used for sorting. Overall this should not
981 - * be a problem, since it only occurs in cases where the sort order is not fully specified anyway.
982 - *
983 - * Also, sorting may (1) impair performance, since SQL needs to keep track of additional values,
984 - * (2) impair performance, since additional joins may be needed to incorporate into the query the
985 - * page names by which something should be sorted (while otherwise IDs suffice for treating many
986 - * cases).
987 - *
988 - * @param $description The SMWDescription to be processed.
989 - * @param &$tables The string of computed FROM statements (with aliases for tables), appended to supplied string.
990 - * @param &$conds The string of computed WHERE conditions, appended to supplied string.
991 - * @param $db The database object
992 - * @param $tablepref The base name of table aliases that may be created. Used as a prefix to all such aliases.
993 - * @param $jointable The name of the table with which the results should be joined or none if the join is performed by the caller.
994 - * @param $sort True if the subcondition should be used for sorting. This is only meaningful for queries that are below some relation or attribute statement.
995 - *
996 - * @TODO: there are still design problems with sorting, since sorting always needs unique article title fields that some descriptions just do not yield. One problem is SMWThingDescription: if not joined, it just cannot provide a (set of) ids that could be used to join the page table for obtaining the title texts. Maybe one should handle all relation-sort cases in the condition root (when handling SMWSomeRelation)? This woul simplify matters but then $sort is only relevant in one case, which is strange design too. But anyway this appears to be preferrable.
997 - * @TODO: the case of disjunction is not implemented yet. Somewhat unclear.
998 - * @TODO: Maybe there need to be optimisations in certain cases (atomic implementation for common nestings of descriptions?)
999 - */
1000 -// protected function oldcreateSQLQuery(SMWDescription $description, &$tables, &$conds, &$db, $tablepref = 't', $jointable = '', $sort = false) {
1001 -// $tablecount = 0;
1002 -// $newtables = '';
1003 -// $newconds = '';
1004 -// $result = NULL;
1005 -// if ($description instanceof SMWThingDescription) {
1006 -// // no condition (and no possible return id value)
1007 -// if ( ($sort) && ($jointable != '') ) {
1008 -// $this->m_sortfield = $jointable . '.object_title';
1009 -// }
1010 -// } elseif ($description instanceof SMWClassDescription) {
1011 -// $cattable = $tablepref . $tablecount++;
1012 -// $newtables .= $db->tableName('categorylinks') . ' as ' . $cattable;
1013 -// $newconds .= $cattable . '.cl_to=' . $db->addQuotes($description->getCategory()->getText());
1014 -// $result = $cattable . '.cl_from';
1015 -// } elseif ($description instanceof SMWNominalDescription) {
1016 -// if ($jointable != '') {
1017 -// $newconds .= $jointable . '.object_title=' .
1018 -// $db->addQuotes($description->getIndividual()->getText()) . ' AND ' .
1019 -// $jointable . '.object_namespace=' . $description->getIndividual()->getNamespace();
1020 -// if ($sort) {
1021 -// $this->m_sortfield = $jointable . '.object_title';
1022 -// }
1023 -// } else {
1024 -// $pagetable = $tablepref . $tablecount++;
1025 -// $newtables .= $db->tableName('page') . ' as ' . $pagetable;
1026 -// $newconds .= $pagetable . '.page_title=' .
1027 -// $db->addQuotes($description->getIndividual()->getText()) . ' AND ' .
1028 -// $pagetable . '.page_namespace=' . $description->getIndividual()->getNamespace();
1029 -// $result = $pagetable . '.page_id';
1030 -// if ($sort) {
1031 -// $this->m_sortfield = $pagetable . '.page_title';
1032 -// $sort = false; // (prevents standard handling of sorting below)
1033 -// }
1034 -// }
1035 -// } elseif ($description instanceof SMWValueDescription) {
1036 -// if ($jointable != '') {
1037 -// switch ($description->getComparator()) {
1038 -// case SMW_CMP_EQ: $op = '='; break;
1039 -// case SMW_CMP_LEQ: $op = '<='; break;
1040 -// case SMW_CMP_GEQ: $op = '>='; break;
1041 -// case SMW_CMP_NEQ: $op = '!='; break;
1042 -// case SMW_CMP_ANY: default: $op = NULL; break;
1043 -// }
1044 -// if ($op !== NULL) {
1045 -// if ($description->getDatavalue()->isNumeric()) {
1046 -// $valuefield = 'value_num';
1047 -// $value = $description->getDatavalue()->getNumericValue();
1048 -// } else {
1049 -// $valuefield = 'value_xsd';
1050 -// $value = $description->getDatavalue()->getXSDValue();
1051 -// }
1052 -// //TODO: implement check for unit
1053 -// $newconds .= $jointable . '.' . $valuefield . $op . $db->addQuotes($value);
1054 -// if ($sort != '') {
1055 -// $this->m_sortfield = $jointable . '.' . $valuefield;
1056 -// }
1057 -// }
1058 -// } // else: not possible
1059 -// } elseif ($description instanceof SMWConjunction) {
1060 -// $id = NULL;
1061 -// foreach ($description->getDescriptions() as $subdesc) {
1062 -// $subtablepref = $tablepref . $tablecount++ . 't';
1063 -// $newid = $this->createSQLQuery($subdesc, $newtables, $newconds, $db, $subtablepref);
1064 -// if ($newid !== NULL) { // catches e.g. the case that owl:Thing is used in conjunctions (no id)
1065 -// if ($id !== NULL) {
1066 -// $newconds .= ' AND ' . $id . '=' . $newid;
1067 -// }
1068 -// $id = $newid;
1069 -// }
1070 -// }
1071 -// $result = $id; //NULL if only non-sensical conditions were included
1072 -// } elseif ($description instanceof SMWDisjunction) {
1073 -// $id = NULL;
1074 -// ///TODO: complete
1075 -// foreach ($description->getDescriptions() as $subdesc) {
1076 -// // $subtablepref = $tablepref . $tablecount++ . 't';
1077 -// // $newid = $this->createSQLQuery($subdesc, $newtables, $newconds, $db, $subtablepref);
1078 -// // if ($newid !== NULL) { // catches e.g. the case that owl:Thing is used in conjunctions (no id)
1079 -// // if ($id !== NULL) {
1080 -// // $newconds .= ' AND ' . $id . '=' . $newid;
1081 -// // }
1082 -// // $id = $newid;
1083 -// // }
1084 -// }
1085 -// $result = $id; //NULL if only non-sensical conditions were included
1086 -// } elseif ($description instanceof SMWSomeRelation) {
1087 -// $reltable = $tablepref . $tablecount++;
1088 -// $newtables .= $db->tableName('smw_relations') . ' as ' . $reltable;
1089 -// $newconds .= $reltable . '.relation_title=' . $db->addQuotes($description->getRelation()->getDBKey());
1090 -// $this->createSQLQuery($description->getDescription(), $newtables, $newconds, $db, $reltable . 't', $reltable, ($this->m_sortkey == $description->getRelation()->getDBKey()) );
1091 -// $result = $reltable . '.subject_id';
1092 -// } elseif ($description instanceof SMWSomeAttribute) {
1093 -// $atttable = $tablepref . $tablecount++;
1094 -// $newtables .= $db->tableName('smw_attributes') . ' as ' . $atttable;
1095 -// $newconds .= $atttable . '.attribute_title=' . $db->addQuotes($description->getAttribute()->getDBKey());
1096 -// $this->createSQLQuery($description->getDescription(), $newtables, $newconds, $db, $atttable . 't', $atttable, ($this->m_sortkey == $description->getAttribute()->getDBKey()) );
1097 -// $result = $atttable . '.subject_id';
1098 -// }
1099 -//
1100 -// // add standard join and sort clauses if applicable
1101 -// if ( ( ($jointable != '') || ($sort) ) && ($result !== NULL) ) {
1102 -// $pagetable = $tablepref . $tablecount++;
1103 -// if ($newtables != '') {
1104 -// $newtables .= ', ';
1105 -// }
1106 -// $newtables .= $db->tableName('page') . ' as ' . $pagetable;
1107 -// $newconds .= $result . '=' . $pagetable . '.page_id';
1108 -// if ($jointable != '') {
1109 -// $newconds .= ' AND ' . $jointable . '.object_title=' . $pagetable . '.page_title' . ' AND ' .
1110 -// $jointable . '.object_namespace=' . $pagetable . '.page_namespace';
1111 -// }
1112 -// if ($sort != '') {
1113 -// $this->m_sortfield = $pagetable . '.page_title';
1114 -// }
1115 -// }
1116 -//
1117 -// if ( ($tables != '') && ($newtables != '') ) {
1118 -// $tables .= ', ';
1119 -// }
1120 -// $tables .= $newtables;
1121 -// if ( ($conds != '') && ($newconds != '') ) {
1122 -// $conds .= ' AND (';
1123 -// $newconds .= ')';
1124 -// }
1125 -// $conds .= $newconds;
1126 -// return $result;
1127 -// }
1128 -
1129 - /**
1130965 * Make sure that the given column in the given DB table is indexed by *one* index.
1131966 */
1132967 protected function setupIndex($table, $column, $db) {

Status & tagging log