Finished sqlite create_table method

This commit is contained in:
Timothy Warren 2012-02-07 19:32:47 -05:00
parent 9ddab65bc0
commit 7b4f00085b

View File

@ -26,7 +26,7 @@ class SQLite_manip extends db_manip {
* @param array $indexes // column => index pairs * @param array $indexes // column => index pairs
* @return string * @return string
*/ */
function create_table($name, $columns, $constraints=array(), $indexes=array()) function create_table($name, $columns, $constraints=array())
{ {
$column_array = 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) $str = "{$name} ";
{ $str .= (isset($props['type'])) ? "{$props['type']}" : "";
$column_array[$col]['index'] = $ind; $str .= (isset($props['constraint'])) ? "{$props['constraint']} " : "";
}
$columns[] = $str;
} }
// Generate the sql for the creation of the table // Generate the sql for the creation of the table
$sql = "CREATE TABLE {$name} ("; $sql = "CREATE TABLE {$name} (";
$sql .= implode(",", $columns);
$sql .= ")"; $sql .= ")";
return $sql;
} }
/** /**