cvs: pear /MDB2 package_sqlite.php /MDB2/MDB2/Driver/Manager sqlite.php
| From: | Lorenzo Alberton | Date: | Mon, 05 Mar 2007 01:31:28 +0000 |
| Subject: | cvs: pear /MDB2 package_sqlite.php /MDB2/MDB2/Driver/Manager sqlite.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44971@lists.php.net to get a copy of this message | ||
quipo Mon Mar 5 01:31:28 2007 UTC
Modified files:
/pear/MDB2/MDB2/Driver/Manager sqlite.php
/pear/MDB2 package_sqlite.php
Log:
- implemented listViews() in the Manager module
- implemented listTableViews() in the Manager module
- implemented listTableTriggers() in the Manager module
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Manager/sqlite.php?r1=1.61&r2=1.62&diff_format=u
Index: pear/MDB2/MDB2/Driver/Manager/sqlite.php
diff -u pear/MDB2/MDB2/Driver/Manager/sqlite.php:1.61 pear/MDB2/MDB2/Driver/Manager/sqlite.php:1.62
--- pear/MDB2/MDB2/Driver/Manager/sqlite.php:1.61 Sun Mar 4 23:50:02 2007
+++ pear/MDB2/MDB2/Driver/Manager/sqlite.php Mon Mar 5 01:31:27 2007
@@ -39,10 +39,11 @@
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
// | POSSIBILITY OF SUCH DAMAGE. |
// +----------------------------------------------------------------------+
-// | Author: Lukas Smith <smith@pooteeweet.org> |
+// | Authors: Lukas Smith <smith@pooteeweet.org> |
+// | Lorenzo Alberton <l.alberton@quipo.it> |
// +----------------------------------------------------------------------+
//
-// $Id: sqlite.php,v 1.61 2007/03/04 23:50:02 quipo Exp $
+// $Id: sqlite.php,v 1.62 2007/03/05 01:31:27 quipo Exp $
//
require_once 'MDB2/Driver/Manager/Common.php';
@@ -53,6 +54,7 @@
* @package MDB2
* @category Database
* @author Lukas Smith <smith@pooteeweet.org>
+ * @author Lorenzo Alberton <l.alberton@quipo.it>
*/
class MDB2_Driver_Manager_sqlite extends MDB2_Driver_Manager_Common
{
@@ -407,6 +409,70 @@
}
// }}}
+ // {{{ listViews()
+
+ /**
+ * list all views in the current database
+ *
+ * @return mixed array of view names on success, a MDB2 error on failure
+ * @access public
+ */
+ function listViews()
+ {
+ $db =& $this->getDBInstance();
+ if (PEAR::isError($db)) {
+ return $db;
+ }
+
+ $query = "SELECT name FROM sqlite_master WHERE type='view' AND sql NOT
NULL";
+ $result = $db->queryCol($query);
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+ if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
+ $result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
+ }
+ return $result;
+ }
+
+ // }}}
+ // {{{ listTableViews()
+
+ /**
+ * list the views in the database that reference a given table
+ *
+ * @param string table for which all referenced views should be found
+ * @return mixed array of view names on success, a MDB2 error on failure
+ * @access public
+ */
+ function listTableViews($table)
+ {
+ $db =& $this->getDBInstance();
+ if (PEAR::isError($db)) {
+ return $db;
+ }
+
+ $query = "SELECT name, sql FROM sqlite_master WHERE type='view' AND sql NOT
NULL";
+ $views = $db->queryAll($query, array('text', 'text'),
MDB2_FETCHMODE_ASSOC);
+ if (PEAR::isError($views)) {
+ return $views;
+ }
+ $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;
+ }
+ }
+ }
+
+ if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
+ $result = array_change_key_case($result, $db->options['field_case']);
+ }
+ return array_keys($result);
+ }
+
+ // }}}
// {{{ listTables()
/**
@@ -488,6 +554,41 @@
}
// }}}
+ // {{{ listTableTriggers()
+
+ /**
+ * list all triggers in the database that reference a given table
+ *
+ * @param string table for which all referenced triggers should be found
+ * @return mixed array of trigger names on success, a MDB2 error on failure
+ * @access public
+ */
+ function listTableTriggers($table = null)
+ {
+ $db =& $this->getDBInstance();
+ if (PEAR::isError($db)) {
+ return $db;
+ }
+
+ $query = "SELECT name FROM sqlite_master WHERE type='trigger' AND sql NOT
NULL";
+ if (!is_null($table)) {
+ if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
+ $query.= ' AND LOWER(tbl_name)='.$db->quote(strtolower($table),
'text');
+ } else {
+ $query.= ' AND tbl_name='.$db->quote($table, 'text');
+ }
+ }
+ $result = $db->queryCol($query);
+ if (PEAR::isError($result)) {
+ return $result;
+ }
+ if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {
+ $result = array_map(($db->options['field_case'] == CASE_LOWER ?
'strtolower' : 'strtoupper'), $result);
+ }
+ return $result;
+ }
+
+ // }}}
// {{{ createIndex()
/**
http://cvs.php.net/viewvc.cgi/pear/MDB2/package_sqlite.php?r1=1.83&r2=1.84&diff_format=u
Index: pear/MDB2/package_sqlite.php
diff -u pear/MDB2/package_sqlite.php:1.83 pear/MDB2/package_sqlite.php:1.84
--- pear/MDB2/package_sqlite.php:1.83 Sun Mar 4 23:57:28 2007
+++ pear/MDB2/package_sqlite.php Mon Mar 5 01:31:27 2007
@@ -16,6 +16,9 @@
custom data types (thanks to Andrew Hill).
- fixed bug #9693: execute statement again in case of a SQLITE_SCHEMA error
- fixed bug #10027: PHP4 compatibility in createConstraint() and dropConstraint()
+- implemented listViews() in the Manager module
+- implemented listTableViews() in the Manager module
+- implemented listTableTriggers() in the Manager module
- phpdoc fixes
note: