This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/Rails/ActiveRecord/Adapter/Sqlite/Table.php
2013-10-02 01:12:58 -05:00

36 lines
911 B
PHP
Executable File

<?php
namespace Rails\ActiveRecord\Adapter\Sqlite;
use PDO;
use Rails;
use Rails\ActiveRecord\Connection;
use Rails\ActiveRecord\Adapter\AbstractTable;
class Table/* extends AbstractTable*/
{
static public function fetchSchema(Connection $connection, $table_name)
{
$stmt = $connection->executeSql("PRAGMA table_info(`".$table_name."`);");
if (!$rows = $stmt->fetchAll(PDO::FETCH_ASSOC)) {
return $stmt;
}
$table_data = $pri = $uni = [];
$table_indexes = [
'pri' => [],
'uni' => []
];
foreach ($rows as $row) {
$data = ['type' => $row['type']];
$table_data[$row['name']] = $data;
if ($row['pk'])
$table_indexes['pri'][] = $row['name'];
}
return [$table_data, $table_indexes];
}
}