From 0a11b13bb1d94d51e695cd626dcde498346fee36 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 7 Feb 2012 12:30:16 -0500 Subject: [PATCH] SQLite driver updates Closer to having a usable create_table method --- src/databases/sqlite.php | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/databases/sqlite.php b/src/databases/sqlite.php index 09d1e4d..d407f6b 100644 --- a/src/databases/sqlite.php +++ b/src/databases/sqlite.php @@ -65,6 +65,9 @@ class SQLite extends DB_PDO { } } +/** + * Database manipulation class + */ class SQLite_manip extends SQLite { function __construct($dsn) @@ -79,19 +82,48 @@ class SQLite_manip extends SQLite { * @param array $columns //columns as straight array and/or column => type pairs * @param array $constraints // column => constraint pairs * @param array $indexes // column => index pairs - * @return srtring + * @return string */ function create_table($name, $columns, $constraints, $indexes) { - $sql = "CREATE TABLE {$name} ("; - + $column_array = array(); + + // Reorganize into an array indexed with column information + // Eg $column_array[$colname] = array( + // 'type' => ..., + // 'constraint' => ..., + // 'index' => ..., + // ) foreach($columns as $colname => $type) { if(is_numeric($colname)) { $colname = $type; } + + $column_array[$colname] = array(); + $column_array[$colname]['type'] = ($type !== $colname) ? $type : ''; } + + if( ! empty($constraints)) + { + foreach($constraints as $col => $const) + { + $column_array[$col]['constraint'] = $const; + } + } + + if( ! empty($indexes)) + { + foreach($indexes as $col => $ind) + { + $column_array[$col]['index'] = $ind; + } + } + + // Generate the sql for the creation of the table + $sql = "CREATE TABLE {$name} ("; + $sql .= ")"; } /**