Browse Source

Change "rebind" to "retype" to better reflect what actually happens

microsub
J. King 6 years ago
parent
commit
bc9fcb975f
  1. 8
      lib/Db/AbstractStatement.php
  2. 2
      lib/Db/PDOStatement.php
  3. 2
      lib/Db/SQLite3/Statement.php
  4. 4
      lib/Db/Statement.php
  5. 6
      tests/cases/Db/SQLite3/TestStatement.php
  6. 6
      tests/cases/Db/SQLite3PDO/TestStatement.php

8
lib/Db/AbstractStatement.php

@ -18,18 +18,18 @@ abstract class AbstractStatement implements Statement {
return $this->runArray($values);
}
public function rebind(...$bindings): bool {
return $this->rebindArray($bindings);
public function retype(...$bindings): bool {
return $this->retypeArray($bindings);
}
public function rebindArray(array $bindings, bool $append = false): bool {
public function retypeArray(array $bindings, bool $append = false): bool {
if (!$append) {
$this->types = [];
}
foreach ($bindings as $binding) {
if (is_array($binding)) {
// recursively flatten any arrays, which may be provided for SET or IN() clauses
$this->rebindArray($binding, true);
$this->retypeArray($binding, true);
} else {
$binding = trim(strtolower($binding));
if (strpos($binding, "strict ")===0) {

2
lib/Db/PDOStatement.php

@ -24,7 +24,7 @@ class PDOStatement extends AbstractStatement {
public function __construct(\PDO $db, \PDOStatement $st, array $bindings = []) {
$this->db = $db;
$this->st = $st;
$this->rebindArray($bindings);
$this->retypeArray($bindings);
}
public function __destruct() {

2
lib/Db/SQLite3/Statement.php

@ -31,7 +31,7 @@ class Statement extends \JKingWeb\Arsse\Db\AbstractStatement {
public function __construct(\SQLite3 $db, \SQLite3Stmt $st, array $bindings = []) {
$this->db = $db;
$this->st = $st;
$this->rebindArray($bindings);
$this->retypeArray($bindings);
}
public function __destruct() {

4
lib/Db/Statement.php

@ -29,6 +29,6 @@ interface Statement {
public function run(...$values): Result;
public function runArray(array $values = []): Result;
public function rebind(...$bindings): bool;
public function rebindArray(array $bindings): bool;
public function retype(...$bindings): bool;
public function retypeArray(array $bindings): bool;
}

6
tests/cases/Db/SQLite3/TestStatement.php

@ -35,10 +35,10 @@ class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
$s = new self::$imp($this->c, $nativeStatement);
$types = array_unique(Statement::TYPES);
foreach ($types as $type) {
$s->rebindArray([$strict ? "strict $type" : $type]);
$s->retypeArray([$strict ? "strict $type" : $type]);
$val = $s->runArray([$input])->getRow()['value'];
$this->assertSame($expectations[$type], $val, "Binding from type $type failed comparison.");
$s->rebind(...[$strict ? "strict $type" : $type]);
$s->retype(...[$strict ? "strict $type" : $type]);
$val = $s->run(...[$input])->getRow()['value'];
$this->assertSame($expectations[$type], $val, "Binding from type $type failed comparison.");
}
@ -56,7 +56,7 @@ class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
) as pass"
);
$s = new self::$imp($this->c, $nativeStatement);
$s->rebindArray([$type, $type]);
$s->retypeArray([$type, $type]);
$act = (bool) $s->run(...[$value, $value])->getRow()['pass'];
$this->assertTrue($act);
}

6
tests/cases/Db/SQLite3PDO/TestStatement.php

@ -36,10 +36,10 @@ class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
$s = new self::$imp($this->c, $nativeStatement);
$types = array_unique(Statement::TYPES);
foreach ($types as $type) {
$s->rebindArray([$strict ? "strict $type" : $type]);
$s->retypeArray([$strict ? "strict $type" : $type]);
$val = $s->runArray([$input])->getRow()['value'];
$this->assertSame($expectations[$type], $val, "Binding from type $type failed comparison.");
$s->rebind(...[$strict ? "strict $type" : $type]);
$s->retype(...[$strict ? "strict $type" : $type]);
$val = $s->run(...[$input])->getRow()['value'];
$this->assertSame($expectations[$type], $val, "Binding from type $type failed comparison.");
}
@ -57,7 +57,7 @@ class TestStatement extends \JKingWeb\Arsse\Test\AbstractTest {
) as pass"
);
$s = new self::$imp($this->c, $nativeStatement);
$s->rebind(...[$type, $type]);
$s->retype(...[$type, $type]);
$act = (bool) $s->run(...[$value, $value])->getRow()['pass'];
$this->assertTrue($act);
}

Loading…
Cancel
Save