Browse Source

Rename Result->get() to Result->getRow

It should be slightly clearer what it does
microsub
J. King 7 years ago
parent
commit
485400df2b
  1. 6
      lib/Database.php
  2. 2
      lib/Db/Result.php
  3. 2
      lib/Db/SQLite3/Result.php
  4. 6
      tests/Db/SQLite3/TestDbResultSQLite3.php
  5. 6
      tests/Db/SQLite3/TestDbStatementSQLite3.php

6
lib/Database.php

@ -52,7 +52,7 @@ class Database {
}
public function settingGet(string $key) {
$row = $this->db->prepare("SELECT value, type from newssync_settings where key = ?", "str")->run($key)->get();
$row = $this->db->prepare("SELECT value, type from newssync_settings where key = ?", "str")->run($key)->getRow();
if(!$row) return null;
switch($row['type']) {
case "int": return (int) $row['value'];
@ -218,7 +218,7 @@ class Database {
public function userPropertiesGet(string $user): array {
if(!$this->data->user->authorize($user, __FUNCTION__)) throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
$prop = $this->db->prepare("SELECT name,rights from newssync_users where id is ?", "str")->run($user)->get();
$prop = $this->db->prepare("SELECT name,rights from newssync_users where id is ?", "str")->run($user)->getRow();
if(!$prop) return [];
return $prop;
}
@ -340,7 +340,7 @@ class Database {
$root = null;
} else {
// if a parent is specified, make sure it exists and belongs to the user; get its root (first-level) folder if it's a nested folder
$p = $this->db->prepare("SELECT id,root from newssync_folders where owner is ? and id is ?", "str", "int")->run($user, $parent)->get();
$p = $this->db->prepare("SELECT id,root from newssync_folders where owner is ? and id is ?", "str", "int")->run($user, $parent)->getRow();
if($p===null) {
throw new Db\ExceptionInput("idMissing", ["action" => __FUNCTION__, "field" => "parent", 'id' => $parent]);
} else {

2
lib/Db/Result.php

@ -9,7 +9,7 @@ interface Result extends \Iterator {
function rewind();
function valid();
function get();
function getRow();
function getAll();
function getValue();

2
lib/Db/SQLite3/Result.php

@ -21,7 +21,7 @@ class Result implements \JKingWeb\NewsSync\Db\Result {
return null;
}
public function get() {
public function getRow() {
$this->next();
return ($this->valid() ? $this->cur : null);
}

6
tests/Db/SQLite3/TestDbResultSQLite3.php

@ -81,9 +81,9 @@ class TestDbResultSQLite3 extends \PHPUnit\Framework\TestCase {
['album' => 'Clockwork Angels', 'track' => 'The Wreckers'],
];
$test = new Db\SQLite3\Result($set);
$this->assertEquals($rows[0], $test->get());
$this->assertEquals($rows[1], $test->get());
$this->assertSame(null, $test->get());
$this->assertEquals($rows[0], $test->getRow());
$this->assertEquals($rows[1], $test->getRow());
$this->assertSame(null, $test->getRow());
$this->assertEquals($rows, $test->getAll());
}
}

6
tests/Db/SQLite3/TestDbStatementSQLite3.php

@ -29,7 +29,7 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase {
$types = array_unique(Statement::TYPES);
foreach($types as $type) {
$s->rebindArray([$type]);
$val = $s->runArray([$input])->get()['value'];
$val = $s->runArray([$input])->getRow()['value'];
$this->assertSame($expectations[$type], $val, "Type $type failed comparison.");
}
}
@ -42,7 +42,7 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase {
function testBindMissingValue() {
$nativeStatement = $this->c->prepare("SELECT ? as value");
$s = new self::$imp($this->c, $nativeStatement);
$val = $s->runArray()->get()['value'];
$val = $s->runArray()->getRow()['value'];
$this->assertSame(null, $val);
}
@ -53,7 +53,7 @@ class TestDbStatementSQLite3 extends \PHPUnit\Framework\TestCase {
];
$nativeStatement = $this->c->prepare("SELECT ? as one, ? as two");
$s = new self::$imp($this->c, $nativeStatement, ["int", "int"]);
$val = $s->runArray([1,2])->get();
$val = $s->runArray([1,2])->getRow();
$this->assertSame($exp, $val);
}

Loading…
Cancel
Save