function createTable($name, $fields, $field, $type, $array, $length, $notnull, $default, $withoutoids, $colcomment, $tblcomment, $tablespace, $uniquekey, $primarykey)
{
$f_schema = $this->_schema;
$this->fieldClean($f_schema);
$this->fieldClean($name);
$status = $this->beginTransaction();
if ($status != 0) {
return -1;
}
$found = false;
$first = true;
$comment_sql = '';
//Accumulate comments for the columns
$sql = "CREATE TABLE \"{$f_schema}\".\"{$name}\" (";
for ($i = 0; $i < $fields; $i++) {
$this->fieldClean($field[$i]);
$this->clean($type[$i]);
$this->clean($length[$i]);
$this->clean($colcomment[$i]);
// Skip blank columns - for user convenience
if ($field[$i] == '' || $type[$i] == '') {
continue;
}
// If not the first column, add a comma
if (!$first) {
$sql .= ", ";
} else {
$first = false;
}
switch ($type[$i]) {
// Have to account for weird placing of length for with/without
// time zone types
case 'timestamp with time zone':
case 'timestamp without time zone':
$qual = substr($type[$i], 9);
$sql .= "\"{$field[$i]}\" timestamp";
if ($length[$i] != '') {
$sql .= "({$length[$i]})";
}
$sql .= $qual;
break;
case 'time with time zone':
case 'time without time zone':
$qual = substr($type[$i], 4);
$sql .= "\"{$field[$i]}\" time";
if ($length[$i] != '') {
$sql .= "({$length[$i]})";
}
$sql .= $qual;
break;
default:
$sql .= "\"{$field[$i]}\" {$type[$i]}";
if ($length[$i] != '') {
$sql .= "({$length[$i]})";
}
}
// Add array qualifier if necessary
if ($array[$i] == '[]') {
$sql .= '[]';
}
// Add other qualifiers
if (!isset($primarykey[$i])) {
if (isset($uniquekey[$i])) {
$sql .= " UNIQUE";
}
if (isset($notnull[$i])) {
$sql .= " NOT NULL";
}
}
if ($default[$i] != '') {
$sql .= " DEFAULT {$default[$i]}";
}
if ($colcomment[$i] != '') {
$comment_sql .= "COMMENT ON COLUMN \"{$name}\".\"{$field[$i]}\" IS '{$colcomment[$i]}';\n";
}
$found = true;
}
if (!$found) {
return -1;
}
// PRIMARY KEY
$primarykeycolumns = array();
for ($i = 0; $i < $fields; $i++) {
if (isset($primarykey[$i])) {
$primarykeycolumns[] = "\"{$field[$i]}\"";
}
}
if (count($primarykeycolumns) > 0) {
$sql .= ", PRIMARY KEY (" . implode(", ", $primarykeycolumns) . ")";
}
$sql .= ")";
// WITHOUT OIDS
if ($withoutoids) {
$sql .= ' WITHOUT OIDS';
} else {
$sql .= ' WITH OIDS';
}
// Tablespace
if ($this->hasTablespaces() && $tablespace != '') {
$this->fieldClean($tablespace);
$sql .= " TABLESPACE \"{$tablespace}\"";
}
$status = $this->execute($sql);
if ($status) {
$this->rollbackTransaction();
return -1;
}
if ($tblcomment != '') {
$status = $this->setComment('TABLE', '', $name, $tblcomment, true);
if ($status) {
$this->rollbackTransaction();
return -1;
}
}
if ($comment_sql != '') {
$status = $this->execute($comment_sql);
if ($status) {
$this->rollbackTransaction();
return -1;
}
}
return $this->endTransaction();
}