diff --git a/db.class.php b/db.class.php index 0f2a0fd..07c9cf4 100644 --- a/db.class.php +++ b/db.class.php @@ -1072,56 +1072,6 @@ class MeekroDBException extends Exception { public function getQuery() { return $this->query; } } -class DBHelper { - /* - verticalSlice - 1. For an array of assoc rays, return an array of values for a particular key - 2. if $keyfield is given, same as above but use that hash key as the key in new array - */ - - public static function verticalSlice($array, $field, $keyfield = null) { - $array = (array) $array; - - $R = array(); - foreach ($array as $obj) { - if (! array_key_exists($field, $obj)) die("verticalSlice: array doesn't have requested field\n"); - - if ($keyfield) { - if (! array_key_exists($keyfield, $obj)) die("verticalSlice: array doesn't have requested field\n"); - $R[$obj[$keyfield]] = $obj[$field]; - } else { - $R[] = $obj[$field]; - } - } - return $R; - } - - /* - reIndex - For an array of assoc rays, return a new array of assoc rays using a certain field for keys - */ - - public static function reIndex() { - $fields = func_get_args(); - $array = array_shift($fields); - $array = (array) $array; - - $R = array(); - foreach ($array as $obj) { - $target =& $R; - - foreach ($fields as $field) { - if (! array_key_exists($field, $obj)) die("reIndex: array doesn't have requested field\n"); - - $nextkey = $obj[$field]; - $target =& $target[$nextkey]; - } - $target = $obj; - } - return $R; - } -} - class MeekroDBEval { public $text = ''; diff --git a/simpletest/HelperTest.php b/simpletest/HelperTest.php deleted file mode 100644 index 496c406..0000000 --- a/simpletest/HelperTest.php +++ /dev/null @@ -1,51 +0,0 @@ -assert(count($names) === 5); - $this->assert($names[0] === 'Abe'); - - $ages = DBHelper::verticalSlice($all, 'age', 'username'); - $this->assert(count($ages) === 5); - $this->assert($ages['Abe'] === '700'); - } - - function test_2_reindex() { - $all = DB::query("SELECT * FROM accounts ORDER BY id ASC"); - $names = DBHelper::reIndex($all, 'username'); - $this->assert(count($names) === 5); - $this->assert($names['Bart']['username'] === 'Bart'); - $this->assert($names['Bart']['age'] === '15'); - - $names = DBHelper::reIndex($all, 'username', 'age'); - $this->assert($names['Bart']['15']['username'] === 'Bart'); - $this->assert($names['Bart']['15']['age'] === '15'); - } - - function test_3_empty() { - $none = DB::query("SELECT * FROM accounts WHERE username=%s", 'doesnotexist'); - $this->assert(is_array($none) && count($none) === 0); - $names = DBHelper::verticalSlice($none, 'username', 'age'); - $this->assert(is_array($names) && count($names) === 0); - - $names_other = DBHelper::reIndex($none, 'username', 'age'); - $this->assert(is_array($names_other) && count($names_other) === 0); - } - - function test_4_null() { - DB::query("UPDATE accounts SET password = NULL WHERE username=%s", 'Bart'); - - $all = DB::query("SELECT * FROM accounts ORDER BY id ASC"); - $ages = DBHelper::verticalSlice($all, 'age', 'password'); - $this->assert(count($ages) === 5); - $this->assert($ages[''] === '15'); - - $passwords = DBHelper::reIndex($all, 'password'); - $this->assert(count($passwords) === 5); - $this->assert($passwords['']['username'] === 'Bart'); - $this->assert($passwords['']['password'] === NULL); - } - -} -?> diff --git a/simpletest/test.php b/simpletest/test.php index 321ab4e..9d614a3 100755 --- a/simpletest/test.php +++ b/simpletest/test.php @@ -37,7 +37,6 @@ require_once __DIR__ . '/ObjectTest.php'; require_once __DIR__ . '/WhereClauseTest.php'; require_once __DIR__ . '/HookTest.php'; require_once __DIR__ . '/TransactionTest.php'; -require_once __DIR__ . '/HelperTest.php'; $classes_to_test = array( 'BasicTest', @@ -47,7 +46,6 @@ $classes_to_test = array( 'ObjectTest', 'HookTest', 'TransactionTest', - 'HelperTest', ); $mysql_version = DB::serverVersion();