From 7b4f00085bb82b3bf4ecb260e9a57d0819018f3c Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 7 Feb 2012 19:32:47 -0500 Subject: [PATCH] Finished sqlite create_table method --- src/databases/sqlite_manip.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/databases/sqlite_manip.php b/src/databases/sqlite_manip.php index c996881..6f0094a 100644 --- a/src/databases/sqlite_manip.php +++ b/src/databases/sqlite_manip.php @@ -26,7 +26,7 @@ class SQLite_manip extends db_manip { * @param array $indexes // column => index pairs * @return string */ - function create_table($name, $columns, $constraints=array(), $indexes=array()) + function create_table($name, $columns, $constraints=array()) { $column_array = array(); @@ -55,17 +55,23 @@ class SQLite_manip extends db_manip { } } - if( ! empty($indexes)) + // Join column definitons together + $columns = array(); + foreach($coumn_array as $name => $props) { - foreach($indexes as $col => $ind) - { - $column_array[$col]['index'] = $ind; - } + $str = "{$name} "; + $str .= (isset($props['type'])) ? "{$props['type']}" : ""; + $str .= (isset($props['constraint'])) ? "{$props['constraint']} " : ""; + + $columns[] = $str; } // Generate the sql for the creation of the table $sql = "CREATE TABLE {$name} ("; + $sql .= implode(",", $columns); $sql .= ")"; + + return $sql; } /**