DB::columnList() now returns details
This commit is contained in:
14
db.class.php
14
db.class.php
@@ -363,7 +363,19 @@ class MeekroDB {
|
||||
}
|
||||
|
||||
public function columnList($table) {
|
||||
return $this->queryOneColumn('Field', "SHOW COLUMNS FROM %b", $table);
|
||||
$data = $this->query("SHOW COLUMNS FROM %b", $table);
|
||||
$columns = [];
|
||||
foreach ($data as $row) {
|
||||
$columns[$row['Field']] = [
|
||||
'type' => $row['Type'],
|
||||
'null' => $row['Null'],
|
||||
'key' => $row['Type'],
|
||||
'default' => $row['Default'],
|
||||
'extra' => $row['Extra']
|
||||
];
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function tableList($db = null) {
|
||||
|
||||
@@ -161,10 +161,12 @@ class BasicTest extends SimpleTest {
|
||||
$results = DB::query("SELECT * FROM accounts WHERE username!=%s", "Charlie's Friend");
|
||||
$this->assert(count($results) === 3);
|
||||
|
||||
$columnlist = DB::columnList('accounts');
|
||||
$this->assert(count($columnlist) === 8);
|
||||
$this->assert($columnlist[0] === 'id');
|
||||
$this->assert($columnlist[5] === 'height');
|
||||
$columnList = DB::columnList('accounts');
|
||||
$columnKeys = array_keys($columnList);
|
||||
$this->assert(count($columnList) === 8);
|
||||
$this->assert($columnList['id']['type'] == 'int(11)');
|
||||
$this->assert($columnList['height']['type'] == 'double');
|
||||
$this->assert($columnKeys[5] == 'height');
|
||||
|
||||
$tablelist = DB::tableList();
|
||||
$this->assert(count($tablelist) === 3);
|
||||
@@ -283,7 +285,7 @@ class BasicTest extends SimpleTest {
|
||||
|
||||
$columns = DB::columnList('store data');
|
||||
$this->assert(count($columns) === 2);
|
||||
$this->assert($columns[1] === 'picture');
|
||||
$this->assert($columns['picture']['type'] === 'blob');
|
||||
|
||||
|
||||
$smile = file_get_contents(__DIR__ . '/smile1.jpg');
|
||||
|
||||
@@ -117,10 +117,12 @@ class ObjectTest extends SimpleTest {
|
||||
$results = $this->mdb->query("SELECT * FROM accounts WHERE username!=%s", "Charlie's Friend");
|
||||
$this->assert(count($results) === 2);
|
||||
|
||||
$columnlist = $this->mdb->columnList('accounts');
|
||||
$this->assert(count($columnlist) === 6);
|
||||
$this->assert($columnlist[0] === 'id');
|
||||
$this->assert($columnlist[4] === 'height');
|
||||
$columnList = $this->mdb->columnList('accounts');
|
||||
$columnKeys = array_keys($columnList);
|
||||
$this->assert(count($columnList) === 6);
|
||||
$this->assert($columnList['id']['type'] == 'int(11)');
|
||||
$this->assert($columnList['height']['type'] == 'double');
|
||||
$this->assert($columnKeys[4] == 'height');
|
||||
|
||||
$tablelist = $this->mdb->tableList();
|
||||
$this->assert(count($tablelist) === 1);
|
||||
|
||||
Reference in New Issue
Block a user