Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2_Queries.php |
— | — | @@ -127,7 +127,7 @@ |
128 | 128 | $this->m_dbs->delete( 'smw_conccache', array( 'o_id' => $cid ), 'SMW::refreshConceptCache' ); |
129 | 129 | |
130 | 130 | if ( $wgDBtype == 'postgres' ) { // PostgresQL: no INSERT IGNORE, check for duplicates explicitly |
131 | | - $where = $qobj->where . ( $qobj->where ? ' AND ':'' ) . |
| 131 | + $where = $qobj->where . ( $qobj->where ? ' AND ' : '' ) . |
132 | 132 | 'NOT EXISTS (SELECT NULL FROM ' . $this->m_dbs->tableName( 'smw_conccache' ) . |
133 | 133 | ' WHERE ' . $this->m_dbs->tablename( 'smw_conccache' ) . '.s_id = ' . $qobj->alias . '.s_id ' . |
134 | 134 | ' AND ' . $this->m_dbs->tablename( 'smw_conccache' ) . '.o_id = ' . $qobj->alias . '.o_id )'; |
— | — | @@ -135,10 +135,10 @@ |
136 | 136 | $where = $qobj->where; |
137 | 137 | } |
138 | 138 | |
139 | | - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "":"IGNORE " ) . "INTO " . $this->m_dbs->tableName( 'smw_conccache' ) . |
| 139 | + $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . 'INTO ' . $this->m_dbs->tableName( 'smw_conccache' ) . |
140 | 140 | " SELECT DISTINCT $qobj->joinfield AS s_id, $cid AS o_id FROM " . |
141 | 141 | $this->m_dbs->tableName( $qobj->jointable ) . " AS $qobj->alias" . $qobj->from . |
142 | | - ( $where ? " WHERE ":'' ) . $where . " LIMIT $smwgQMaxLimit", |
| 142 | + ( $where ? ' WHERE ' : '' ) . $where . " LIMIT $smwgQMaxLimit", |
143 | 143 | 'SMW::refreshConceptCache' ); |
144 | 144 | |
145 | 145 | $this->m_dbs->update( 'smw_conc2', array( 'cache_date' => strtotime( "now" ), 'cache_count' => $this->m_dbs->affectedRows() ), array( 's_id' => $cid ), 'SMW::refreshConceptCache' ); |
— | — | @@ -289,7 +289,7 @@ |
290 | 290 | $result .= 'SQL query<br />' . |
291 | 291 | "<tt>SELECT DISTINCT $qobj->alias.smw_title AS t,$qobj->alias.smw_namespace AS ns FROM " . |
292 | 292 | $this->m_dbs->tableName( $qobj->jointable ) . " AS $qobj->alias" . $qobj->from . |
293 | | - ( ( $qobj->where == '' ) ? '':' WHERE ' ) . $qobj->where . "$tailOpts LIMIT " . |
| 293 | + ( ( $qobj->where == '' ) ? '' : ' WHERE ' ) . $qobj->where . "$tailOpts LIMIT " . |
294 | 294 | $sql_options['LIMIT'] . ' OFFSET ' . $sql_options['OFFSET'] . ';</tt>'; |
295 | 295 | } else { |
296 | 296 | $result .= '<b>Empty result, no SQL query created.</b>'; |
— | — | @@ -809,14 +809,14 @@ |
810 | 810 | $condition = ''; |
811 | 811 | |
812 | 812 | foreach ( $subquery->joinfield as $value ) { |
813 | | - $condition .= ( $condition ? ' OR ':'' ) . "$joinfield=" . $this->m_dbs->addQuotes( $value ); |
| 813 | + $condition .= ( $condition ? ' OR ' : '' ) . "$joinfield=" . $this->m_dbs->addQuotes( $value ); |
814 | 814 | } |
815 | 815 | |
816 | 816 | if ( count( $subquery->joinfield ) > 1 ) { |
817 | 817 | $condition = "($condition)"; |
818 | 818 | } |
819 | 819 | |
820 | | - $query->where .= ( ( $query->where == '' ) ? '':' AND ' ) . $condition; |
| 820 | + $query->where .= ( ( $query->where == '' ) ? '' : ' AND ' ) . $condition; |
821 | 821 | } else { // interpret empty joinfields as impossible condition (empty result) |
822 | 822 | $query->joinfield = ''; // make whole query false |
823 | 823 | $query->jointable = ''; |
— | — | @@ -826,7 +826,7 @@ |
827 | 827 | } |
828 | 828 | |
829 | 829 | if ( $subquery->where != '' ) { |
830 | | - $query->where .= ( ( $query->where == '' ) ? '':' AND ' ) . '(' . $subquery->where . ')'; |
| 830 | + $query->where .= ( ( $query->where == '' ) ? '' : ' AND ' ) . '(' . $subquery->where . ')'; |
831 | 831 | } |
832 | 832 | |
833 | 833 | $query->from .= $subquery->from; |
— | — | @@ -887,10 +887,10 @@ |
888 | 888 | $sql = ''; |
889 | 889 | |
890 | 890 | if ( $subquery->jointable != '' ) { |
891 | | - $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '':'IGNORE ' ) . 'INTO ' . |
| 891 | + $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . 'INTO ' . |
892 | 892 | $this->m_dbs->tableName( $query->alias ) . |
893 | 893 | " SELECT $subquery->joinfield FROM " . $this->m_dbs->tableName( $subquery->jointable ) . |
894 | | - " AS $subquery->alias $subquery->from" . ( $subquery->where ? " WHERE $subquery->where":'' ); |
| 894 | + " AS $subquery->alias $subquery->from" . ( $subquery->where ? " WHERE $subquery->where" : '' ); |
895 | 895 | } elseif ( $subquery->joinfield !== '' ) { |
896 | 896 | // NOTE: this works only for single "unconditional" values without further |
897 | 897 | // WHERE or FROM. The execution must take care of not creating any others. |
— | — | @@ -900,7 +900,7 @@ |
901 | 901 | $values .= ( $values ? ',' : '' ) . '(' . $this->m_dbs->addQuotes( $value ) . ')'; |
902 | 902 | } |
903 | 903 | |
904 | | - $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '':'IGNORE ' ) . 'INTO ' . $this->m_dbs->tableName( $query->alias ) . " (id) VALUES $values"; |
| 904 | + $sql = 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . 'INTO ' . $this->m_dbs->tableName( $query->alias ) . " (id) VALUES $values"; |
905 | 905 | } // else: // interpret empty joinfields as impossible condition (empty result), ignore |
906 | 906 | if ( $sql ) { |
907 | 907 | $this->m_querylog[$query->alias][] = $sql; |
— | — | @@ -948,11 +948,11 @@ |
949 | 949 | $valuecond = ''; |
950 | 950 | |
951 | 951 | foreach ( $query->joinfield as $value ) { |
952 | | - $values .= ( $values ? ',':'' ) . '(' . $this->m_dbs->addQuotes( $value ) . ')'; |
953 | | - $valuecond .= ( $valuecond ? ' OR ':'' ) . 'o_id=' . $this->m_dbs->addQuotes( $value ); |
| 952 | + $values .= ( $values ? ',' : '' ) . '(' . $this->m_dbs->addQuotes( $value ) . ')'; |
| 953 | + $valuecond .= ( $valuecond ? ' OR ' : '' ) . 'o_id=' . $this->m_dbs->addQuotes( $value ); |
954 | 954 | } |
955 | 955 | |
956 | | - $smwtable = $this->m_dbs->tableName( ( $query->type == SMW_SQL2_PROP_HIERARCHY ) ? 'smw_subp2':'smw_subs2' ); |
| 956 | + $smwtable = $this->m_dbs->tableName( ( $query->type == SMW_SQL2_PROP_HIERARCHY ) ? 'smw_subp2' : 'smw_subs2' ); |
957 | 957 | |
958 | 958 | // Try to safe time (SELECT is cheaper than creating/dropping 3 temp tables): |
959 | 959 | $res = $this->m_dbs->select( $smwtable, 's_id', $valuecond, array( 'LIMIT' => 1 ) ); |
— | — | @@ -991,19 +991,21 @@ |
992 | 992 | // obtained in the previous step are relevant. So this is a performance measure. |
993 | 993 | $tmpnew = 'smw_new'; |
994 | 994 | $tmpres = 'smw_res'; |
| 995 | + |
995 | 996 | $this->m_dbs->query( $this->getCreateTempIDTableSQL( $tmpnew ), 'SMW::executeQueries' ); |
996 | 997 | $this->m_dbs->query( $this->getCreateTempIDTableSQL( $tmpres ), 'SMW::executeQueries' ); |
997 | | - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "" : "IGNORE" ) . " INTO $tablename (id) VALUES $values", 'SMW::executeHierarchyQuery' ); |
998 | | - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? "" : "IGNORE" ) . " INTO $tmpnew (id) VALUES $values", 'SMW::executeHierarchyQuery' ); |
| 998 | + |
| 999 | + $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : "IGNORE" ) . " INTO $tablename (id) VALUES $values", 'SMW::executeHierarchyQuery' ); |
| 1000 | + $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : "IGNORE" ) . " INTO $tmpnew (id) VALUES $values", 'SMW::executeHierarchyQuery' ); |
999 | 1001 | |
1000 | 1002 | for ( $i = 0; $i < $depth; $i++ ) { |
1001 | | - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tmpres (id) SELECT s_id" . ( $wgDBtype == 'postgres' ? '::integer':'' ) . " FROM $smwtable, $tmpnew WHERE o_id=id", |
| 1003 | + $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tmpres (id) SELECT s_id" . ( $wgDBtype == 'postgres' ? '::integer' : '' ) . " FROM $smwtable, $tmpnew WHERE o_id=id", |
1002 | 1004 | 'SMW::executeHierarchyQuery' ); |
1003 | 1005 | if ( $this->m_dbs->affectedRows() == 0 ) { // no change, exit loop |
1004 | 1006 | break; |
1005 | 1007 | } |
1006 | 1008 | |
1007 | | - $this->m_dbs->query( "INSERT " . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tablename (id) SELECT $tmpres.id FROM $tmpres", |
| 1009 | + $this->m_dbs->query( 'INSERT ' . ( ( $wgDBtype == 'postgres' ) ? '' : 'IGNORE ' ) . "INTO $tablename (id) SELECT $tmpres.id FROM $tmpres", |
1008 | 1010 | 'SMW::executeHierarchyQuery' ); |
1009 | 1011 | |
1010 | 1012 | if ( $this->m_dbs->affectedRows() == 0 ) { // no change, exit loop |
— | — | @@ -1032,6 +1034,7 @@ |
1033 | 1035 | */ |
1034 | 1036 | protected function applyOrderConditions( $qid ) { |
1035 | 1037 | $qobj = $this->m_queries[$qid]; |
| 1038 | + |
1036 | 1039 | // (1) collect required extra property descriptions: |
1037 | 1040 | $extraproperties = array(); |
1038 | 1041 | |
— | — | @@ -1098,9 +1101,10 @@ |
1099 | 1102 | */ |
1100 | 1103 | protected function cleanUp() { |
1101 | 1104 | global $wgDBtype; |
| 1105 | + |
1102 | 1106 | if ( $this->m_qmode !== SMWQuery::MODE_DEBUG ) { |
1103 | 1107 | foreach ( $this->m_querylog as $table => $log ) { |
1104 | | - $this->m_dbs->query( ( ( $wgDBtype == 'postgres' ) ? "DROP TABLE IF EXISTS ":"DROP TEMPORARY TABLE " ) . $this->m_dbs->tableName( $table ), 'SMW::getQueryResult' ); |
| 1108 | + $this->m_dbs->query( ( ( $wgDBtype == 'postgres' ) ? 'DROP TABLE IF EXISTS ' : 'DROP TEMPORARY TABLE ' ) . $this->m_dbs->tableName( $table ), 'SMW::getQueryResult' ); |
1105 | 1109 | } |
1106 | 1110 | } |
1107 | 1111 | } |