Skip to content

Commit 36a19c3

Browse files
author
Daniel Kinzler
committed
fix gpPageSet.strip
git-svn-id: https://svn.toolserver.org/svnroot/daniel/duesenstuff/trunk/gpClient@544 9f2c43bc-b3c0-43f4-b155-41619b16f219
1 parent 424b97b commit 36a19c3

File tree

2 files changed

+17
-53
lines changed

2 files changed

+17
-53
lines changed

php/gpMediaWiki.php

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public static function new_slave_connection( $command, $cwd = null, $env = null
176176
return new gpMediaWikiGlue( new gpSlaveTransport($command, $cwd, $env) );
177177
}
178178

179-
public function condition_sql( $where, $assume_literals = true ) {
179+
public function condition_sql( $where, $assume_literals = true, $inverse = false ) {
180180
if ( is_array($where) ) {
181181
if ( isset( $where[0] ) ) { #indexed array
182182
$where = '(' . implode(') AND (', $where) . ')';
@@ -188,9 +188,9 @@ public function condition_sql( $where, $assume_literals = true ) {
188188
$where .= '(';
189189
$where .= $k;
190190

191-
if ( is_array($v) ) $where .= ( $inverse ? " not in " : " in " ) . $this->glue->as_list( $v );
191+
if ( is_array($v) ) $where .= ( $inverse ? " not in " : " in " ) . $this->as_list( $v );
192192
elseif ( is_string($v) && !$assume_literals ) $where .= ( $inverse ? " != " : " = " ) . $v; # field reference or quoted literal
193-
else $where .= ( $inverse ? " != " : " = " ) . $this->glue->as_literal( $v );
193+
else $where .= ( $inverse ? " != " : " = " ) . $this->as_literal( $v );
194194

195195
$where .= ')';
196196
}
@@ -240,26 +240,13 @@ public function get_table() {
240240
}
241241

242242
public function create_table( ) {
243-
$table = $this->table;
244-
$t = "";
245-
246-
if ( !$table || $table === '?' ) {
247-
$table = "gp_temp_" . $this->glue->next_id();
248-
$t = " TEMPORARY ";
249-
}
250-
251-
$sql = "CREATE $t TABLE " . $table;
252-
$sql .= "(";
253-
$sql .= $this->table_obj->get_field_definitions();
254-
$sql .= ")";
255-
256-
$this->query($sql);
257-
258-
$this->table = $table;
259-
$this->table_obj->set_name( $this->table );
260-
$this->table_id_obj->set_name( $this->table );
243+
#TODO: port this solution using make_temp_table to python!
244+
$this->table_obj = $this->glue->make_temp_table( $this->table_obj );
261245

262-
return $table;
246+
$this->table = $this->table_obj->get_name();
247+
$this->table_id_obj->set_name( $this->table );
248+
249+
return $this->table;
263250

264251
}
265252

@@ -447,7 +434,7 @@ public function remove_page_id( $id ) {
447434
}
448435

449436
public function strip_namespace( $ns, $inverse = false ) {
450-
$where = $this->namespace_field . ' = ' . (int)$ns;
437+
$where = array( $this->namespace_field => $ns );
451438
return $this->strip( $where, null, $inverse );
452439
}
453440

@@ -502,7 +489,7 @@ public function retian_larger( $size ) { #TODO: port to python!
502489
}
503490

504491
public function strip( $where, $join = null, $inverse = false ) { #TODO: port to python!
505-
if ( $where ) $where = $this->glue->condition_sql($where);
492+
if ( $where ) $where = $this->glue->condition_sql($where, true, $inverse);
506493

507494
if ( is_array($join) ) {
508495
if ( isset( $join[0] ) ) { #indexed array
@@ -521,8 +508,8 @@ public function strip( $where, $join = null, $inverse = false ) { #TODO: port to
521508
}
522509

523510
if ( $join ) {
524-
$sql = 'DELETE FROM TTT ';
525-
$sql .= ' USING ' . $this->table . ' AS TTT ';
511+
$sql = 'DELETE FROM T ';
512+
$sql .= ' USING ' . $this->table . ' AS T ';
526513
$sql .= $join;
527514
} else {
528515
$sql = 'DELETE FROM ' . $this->table;

php/test/gpMediaWiki.test.php

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public function testAddPageSet() {
378378
$cheese->dispose();
379379
}
380380

381-
public function testDeleteWhere() {
381+
public function testStrip() {
382382
$this->makeWikiStructure();
383383
$this->gp->add_arcs_from_category_structure();
384384

@@ -388,7 +388,7 @@ public function testDeleteWhere() {
388388
$set->add_pages_in("topics", null, 5);
389389

390390
//-----------------------------------------------------------
391-
$set->delete_where( "where page_namespace = " . NS_CATEGORY );
391+
$set->strip( "page_namespace = " . NS_CATEGORY );
392392

393393
$a = $set->capture();
394394
$expected = array(array(1111, NS_MAIN, "Lager"),
@@ -397,35 +397,12 @@ public function testDeleteWhere() {
397397

398398
$this->assertEquals($expected, $a );
399399

400+
#TODO: test joins
401+
#TODO: test $where and $join as array, both indexed and assoc
400402
//-----------------------------------------------------------
401403
$set->dispose();
402404
}
403405

404-
public function testDeleteUsing() {
405-
$this->makeWikiStructure();
406-
$this->gp->add_arcs_from_category_structure();
407-
408-
$set = new gpPageSet($this->gp);
409-
$set->create_table();
410-
411-
$set->add_pages_in("topics", null, 5);
412-
413-
//-----------------------------------------------------------
414-
$sql = " JOIN " . $this->gp->wiki_table("templatelinks") . " as X ";
415-
$sql .= " ON T.page_id = X.tl_from ";
416-
$sql .= " WHERE X.tl_namespace = " . NS_TEMPLATE;
417-
$sql .= " AND X.tl_title = " . $this->gp->quote_string("Yuck");
418-
419-
$set->delete_using( $sql );
420-
421-
$a = $set->capture(NS_MAIN);
422-
$expected = array(array(1112, NS_MAIN, "Pils"));
423-
424-
$this->assertEquals($expected, $a );
425-
426-
//-----------------------------------------------------------
427-
$set->dispose();
428-
}
429406

430407
public function testStripNamespace() {
431408
$this->makeWikiStructure();

0 commit comments

Comments
 (0)