From e68b193c0a43cb674e413feda4516ffa44c28192 Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 7 Mar 2007 09:59:44 +0000 Subject: [PATCH] ported listTableViews and listViews from MDB2 cvs --- lib/Doctrine/Import/Sqlite.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/Import/Sqlite.php b/lib/Doctrine/Import/Sqlite.php index 6b03f7bcd..da9d17c7b 100644 --- a/lib/Doctrine/Import/Sqlite.php +++ b/lib/Doctrine/Import/Sqlite.php @@ -139,7 +139,7 @@ class Doctrine_Import_Sqlite extends Doctrine_Import 'length' => null, 'scale' => null, 'precision' => null, - 'unsigned' => null, + 'unsigned' => null, ); $columns[$val['name']] = $description; } @@ -188,7 +188,18 @@ class Doctrine_Import_Sqlite extends Doctrine_Import */ public function listTableViews($table) { + $query = "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT NULL"; + $views = $db->fetchAll($query); + $result = array(); + foreach ($views as $row) { + if (preg_match("/^create view .* \bfrom\b\s+\b{$table}\b /i", $row['sql'])) { + if ( ! empty($row['name'])) { + $result[$row['name']] = true; + } + } + } + return $result; } /** * lists database users @@ -207,7 +218,9 @@ class Doctrine_Import_Sqlite extends Doctrine_Import */ public function listViews($database = null) { + $query = "SELECT name FROM sqlite_master WHERE type='view' AND sql NOT NULL"; + return $this->conn->fetchColumn($query); } }