r94077 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94076‎ | r94077 | r94078 >
Date:19:53, 8 August 2011
Author:kipcool
Status:deferred
Tags:
Comment:
dbr/dbw convention ; added some freeResult and limit 1
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php (modified) (history)
  • /trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataGlobals.php
@@ -1,6 +1,7 @@
22 <?php
33
44 define( 'NS_EXPRESSION', 16 );
 5+define( 'NS_DEFINEDMEANING', 24 );
56
67 require_once( "Wikidata.php" );
78
Index: trunk/extensions/Wikidata/OmegaWiki/WikiDataAPI.php
@@ -1,6 +1,7 @@
22 <?php
33
44 require_once( 'Transaction.php' );
 5+require_once( 'WikiDataGlobals.php' );
56
67 class Expression {
78 public $id;
@@ -54,6 +55,7 @@
5556 while ( $syntransRecord = $dbr->fetchObject( $queryResult ) ) {
5657 $this->meaningIds[] = $syntransRecord->defined_meaning_id;
5758 }
 59+ $dbr->freeResult( $queryResult ) ;
5860 }
5961
6062 }
@@ -64,9 +66,9 @@
6567 $dbr = wfGetDB( DB_SLAVE );
6668 $queryResult = $dbr->query( "SELECT spelling, language_id " .
6769 " FROM {$dc}_expression " .
68 - " WHERE {$dc}_expression.expression_id=$expressionId" .
69 - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
 70+ " WHERE {$dc}_expression.expression_id=$expressionId LIMIT 1" );
7071 $expressionRecord = $dbr->fetchObject( $queryResult );
 72+ $dbr->freeResult( $queryResult ) ;
7173 if ( $expressionRecord ) {
7274 $expression = new Expression( $expressionId, $expressionRecord->spelling, $expressionRecord->language_id );
7375 return $expression;
@@ -78,10 +80,10 @@
7981 function newObjectId( $table ) {
8082 $dc = wdGetDataSetContext();
8183
82 - $dbr = wfGetDB( DB_MASTER );
83 - $dbr->query( "INSERT INTO {$dc}_objects (`table`, `UUID`) VALUES (" . $dbr->addQuotes( $table ) . ", UUID())" );
 84+ $dbw = wfGetDB( DB_MASTER );
 85+ $dbw->query( "INSERT INTO {$dc}_objects (`table`, `UUID`) VALUES (" . $dbw->addQuotes( $table ) . ", UUID())" );
8486
85 - return $dbr->insertId();
 87+ return $dbw->insertId();
8688 }
8789
8890 function getTableNameWithObjectId( $objectId ) {
@@ -107,7 +109,7 @@
108110 $dbr = wfGetDB( DB_SLAVE );
109111 $sql = "SELECT expression_id FROM {$dc}_expression " .
110112 'WHERE spelling=binary ' . $dbr->addQuotes( $spelling ) . ' AND language_id=' . $languageId .
111 - ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" );
 113+ ' AND ' . getLatestTransactionRestriction( "{$dc}_expression" ) . " LIMIT 1 " ;
112114 $queryResult = $dbr->query( $sql );
113115 $expression = $dbr->fetchObject( $queryResult );
114116 return isset( $expression->expression_id ) ? $expression->expression_id : null;
@@ -119,10 +121,10 @@
120122
121123 $expressionId = newObjectId( "{$dc}_expression" );
122124
123 - $dbr = wfGetDB( DB_MASTER );
124 - $spelling = $dbr->addQuotes( $spelling );
 125+ $dbw = wfGetDB( DB_MASTER );
 126+ $spelling = $dbw->addQuotes( $spelling );
125127
126 - $dbr->query( "INSERT INTO {$dc}_expression(expression_id, spelling, language_id, add_transaction_id) values($expressionId, $spelling, $languageId, " . getUpdateTransactionId() . ")" );
 128+ $dbw->query( "INSERT INTO {$dc}_expression(expression_id, spelling, language_id, add_transaction_id) values($expressionId, $spelling, $languageId, " . getUpdateTransactionId() . ")" );
127129
128130 return $expressionId;
129131 }
@@ -133,48 +135,47 @@
134136
135137
136138 function createPage( $namespace, $title ) {
137 - $dbr = wfGetDB( DB_MASTER );
138 - $title = $dbr->addQuotes( $title );
139 - $timestamp = $dbr->timestamp();
 139+ $dbw = wfGetDB( DB_MASTER );
 140+ $title = $dbw->addQuotes( $title );
 141+ $timestamp = $dbw->timestamp();
140142 $sql = "select page_id from page where page_namespace = $namespace and page_title = $title";
141 - $queryResult = $dbr->query( $sql );
142 - $page = $dbr->fetchObject( $queryResult );
 143+ $queryResult = $dbw->query( $sql );
 144+ $page = $dbw->fetchObject( $queryResult );
143145 if ( isset( $page->page_id ) ) {
144146 return $page->page_id;
145147 }
146148 else {
147149 $sql = "insert into page(page_namespace,page_title,page_is_new,page_touched) " .
148150 "values($namespace, $title, 1, $timestamp)";
149 - $dbr->query( $sql );
150 - return $dbr->insertId();
 151+ $dbw->query( $sql );
 152+ return $dbw->insertId();
151153 }
152154 }
153155
154156 function setPageLatestRevision( $pageId, $latestRevision ) {
155 - $dbr = wfGetDB( DB_MASTER );
 157+ $dbw = wfGetDB( DB_MASTER );
156158 $sql = "update page set page_latest=$latestRevision where page_id=$pageId";
157 - $dbr->query( $sql );
 159+ $dbw->query( $sql );
158160 }
159161 function createInitialRevisionForPage( $pageId, $comment ) {
160 - global
161 - $wgUser;
 162+ global $wgUser;
162163
163 - $dbr = wfGetDB( DB_MASTER );
 164+ $dbw = wfGetDB( DB_MASTER );
164165 $userId = $wgUser->getID();
165 - $userName = $dbr->addQuotes( $wgUser->getName() );
166 - $comment = $dbr->addQuotes( $comment );
167 - $timestamp = $dbr->timestamp();
 166+ $userName = $dbw->addQuotes( $wgUser->getName() );
 167+ $comment = $dbw->addQuotes( $comment );
 168+ $timestamp = $dbw->timestamp();
168169
169170 $sql = "insert into revision(rev_page,rev_comment,rev_user,rev_user_text,rev_timestamp) " .
170171 "values($pageId, $comment, $userId, $userName, $timestamp)";
171 - $dbr->query( $sql );
 172+ $dbw->query( $sql );
172173
173 - $revisionId = $dbr->insertId();
 174+ $revisionId = $dbw->insertId();
174175 setPageLatestRevision( $pageId, $revisionId );
175176
176177 return $revisionId;
177178 }
178 -
 179+
179180 function findExpression( $spelling, $languageId ) {
180181 if ( $expressionId = getExpressionId( $spelling, $languageId ) ) {
181182 return new Expression( $expressionId, $spelling, $languageId );
@@ -200,13 +201,12 @@
201202 return createExpression( $spelling, $languageId );
202203 }
203204
204 -
205 -
206205 function getSynonymId( $definedMeaningId, $expressionId ) {
207206 $dc = wdGetDataSetContext();
208207 $dbr = wfGetDB( DB_SLAVE );
209208 $queryResult = $dbr->query( "SELECT syntrans_sid FROM {$dc}_syntrans " .
210 - "WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId LIMIT 1" );
 209+ "WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId " .
 210+ getLatestTransactionRestriction( "{$dc}_syntrans" ) . " LIMIT 1" );
211211
212212 if ( $synonym = $dbr->fetchObject( $queryResult ) )
213213 return $synonym->syntrans_sid;
@@ -223,16 +223,15 @@
224224 if ( $synonymId == 0 )
225225 $synonymId = newObjectId( "{$dc}_syntrans" );
226226
227 - $dbr = wfGetDB( DB_MASTER );
 227+ $dbw = wfGetDB( DB_MASTER );
228228 $identicalMeaningInteger = (int) $identicalMeaning;
229229 $sql = "insert into {$dc}_syntrans(syntrans_sid, defined_meaning_id, expression_id, identical_meaning, add_transaction_id) " .
230230 "values($synonymId, $definedMeaningId, $expressionId, $identicalMeaningInteger, " . getUpdateTransactionId() . ")";
231 - $queryResult = $dbr->query( $sql );
 231+ $queryResult = $dbw->query( $sql );
232232 }
233233
234234 function expressionIsBoundToDefinedMeaning( $definedMeaningId, $expressionId ) {
235 - global
236 - $dataSet;
 235+ global $dataSet;
237236
238237 $dc = wdGetDataSetContext();
239238 $dbr = wfGetDB( DB_SLAVE );
@@ -285,7 +284,7 @@
286285 $dbr = wfGetDB( DB_SLAVE );
287286 $queryResult = $dbr->query( "SELECT meaning1_mid FROM {$dc}_meaning_relations " .
288287 "WHERE meaning1_mid=$definedMeaning1Id AND meaning2_mid=$definedMeaning2Id AND relationtype_mid=$relationTypeId " .
289 - "AND " . getLatestTransactionRestriction( "{$dc}_meaning_relations" ) );
 288+ "AND " . getLatestTransactionRestriction( "{$dc}_meaning_relations" ) . " LIMIT 1" );
290289
291290 return $dbr->numRows( $queryResult ) > 0;
292291 }
@@ -298,10 +297,10 @@
299298 if ( $relationId == 0 )
300299 $relationId = newObjectId( "{$dc}_meaning_relations" );
301300
302 - $dbr = wfGetDB( DB_MASTER );
 301+ $dbw = wfGetDB( DB_MASTER );
303302 $sql = "INSERT INTO {$dc}_meaning_relations(relation_id, meaning1_mid, meaning2_mid, relationtype_mid, add_transaction_id) " .
304303 " VALUES ($relationId, $definedMeaning1Id, $definedMeaning2Id, $relationTypeId, " . getUpdateTransactionId() . ")";
305 - $dbr->query( $sql );
 304+ $dbw->query( $sql );
306305 }
307306
308307 function addRelation( $definedMeaning1Id, $relationTypeId, $definedMeaning2Id ) {
@@ -311,16 +310,16 @@
312311
313312 function removeRelation( $definedMeaning1Id, $relationTypeId, $definedMeaning2Id ) {
314313 $dc = wdGetDataSetContext();
315 - $dbr = wfGetDB( DB_MASTER );
316 - $dbr->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() .
 314+ $dbw = wfGetDB( DB_MASTER );
 315+ $dbw->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() .
317316 " WHERE meaning1_mid=$definedMeaning1Id AND meaning2_mid=$definedMeaning2Id AND relationtype_mid=$relationTypeId " .
318317 " AND remove_transaction_id IS NULL" );
319318 }
320319
321320 function removeRelationWithId( $relationId ) {
322321 $dc = wdGetDataSetContext();
323 - $dbr = wfGetDB( DB_MASTER );
324 - $dbr->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() .
 322+ $dbw = wfGetDB( DB_MASTER );
 323+ $dbw->query( "UPDATE {$dc}_meaning_relations SET remove_transaction_id=" . getUpdateTransactionId() .
325324 " WHERE relation_id=$relationId " .
326325 " AND remove_transaction_id IS NULL" );
327326 }
@@ -336,13 +335,13 @@
337336 * @param unknown_type $relationTypeId dmid of the relationtype, optional.
338337 * @param unknown_type $lhs dmid of the left hand side, optional.
339338 * @param unknown_type $dmId dmid of the right hand side, optional.
340 - * * @param unknown_type $dc the dataset, optional
 339+ * @param unknown_type $dc the dataset, optional
341340 */
342341 function getRelationDefinedMeanings( $relationTypeId = null, $lhs = null, $rhs = null, $dc = null ) {
343342 $result = array();
344343
345344 $dc = wdGetDataSetContext( $dc );
346 - $dbr = wfGetDB( DB_MASTER );
 345+ $dbr = wfGetDB( DB_SLAVE );
347346 if ( $relationTypeId == null ) {
348347 if ( $lhs == null ) {
349348 if ( $rhs == null ) return $result;
@@ -390,7 +389,8 @@
391390 while ( $row = $dbr->fetchRow( $queryResult ) ) {
392391 $result[] = $row[0];
393392 }
394 -
 393+ $dbr->freeResult( $queryResult ) ;
 394+
395395 return $result;
396396 }
397397
@@ -404,8 +404,8 @@
405405 $dbr = wfGetDB( DB_SLAVE );
406406 $queryResult = $dbr->query( "SELECT object_id FROM {$dc}_class_attributes" .
407407 " WHERE class_mid=$classMeaningId AND level_mid=$levelMeaningId AND attribute_mid=$attributeMeaningId AND attribute_type = " . $dbr->addQuotes( $attributeType ) .
408 - ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ) );
409 -
 408+ ' AND ' . getLatestTransactionRestriction( "{$dc}_class_attributes" ) . " LIMIT 1" );
 409+
410410 return $dbr->numRows( $queryResult ) > 0;
411411 }
412412
@@ -417,10 +417,10 @@
418418 if ( $objectId == 0 )
419419 $objectId = newObjectId( "{$dc}_class_attributes" );
420420
421 - $dbr = wfGetDB( DB_MASTER );
 421+ $dbw = wfGetDB( DB_MASTER );
422422 $sql = "INSERT INTO {$dc}_class_attributes(object_id, class_mid, level_mid, attribute_mid, attribute_type, add_transaction_id) " .
423 - " VALUES ($objectId, $classMeaningId, $levelMeaningId, $attributeMeaningId, " . $dbr->addQuotes( $attributeType ) . ', ' . getUpdateTransactionId() . ')';
424 - $dbr->query( $sql );
 423+ " VALUES ($objectId, $classMeaningId, $levelMeaningId, $attributeMeaningId, " . $dbw->addQuotes( $attributeType ) . ', ' . getUpdateTransactionId() . ')';
 424+ $dbw->query( $sql );
425425 }
426426
427427 function getClassAttributeId( $classMeaningId, $levelMeaningId, $attributeMeaningId, $attributeType ) {
@@ -437,8 +437,8 @@
438438
439439 function removeClassAttributeWithId( $classAttributeId ) {
440440 $dc = wdGetDataSetContext();
441 - $dbr = wfGetDB( DB_MASTER );
442 - $dbr->query( "UPDATE {$dc}_class_attributes SET remove_transaction_id=" . getUpdateTransactionId() .
 441+ $dbw = wfGetDB( DB_MASTER );
 442+ $dbw->query( "UPDATE {$dc}_class_attributes SET remove_transaction_id=" . getUpdateTransactionId() .
443443 " WHERE object_id=$classAttributeId " .
444444 " AND remove_transaction_id IS NULL" );
445445 }
@@ -462,10 +462,10 @@
463463 if ( $classMembershipId == 0 )
464464 $classMembershipId = newObjectId( "{$dc}_class_membership" );
465465
466 - $dbr = wfGetDB( DB_MASTER );
 466+ $dbw = wfGetDB( DB_MASTER );
467467 $sql = "INSERT INTO {$dc}_class_membership(class_membership_id, class_mid, class_member_mid, add_transaction_id) " .
468468 "VALUES ($classMembershipId, $classId, $classMemberId, " . getUpdateTransactionId() . ")";
469 - $dbr->query( $sql );
 469+ $dbw->query( $sql );
470470 }
471471
472472 function classMembershipExists( $classMemberId, $classId ) {
@@ -473,7 +473,7 @@
474474 $dbr = wfGetDB( DB_SLAVE );
475475 $queryResult = $dbr->query( "SELECT class_member_mid FROM {$dc}_class_membership " .
476476 "WHERE class_mid=$classId AND class_member_mid=$classMemberId " .
477 - "AND " . getLatestTransactionRestriction( "{$dc}_class_membership" ) );
 477+ "AND " . getLatestTransactionRestriction( "{$dc}_class_membership" ) . " LIMIT 1" );
478478
479479 return $dbr->numRows( $queryResult ) > 0;
480480 }
@@ -485,8 +485,8 @@
486486
487487 function removeClassMembership( $classMemberId, $classId ) {
488488 $dc = wdGetDataSetContext();
489 - $dbr = wfGetDB( DB_MASTER );
490 - $dbr->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() .
 489+ $dbw = wfGetDB( DB_MASTER );
 490+ $dbw->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() .
491491 " WHERE class_mid=$classId AND class_member_mid=$classMemberId " .
492492 " AND remove_transaction_id IS NULL" );
493493 }
@@ -494,23 +494,23 @@
495495 function removeClassMembershipWithId( $classMembershipId ) {
496496 $dc = wdGetDataSetContext();
497497
498 - $dbr = wfGetDB( DB_MASTER );
499 - $dbr->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() .
 498+ $dbw = wfGetDB( DB_MASTER );
 499+ $dbw->query( "UPDATE {$dc}_class_membership SET remove_transaction_id=" . getUpdateTransactionId() .
500500 " WHERE class_membership_id=$classMembershipId" .
501501 " AND remove_transaction_id IS NULL" );
502502 }
503503
504504 function removeSynonymOrTranslation( $definedMeaningId, $expressionId ) {
505505 $dc = wdGetDataSetContext();
506 - $dbr = wfGetDB( DB_MASTER );
507 - $dbr->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() .
 506+ $dbw = wfGetDB( DB_MASTER );
 507+ $dbw->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() .
508508 " WHERE defined_meaning_id=$definedMeaningId AND expression_id=$expressionId AND remove_transaction_id IS NULL LIMIT 1" );
509509 }
510510
511511 function removeSynonymOrTranslationWithId( $syntransId ) {
512512 $dc = wdGetDataSetContext();
513 - $dbr = wfGetDB( DB_MASTER );
514 - $dbr->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() .
 513+ $dbw = wfGetDB( DB_MASTER );
 514+ $dbw->query( "UPDATE {$dc}_syntrans SET remove_transaction_id=" . getUpdateTransactionId() .
515515 " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" );
516516 }
517517
@@ -524,7 +524,7 @@
525525 $dbr = wfGetDB( DB_SLAVE );
526526 $queryResult = $dbr->query( "SELECT defined_meaning_id, expression_id" .
527527 " FROM {$dc}_syntrans" .
528 - " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL" );
 528+ " WHERE syntrans_sid=$syntransId AND remove_transaction_id IS NULL LIMIT 1" );
529529
530530 if ( $syntrans = $dbr->fetchObject( $queryResult ) )
531531 updateSynonymOrTranslation( $syntrans->defined_meaning_id, $syntrans->expression_id, $identicalMeaning );
@@ -553,22 +553,22 @@
554554
555555 function createText( $text ) {
556556 $dc = wdGetDataSetContext();
557 - $dbr = wfGetDB( DB_MASTER );
558 - $text = $dbr->addQuotes( $text );
 557+ $dbw = wfGetDB( DB_MASTER );
 558+ $text = $dbw->addQuotes( $text );
559559 $sql = "insert into {$dc}_text(text_text) values($text)";
560 - $dbr->query( $sql );
 560+ $dbw->query( $sql );
561561
562 - return $dbr->insertId();
 562+ return $dbw->insertId();
563563 }
564564
565565 function createTranslatedContent( $translatedContentId, $languageId, $textId ) {
566566 $dc = wdGetDataSetContext();
567567
568 - $dbr = wfGetDB( DB_MASTER );
 568+ $dbw = wfGetDB( DB_MASTER );
569569 $sql = "insert into {$dc}_translated_content(translated_content_id,language_id,text_id,add_transaction_id) values($translatedContentId, $languageId, $textId, " . getUpdateTransactionId() . ")";
570 - $dbr->query( $sql );
 570+ $dbw->query( $sql );
571571
572 - return $dbr->insertId();
 572+ return $dbw->insertId();
573573 }
574574
575575 function translatedTextExists( $textId, $languageId ) {
@@ -585,7 +585,7 @@
586586 " FROM {$dc}_translated_content" .
587587 " WHERE translated_content_id=$textId" .
588588 " AND language_id=$languageId" .
589 - " AND " . getLatestTransactionRestriction( "{$dc}_translated_content" )
 589+ " AND " . getLatestTransactionRestriction( "{$dc}_translated_content" ) . " LIMIT 1"
590590 );
591591
592592 return $dbr->numRows( $queryResult ) > 0;
@@ -605,15 +605,15 @@
606606 $dc = wdGetDataSetContext();
607607 $dbr = wfGetDB( DB_SLAVE );
608608 $queryResult = $dbr->query( "SELECT meaning_text_tcid FROM {$dc}_defined_meaning WHERE defined_meaning_id=$definedMeaningId " .
609 - " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) );
 609+ " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) . " LIMIT 1" );
610610
611611 return $dbr->fetchObject( $queryResult )->meaning_text_tcid;
612612 }
613613
614614 function updateDefinedMeaningDefinitionId( $definedMeaningId, $definitionId ) {
615 - $dbr = wfGetDB( DB_MASTER );
 615+ $dbw = wfGetDB( DB_MASTER );
616616 $dc = wdGetDataSetContext();
617 - $dbr->query( "UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" .
 617+ $dbw->query( "UPDATE {$dc}_defined_meaning SET meaning_text_tcid=$definitionId WHERE defined_meaning_id=$definedMeaningId" .
618618 " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) );
619619 }
620620
@@ -639,8 +639,8 @@
640640
641641 function createDefinedMeaningAlternativeDefinition( $definedMeaningId, $translatedContentId, $sourceMeaningId ) {
642642 $dc = wdGetDataSetContext();
643 - $dbr = wfGetDB( DB_MASTER );
644 - $dbr->query( "INSERT INTO {$dc}_alt_meaningtexts (meaning_mid, meaning_text_tcid, source_id, add_transaction_id) " .
 643+ $dbw = wfGetDB( DB_MASTER );
 644+ $dbw->query( "INSERT INTO {$dc}_alt_meaningtexts (meaning_mid, meaning_text_tcid, source_id, add_transaction_id) " .
645645 "VALUES ($definedMeaningId, $translatedContentId, $sourceMeaningId, " . getUpdateTransactionId() . ")" );
646646 }
647647
@@ -653,15 +653,15 @@
654654
655655 function removeTranslatedText( $translatedContentId, $languageId ) {
656656 $dc = wdGetDataSetContext();
657 - $dbr = wfGetDB( DB_MASTER );
658 - $dbr->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() .
 657+ $dbw = wfGetDB( DB_MASTER );
 658+ $dbw->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() .
659659 " WHERE translated_content_id=$translatedContentId AND language_id=$languageId AND remove_transaction_id IS NULL" );
660660 }
661661
662662 function removeTranslatedTexts( $translatedContentId ) {
663663 $dc = wdGetDataSetContext();
664 - $dbr = wfGetDB( DB_MASTER );
665 - $dbr->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() .
 664+ $dbw = wfGetDB( DB_MASTER );
 665+ $dbw->query( "UPDATE {$dc}_translated_content SET remove_transaction_id=" . getUpdateTransactionId() .
666666 " WHERE translated_content_id=$translatedContentId AND remove_transaction_id IS NULL" );
667667 }
668668
@@ -674,8 +674,8 @@
675675 // removeTranslatedTexts($definitionId);
676676
677677 $dc = wdGetDataSetContext();
678 - $dbr = wfGetDB( DB_MASTER );
679 - $dbr->query( "UPDATE {$dc}_alt_meaningtexts SET remove_transaction_id=" . getUpdateTransactionId() .
 678+ $dbw = wfGetDB( DB_MASTER );
 679+ $dbw->query( "UPDATE {$dc}_alt_meaningtexts SET remove_transaction_id=" . getUpdateTransactionId() .
680680 " WHERE meaning_text_tcid=$definitionId AND meaning_mid=$definedMeaningId" .
681681 " AND remove_transaction_id IS NULL" );
682682 }
@@ -691,16 +691,16 @@
692692 $dc = wdGetDataSetContext();
693693 $dbr = wfGetDB( DB_SLAVE );
694694 $queryResult = $dbr->query( "SELECT collection_id FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND member_mid=$definedMeaningId " .
695 - "AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) );
 695+ "AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " LIMIT 1" );
696696
697697 return $dbr->numRows( $queryResult ) > 0;
698698 }
699699
700700 function addDefinedMeaningToCollection( $definedMeaningId, $collectionId, $internalId ) {
701701 $dc = wdGetDataSetContext();
702 - $dbr = wfGetDB( DB_MASTER );
703 - $dbr->query( "INSERT INTO {$dc}_collection_contents(collection_id, member_mid, internal_member_id, add_transaction_id) " .
704 - "VALUES ($collectionId, $definedMeaningId, " . $dbr->addQuotes( $internalId ) . ", " . getUpdateTransactionId() . ")" );
 702+ $dbw = wfGetDB( DB_MASTER );
 703+ $dbw->query( "INSERT INTO {$dc}_collection_contents(collection_id, member_mid, internal_member_id, add_transaction_id) " .
 704+ "VALUES ($collectionId, $definedMeaningId, " . $dbw->addQuotes( $internalId ) . ", " . getUpdateTransactionId() . ")" );
705705 }
706706
707707 function addDefinedMeaningToCollectionIfNotPresent( $definedMeaningId, $collectionId, $internalId ) {
@@ -711,7 +711,7 @@
712712 function getDefinedMeaningFromCollection( $collectionId, $internalMemberId ) {
713713 $dc = wdGetDataSetContext();
714714 $dbr = wfGetDB( DB_SLAVE );
715 - $query = "SELECT member_mid FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND internal_member_id=" . $dbr->addQuotes( $internalMemberId ) . " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" );
 715+ $query = "SELECT member_mid FROM {$dc}_collection_contents WHERE collection_id=$collectionId AND internal_member_id=" . $dbr->addQuotes( $internalMemberId ) . " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " LIMIT 1" ;
716716 $queryResult = $dbr->query( $query );
717717
718718 if ( $definedMeaningObject = $dbr->fetchObject( $queryResult ) )
@@ -722,8 +722,8 @@
723723
724724 function removeDefinedMeaningFromCollection( $definedMeaningId, $collectionId ) {
725725 $dc = wdGetDataSetContext();
726 - $dbr = wfGetDB( DB_MASTER );
727 - $dbr->query( "UPDATE {$dc}_collection_contents SET remove_transaction_id=" . getUpdateTransactionId() .
 726+ $dbw = wfGetDB( DB_MASTER );
 727+ $dbw->query( "UPDATE {$dc}_collection_contents SET remove_transaction_id=" . getUpdateTransactionId() .
728728 " WHERE collection_id=$collectionId AND member_mid=$definedMeaningId AND remove_transaction_id IS NULL" );
729729 }
730730
@@ -744,7 +744,7 @@
745745 $dc = wdGetDataSetContext();
746746 $dbr = wfGetDB( DB_SLAVE );
747747 $queryResult = $dbr->query( "SELECT collection_mid FROM {$dc}_collection " .
748 - " WHERE collection_id=$collectionId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) );
 748+ " WHERE collection_id=$collectionId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . " LIMIT 1" );
749749
750750 return $dbr->fetchObject( $queryResult )->collection_mid;
751751 }
@@ -753,7 +753,7 @@
754754 $dc = wdGetDataSetContext();
755755 $dbr = wfGetDB( DB_SLAVE );
756756 $queryResult = $dbr->query( "SELECT collection_id FROM {$dc}_collection " .
757 - " WHERE collection_mid=$collectionMeaningId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) );
 757+ " WHERE collection_mid=$collectionMeaningId AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . " LIMIT 1" );
758758
759759 return $dbr->fetchObject( $queryResult )->collection_id;
760760 }
@@ -762,28 +762,26 @@
763763 $dc = wdGetDataSetContext();
764764 $collectionId = newObjectId( "{$dc}_collection" );
765765
766 - $dbr = wfGetDB( DB_MASTER );
767 - $dbr->query( "INSERT INTO {$dc}_collection(collection_id, collection_mid, collection_type, add_transaction_id)" .
 766+ $dbw = wfGetDB( DB_MASTER );
 767+ $dbw->query( "INSERT INTO {$dc}_collection(collection_id, collection_mid, collection_type, add_transaction_id)" .
768768 " VALUES($collectionId, $definedMeaningId, '$collectionType', " . getUpdateTransactionId() . ")" );
769769
770770 return $collectionId;
771771 }
772772
773773 function addDefinedMeaning( $definingExpressionId ) {
774 - # FIXME: Replace with method for Namspace::getIndexForName.
775 - $definedMeaningNameSpaceId = 24;
776774 $dc = wdGetDataSetContext();
777775
778776 $definedMeaningId = newObjectId( "{$dc}_defined_meaning" );
779777
780778 // wfDebug( "addDefinedMeaning(): $definedMeaningId has to be inserted to the database $dc" );
781 - $dbr = wfGetDB( DB_MASTER );
782 - $dbr->query( "INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, " . getUpdateTransactionId() . ")" );
 779+ $dbw = wfGetDB( DB_MASTER );
 780+ $dbw->query( "INSERT INTO {$dc}_defined_meaning(defined_meaning_id, expression_id, add_transaction_id) values($definedMeaningId, $definingExpressionId, " . getUpdateTransactionId() . ")" );
783781
784782 // wfDebug( "addDefinedMeaning(): after $definedMeaningId has been inserted in the database" );
785783
786784 $expression = getExpression( $definingExpressionId );
787 - $pageId = createPage( $definedMeaningNameSpaceId, getPageTitle( "$expression->spelling ($definedMeaningId)" ) );
 785+ $pageId = createPage( NS_DEFINEDMEANING, getPageTitle( "$expression->spelling ($definedMeaningId)" ) );
788786 createInitialRevisionForPage( $pageId, 'Created by adding defined meaning' );
789787
790788 return $definedMeaningId;
@@ -807,17 +805,17 @@
808806
809807 function createTextAttributeValue( $textValueAttributeId, $objectId, $textAttributeId, $text ) {
810808 $dc = wdGetDataSetContext();
811 - $dbr = wfGetDB( DB_MASTER );
812 - $dbr->query(
 809+ $dbw = wfGetDB( DB_MASTER );
 810+ $dbw->query(
813811 "INSERT INTO {$dc}_text_attribute_values (value_id, object_id, attribute_mid, text, add_transaction_id) " .
814 - "VALUES ($textValueAttributeId, $objectId, $textAttributeId, " . $dbr->addQuotes( $text ) . ", " . getUpdateTransactionId() . ")"
 812+ "VALUES ($textValueAttributeId, $objectId, $textAttributeId, " . $dbw->addQuotes( $text ) . ", " . getUpdateTransactionId() . ")"
815813 );
816814 }
817815
818816 function removeTextAttributeValue( $textValueAttributeId ) {
819817 $dc = wdGetDataSetContext();
820 - $dbr = wfGetDB( DB_MASTER );
821 - $dbr->query( "UPDATE {$dc}_text_attribute_values SET remove_transaction_id=" . getUpdateTransactionId() .
 818+ $dbw = wfGetDB( DB_MASTER );
 819+ $dbw->query( "UPDATE {$dc}_text_attribute_values SET remove_transaction_id=" . getUpdateTransactionId() .
822820 " WHERE value_id=$textValueAttributeId" .
823821 " AND remove_transaction_id IS NULL" );
824822 }
@@ -835,7 +833,7 @@
836834 "SELECT object_id, attribute_mid, text" .
837835 " FROM {$dc}_text_attribute_values" .
838836 " WHERE value_id=$textValueAttributeId " .
839 - " AND " . getLatestTransactionRestriction( "{$dc}_text_attribute_values" )
 837+ " AND " . getLatestTransactionRestriction( "{$dc}_text_attribute_values" ) . " LIMIT 1"
840838 );
841839
842840 return $dbr->fetchObject( $queryResult );
@@ -849,17 +847,17 @@
850848
851849 function createLinkAttributeValue( $linkValueAttributeId, $objectId, $linkAttributeId, $url, $label = "" ) {
852850 $dc = wdGetDataSetContext();
853 - $dbr = wfGetDB( DB_MASTER );
854 - $dbr->query(
 851+ $dbw = wfGetDB( DB_MASTER );
 852+ $dbw->query(
855853 "INSERT INTO {$dc}_url_attribute_values (value_id, object_id, attribute_mid, url, label, add_transaction_id) " .
856 - "VALUES ($linkValueAttributeId, $objectId, $linkAttributeId, " . $dbr->addQuotes( $url ) . ", " . $dbr->addQuotes( $label ) . ", " . getUpdateTransactionId() . ")"
 854+ "VALUES ($linkValueAttributeId, $objectId, $linkAttributeId, " . $dbw->addQuotes( $url ) . ", " . $dbw->addQuotes( $label ) . ", " . getUpdateTransactionId() . ")"
857855 );
858856 }
859857
860858 function removeLinkAttributeValue( $linkValueAttributeId ) {
861859 $dc = wdGetDataSetContext();
862 - $dbr = wfGetDB( DB_MASTER );
863 - $dbr->query(
 860+ $dbw = wfGetDB( DB_MASTER );
 861+ $dbw->query(
864862 "UPDATE {$dc}_url_attribute_values SET remove_transaction_id=" . getUpdateTransactionId() .
865863 " WHERE value_id=$linkValueAttributeId" .
866864 " AND remove_transaction_id IS NULL"
@@ -878,7 +876,7 @@
879877 $queryResult = $dbr->query(
880878 "SELECT object_id, attribute_mid, url" .
881879 " FROM {$dc}_url_attribute_values WHERE value_id=$linkValueAttributeId " .
882 - " AND " . getLatestTransactionRestriction( "{$dc}_url_attribute_values" )
 880+ " AND " . getLatestTransactionRestriction( "{$dc}_url_attribute_values" ) . " LIMIT 1"
883881 );
884882
885883 return $dbr->fetchObject( $queryResult );
@@ -886,8 +884,8 @@
887885
888886 function createTranslatedTextAttributeValue( $valueId, $objectId, $attributeId, $translatedContentId ) {
889887 $dc = wdGetDataSetContext();
890 - $dbr = wfGetDB( DB_MASTER );
891 - $dbr->query( "INSERT INTO {$dc}_translated_content_attribute_values (value_id, object_id, attribute_mid, value_tcid, add_transaction_id) " .
 888+ $dbw = wfGetDB( DB_MASTER );
 889+ $dbw->query( "INSERT INTO {$dc}_translated_content_attribute_values (value_id, object_id, attribute_mid, value_tcid, add_transaction_id) " .
892890 "VALUES ($valueId, $objectId, $attributeId, $translatedContentId, " . getUpdateTransactionId() . ")" );
893891 }
894892
@@ -904,7 +902,7 @@
905903 $dc = wdGetDataSetContext();
906904 $dbr = wfGetDB( DB_SLAVE );
907905 $queryResult = $dbr->query( "SELECT value_id, object_id, attribute_mid, value_tcid FROM {$dc}_translated_content_attribute_values WHERE value_id=$valueId " .
908 - " AND " . getLatestTransactionRestriction( "{$dc}_translated_content_attribute_values" ) );
 906+ " AND " . getLatestTransactionRestriction( "{$dc}_translated_content_attribute_values" ) . " LIMIT 1" );
909907
910908 return $dbr->fetchObject( $queryResult );
911909 }
@@ -920,8 +918,8 @@
921919 // back easier.
922920 // removeTranslatedTexts($translatedTextAttribute->value_tcid);
923921
924 - $dbr = wfGetDB( DB_MASTER );
925 - $dbr->query(
 922+ $dbw = wfGetDB( DB_MASTER );
 923+ $dbw->query(
926924 "UPDATE {$dc}_translated_content_attribute_values" .
927925 " SET remove_transaction_id=" . getUpdateTransactionId() .
928926 " WHERE value_id=$valueId" .
@@ -935,7 +933,7 @@
936934 $queryResult = $dbr->query( "SELECT value_id FROM {$dc}_option_attribute_values" .
937935 ' WHERE object_id = ' . $objectId .
938936 ' AND option_id = ' . $optionId .
939 - ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_values" ) );
 937+ ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_values" ) . " LIMIT 1" );
940938 return $dbr->numRows( $queryResult ) > 0;
941939 }
942940
@@ -948,23 +946,23 @@
949947 $dc = wdGetDataSetContext();
950948 $valueId = newObjectId( "{$dc}_option_attribute_values" );
951949
952 - $dbr = wfGetDB( DB_MASTER );
 950+ $dbw = wfGetDB( DB_MASTER );
953951 $sql = "INSERT INTO {$dc}_option_attribute_values(value_id,object_id,option_id,add_transaction_id)" .
954952 ' VALUES(' . $valueId .
955953 ',' . $objectId .
956954 ',' . $optionId .
957955 ',' . getUpdateTransactionId() . ')';
958 - $dbr->query( $sql );
 956+ $dbw->query( $sql );
959957 }
960958
961959 function removeOptionAttributeValue( $valueId ) {
962960 $dc = wdGetDataSetContext();
963 - $dbr = wfGetDB( DB_MASTER );
 961+ $dbw = wfGetDB( DB_MASTER );
964962 $sql = "UPDATE {$dc}_option_attribute_values" .
965963 ' SET remove_transaction_id = ' . getUpdateTransactionId() .
966964 ' WHERE value_id = ' . $valueId .
967965 ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_values" );
968 - $dbr->query( $sql );
 966+ $dbw->query( $sql );
969967 }
970968
971969 function optionAttributeOptionExists( $attributeId, $optionMeaningId, $languageId ) {
@@ -974,7 +972,7 @@
975973 ' WHERE attribute_id = ' . $attributeId .
976974 ' AND option_mid = ' . $optionMeaningId .
977975 ' AND language_id = ' . $languageId .
978 - ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) );
 976+ ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" ) . " LIMIT 1" );
979977 return $dbr->numRows( $queryResult ) > 0;
980978 }
981979
@@ -987,27 +985,27 @@
988986 $dc = wdGetDataSetContext();
989987 $optionId = newObjectId( "{$dc}_option_attribute_options" );
990988
991 - $dbr = wfGetDB( DB_MASTER );
 989+ $dbw = wfGetDB( DB_MASTER );
992990 $sql = "INSERT INTO {$dc}_option_attribute_options(option_id,attribute_id,option_mid,language_id,add_transaction_id)" .
993991 ' VALUES(' . $optionId .
994992 ',' . $attributeId .
995993 ',' . $optionMeaningId .
996994 ',' . $languageId .
997995 ',' . getUpdateTransactionId() . ')';
998 - $dbr->query( $sql );
 996+ $dbw->query( $sql );
999997 }
1000998
1001999 function removeOptionAttributeOption( $optionId ) {
10021000 $dc = wdGetDataSetContext();
1003 - $dbr = wfGetDB( DB_MASTER );
 1001+ $dbw = wfGetDB( DB_MASTER );
10041002
10051003 // first check if the option attribute option is still in use
10061004 $sql = "SELECT * FROM {$dc}_option_attribute_values" .
10071005 ' WHERE option_id = ' . $optionId .
1008 - ' AND remove_transaction_id IS NULL' ;
1009 - $queryResult = $dbr->query( $sql );
 1006+ ' AND remove_transaction_id IS NULL LIMIT 1' ;
 1007+ $queryResult = $dbw->query( $sql );
10101008
1011 - if ( $dbr->numRows( $queryResult ) > 0 ) {
 1009+ if ( $dbw->numRows( $queryResult ) > 0 ) {
10121010 echo "\nThe option $optionId cannot be deleted because it is still in use!\n" ;
10131011 } else {
10141012 // option not used, can proceed to delete
@@ -1016,7 +1014,7 @@
10171015 ' SET remove_transaction_id = ' . $transactionId .
10181016 ' WHERE option_id = ' . $optionId .
10191017 ' AND ' . getLatestTransactionRestriction( "{$dc}_option_attribute_options" );
1020 - $dbr->query( $sql );
 1018+ $dbw->query( $sql );
10211019 }
10221020
10231021 // alternatively to checking if the attribute option is in use
@@ -1040,7 +1038,6 @@
10411039 function getDefinedMeaningDefinitionForLanguage( $definedMeaningId, $languageId, $dc = null ) {
10421040 if ( is_null( $dc ) ) {
10431041 $dc = wdGetDataSetContext();
1044 -
10451042 }
10461043 $dbr = wfGetDB( DB_SLAVE );
10471044 $queryResult = $dbr->query( "SELECT text_text FROM {$dc}_defined_meaning as dm, {$dc}_translated_content as tc, {$dc}_text as t " .
@@ -1048,7 +1045,7 @@
10491046 " AND " . getLatestTransactionRestriction( 'dm' ) .
10501047 " AND " . getLatestTransactionRestriction( 'tc' ) .
10511048 " AND dm.meaning_text_tcid=tc.translated_content_id AND tc.language_id=$languageId " .
1052 - " AND t.text_id=tc.text_id" );
 1049+ " AND t.text_id=tc.text_id LIMIT 1" );
10531050
10541051 if ( $definition = $dbr->fetchObject( $queryResult ) )
10551052 return $definition->text_text;
@@ -1115,17 +1112,17 @@
11161113
11171114 $definedMeaningId = $dbr->addQuotes( $definedMeaningId );
11181115 $userLanguageId = $dbr->addQuotes( $userLanguageId );
1119 - $fallbackLanguageId = $dbr->addQuotes( $fallbackLanguageId );
11201116
11211117 if ( $userLanguageId ) {
1122 - $actual_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$userLanguageId and {$dc}_expression.remove_transaction_id is NULL";
 1118+ $actual_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$userLanguageId and {$dc}_expression.remove_transaction_id is NULL LIMIT 1";
11231119
11241120 $res = $dbr->query( $actual_query );
11251121 $row = $dbr->fetchObject( $res );
11261122 if ( isset( $row->spelling ) ) return $row->spelling;
11271123 }
11281124
1129 - $fallback_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$fallbackLanguageId and {$dc}_expression.remove_transaction_id is NULL";
 1125+ $fallbackLanguageId = $dbr->addQuotes( $fallbackLanguageId );
 1126+ $fallback_query = "select spelling from {$dc}_syntrans,{$dc}_expression where {$dc}_syntrans.defined_meaning_id=$definedMeaningId and {$dc}_expression.expression_id={$dc}_syntrans.expression_id and language_id=$fallbackLanguageId and {$dc}_expression.remove_transaction_id is NULL LIMIT 1";
11301127
11311128 $res = $dbr->query( $fallback_query );
11321129 $row = $dbr->fetchObject( $res );
@@ -1153,7 +1150,7 @@
11541151 " FROM ({$dc}_collection_contents INNER JOIN {$dc}_collection ON {$dc}_collection.collection_id = {$dc}_collection_contents.collection_id) " .
11551152 " WHERE {$dc}_collection_contents.member_mid = $objectId AND {$dc}_collection.collection_type = 'CLAS' " .
11561153 " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " " .
1157 - " AND " . getLatestTransactionRestriction( "{$dc}_collection" );
 1154+ " AND " . getLatestTransactionRestriction( "{$dc}_collection" ) . " LIMIT 1" ;
11581155 $queryResult = $dbr->query( $query );
11591156
11601157 $result = $dbr->numRows( $queryResult ) > 0;
@@ -1178,9 +1175,8 @@
11791176 }
11801177
11811178 function getCollectionContents( $collectionId ) {
1182 - global
1183 - $dataSet;
1184 -
 1179+ global $dataSet;
 1180+
11851181 $dc = wdGetDataSetContext();
11861182 $dbr = & wfGetDB( DB_SLAVE );
11871183 $queryResult = $dbr->query(
@@ -1217,7 +1213,8 @@
12181214 while ( $row = $dbr->fetchRow( $result ) ) {
12191215 $memberMids[] = $row['member_mid'];
12201216 }
1221 -
 1217+ $dbr->freeResult( $result ) ;
 1218+
12221219 return $memberMids;
12231220 }
12241221
@@ -1229,7 +1226,7 @@
12301227 " FROM {$dc}_collection_contents " .
12311228 " WHERE collection_id=$collectionId" .
12321229 " AND internal_member_id=" . $dbr->addQuotes( $sourceIdentifier ) .
1233 - " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" )
 1230+ " AND " . getLatestTransactionRestriction( "{$dc}_collection_contents" ) . " LIMIT 1"
12341231 );
12351232
12361233 if ( $collectionEntry = $dbr->fetchObject( $queryResult ) )
@@ -1271,8 +1268,10 @@
12721269
12731270 $result = array();
12741271
1275 - while ( $synonymRecord = $dbr->fetchObject( $queryResult ) )
1276 - $result[] = $synonymRecord->defined_meaning_id;
 1272+ while ( $synonymRecord = $dbr->fetchObject( $queryResult ) ) {
 1273+ $result[] = $synonymRecord->defined_meaning_id;
 1274+ }
 1275+ $dbr->freeResult( $queryResult ) ;
12771276
12781277 return $result;
12791278 }
@@ -1298,6 +1297,7 @@
12991298 $result[] = $synonymRecord->defined_meaning_id;
13001299 }
13011300 }
 1301+ $dbr->freeResult( $queryResult ) ;
13021302
13031303 return $result;
13041304 }
@@ -1324,7 +1324,7 @@
13251325
13261326 function getMapping( $dc, $collid, $dm_id ) {
13271327 $dbr = wfGetDB( DB_SLAVE );
1328 - $queryResult = $dbr->query( "select internal_member_id from {$dc}_collection_contents where collection_id = $collid AND member_mid = $dm_id" );
 1328+ $queryResult = $dbr->query( "select internal_member_id from {$dc}_collection_contents where collection_id = $collid AND member_mid = $dm_id LIMIT 1" );
13291329 if ( $record = $dbr->fetchObject( $queryResult ) ) {
13301330 return $record->internal_member_id;
13311331 }
@@ -1371,7 +1371,7 @@
13721372 /** this funtion assumes that there is only a single mapping collection */
13731373
13741374 function getCollectionIdForDC( $dc ) {
1375 - $dbr = & wfGetDB( DB_SLAVE );
 1375+ $dbr = & wfGetDB( DB_SLAVE );
13761376 $query = "
13771377 SELECT collection_id FROM {$dc}_collection
13781378 WHERE collection_type=\"MAPP\"
@@ -1391,12 +1391,12 @@
13921392 // if(is_null($dc)) {
13931393 // $dc=wdGetDataSetContext();
13941394 // }
1395 - $dbr = & wfGetDB( DB_SLAVE );
 1395+ $dbw = & wfGetDB( DB_MASTER );
13961396
13971397 $collection_contents = "{$dc}_collection_contents";
1398 - $collid = $dbr->addQuotes( $collid );
1399 - $uuid = $dbr->addQuotes( $uuid );
1400 - $dm_id = $dbr->addQuotes( $dm_id );
 1398+ $collid = $dbw->addQuotes( $collid );
 1399+ $uuid = $dbw->addQuotes( $uuid );
 1400+ $dm_id = $dbw->addQuotes( $dm_id );
14011401
14021402 $add_transaction_id = $override_transaction;
14031403 if ( is_null( $add_transaction_id ) ) {
@@ -1411,7 +1411,7 @@
14121412 member_mid=$dm_id,
14131413 add_transaction_id=$add_transaction_id
14141414 ";
1415 - $result = $dbr->query( $sql );
 1415+ $result = $dbw->query( $sql );
14161416 }
14171417
14181418 /**read a ConceptMapping from the database.
@@ -1440,7 +1440,7 @@
14411441 $query = "
14421442 SELECT member_mid FROM $collection_contents
14431443 WHERE collection_id = $collection_id
1444 - AND internal_member_id=$concept_id
 1444+ AND internal_member_id=$concept_id LIMIT 1
14451445 ";
14461446 $queryResult = $dbr->query( $query );
14471447 $row = $dbr->fetchObject( $queryResult );
@@ -1462,7 +1462,7 @@
14631463 SELECT internal_member_id AS concept_id
14641464 FROM {$dc}_collection_contents
14651465 WHERE member_mid=$dm
1466 - AND collection_id=$collection_id;
 1466+ AND collection_id=$collection_id LIMIT 1
14671467 ";
14681468 $queryResult = $dbr->query( $query );
14691469 $row = $dbr->fetchObject( $queryResult );
@@ -1506,7 +1506,7 @@
15071507 " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
15081508 " AND {$dc}_expression.expression_id={$dc}_defined_meaning.expression_id" .
15091509 " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) .
1510 - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
 1510+ " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . " LIMIT 1" );
15111511 $expression = $dbr->fetchObject( $queryResult );
15121512 return array( $expression->expression_id, $expression->spelling, $expression->language_id );
15131513 }
@@ -1521,7 +1521,7 @@
15221522 " WHERE {$dc}_defined_meaning.defined_meaning_id=$definedMeaningId " .
15231523 " AND {$dc}_expression.expression_id={$dc}_defined_meaning.expression_id" .
15241524 " AND " . getLatestTransactionRestriction( "{$dc}_defined_meaning" ) .
1525 - " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
 1525+ " AND " . getLatestTransactionRestriction( "{$dc}_expression" ) . " LIMIT 1" );
15261526 $expression = $dbr->fetchObject( $queryResult );
15271527 if ( $expression ) {
15281528 return $expression->spelling;
@@ -1616,7 +1616,7 @@
16171617 function getTextValue( $textId ) {
16181618 $dc = wdGetDataSetContext();
16191619 $dbr = wfGetDB( DB_SLAVE );
1620 - $queryResult = $dbr->query( "SELECT text_text from {$dc}_text where text_id=$textId" );
 1620+ $queryResult = $dbr->query( "SELECT text_text from {$dc}_text where text_id=$textId LIMIT 1" );
16211621
16221622 return $dbr->fetchObject( $queryResult )->text_text;
16231623 }
@@ -1628,12 +1628,13 @@
16291629 $dbr = wfGetDB( DB_SLAVE );
16301630
16311631 $spelling = $dbr->addQuotes( $spelling );
1632 - $queryResult = $dbr->query( "SELECT * FROM {$dc}_expression WHERE {$dc}_expression.spelling=$spelling AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
 1632+ $queryResult = $dbr->query( "SELECT * FROM {$dc}_expression WHERE spelling=$spelling AND " . getLatestTransactionRestriction( "{$dc}_expression" ) );
16331633
16341634 $rv = array();
16351635 while ( $expressionRecord = $dbr->fetchObject( $queryResult ) ) {
16361636 $rv[] = new Expression( $expressionRecord->expression_id, $expressionRecord->spelling, $expressionRecord->language_id );
16371637 }
 1638+ $dbr->freeResult( $queryResult ) ;
16381639 return $rv;
16391640
16401641 }
@@ -1672,7 +1673,7 @@
16731674 $qry .= 'AND ' . getLatestTransactionRestriction( 'trans' );
16741675 $qry .= 'AND ' . getLatestTransactionRestriction( 'dm' );
16751676
1676 -
 1677+
16771678 $definitions = $dbr->query( $qry );
16781679 while ( $row = $dbr->fetchRow( $definitions ) ) {
16791680 // $key becomes something like def_23

Status & tagging log