Finished sqlite create_table method
This commit is contained in:
parent
9ddab65bc0
commit
7b4f00085b
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user