summaryrefslogtreecommitdiff
path: root/lib/schema.php
diff options
context:
space:
mode:
authorBrion Vibber <brion@pobox.com>2010-08-16 16:31:18 -0700
committerBrion Vibber <brion@pobox.com>2010-08-16 16:31:18 -0700
commit033a7570133d4183c2e162859e9b85fe7df3e40b (patch)
tree5b073d537b75a35f11dbb1bf554b805f8d683878 /lib/schema.php
parent1a7d830fff04a9c16b259caf0633cb18fb74fe01 (diff)
More schema work in progress... removing duped code from schema child classes, rebuilding things a bit more (incomplete; non-working state)
Diffstat (limited to 'lib/schema.php')
-rw-r--r--lib/schema.php64
1 files changed, 43 insertions, 21 deletions
diff --git a/lib/schema.php b/lib/schema.php
index 9ebef8aa2..d20bced4a 100644
--- a/lib/schema.php
+++ b/lib/schema.php
@@ -224,7 +224,7 @@ class Schema
}
if (empty($name)) {
- $name = "$table_".implode("_", $columnNames)."_idx";
+ $name = "{$table}_".implode("_", $columnNames)."_idx";
}
$res = $this->conn->query("ALTER TABLE $table ".
@@ -422,7 +422,7 @@ class Schema
* @return array strings for name values
*/
- private function _names($cds)
+ protected function _names($cds)
{
$names = array();
@@ -443,7 +443,7 @@ class Schema
* @return ColumnDef matching item or null if no match.
*/
- private function _byName($cds, $name)
+ protected function _byName($cds, $name)
{
foreach ($cds as $cd) {
if ($cd->name == $name) {
@@ -466,31 +466,53 @@ class Schema
* @return string correct SQL for that column
*/
- private function _columnSql($cd)
+ function columnSql(array $cd)
{
- $sql = "{$cd->name} ";
-
- if (!empty($cd->size)) {
- $sql .= "{$cd->type}({$cd->size}) ";
- } else {
- $sql .= "{$cd->type} ";
+ $line = array();
+ $line[] = $this->typeAndSize();
+
+ if (isset($cd['default'])) {
+ $line[] = 'default';
+ $line[] = $this->quoted($cd['default']);
+ } else if (!empty($cd['not null'])) {
+ // Can't have both not null AND default!
+ $line[] = 'not null';
}
- if (!empty($cd->default)) {
- $sql .= "default {$cd->default} ";
- } else {
- $sql .= ($cd->nullable) ? "null " : "not null ";
- }
+ return implode(' ', $line);
+ }
- if (!empty($cd->auto_increment)) {
- $sql .= " auto_increment ";
- }
+ /**
+ *
+ * @param string $column canonical type name in defs
+ * @return string native DB type name
+ */
+ function mapType($column)
+ {
+ return $column;
+ }
- if (!empty($cd->extra)) {
- $sql .= "{$cd->extra} ";
+ function typeAndSize($column)
+ {
+ $type = $this->mapType($column);
+ $lengths = array();
+
+ if ($column['type'] == 'numeric') {
+ if (isset($column['precision'])) {
+ $lengths[] = $column['precision'];
+ if (isset($column['scale'])) {
+ $lengths[] = $column['scale'];
+ }
+ }
+ } else if (isset($column['length'])) {
+ $lengths[] = $column['length'];
}
- return $sql;
+ if ($lengths) {
+ return $type . '(' . implode(',', $lengths) . ')';
+ } else {
+ return $type;
+ }
}
/**