summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Component.php3
-rw-r--r--src/Components/FieldDefinition.php2
-rw-r--r--src/Statement.php3
-rw-r--r--src/Utils/Table.php5
-rw-r--r--tests/Utils/TableTest.php44
5 files changed, 48 insertions, 9 deletions
diff --git a/src/Component.php b/src/Component.php
index 599784a..cd77982 100644
--- a/src/Component.php
+++ b/src/Component.php
@@ -65,7 +65,8 @@ abstract class Component
*
* @return string
*/
- public function __toString() {
+ public function __toString()
+ {
return static::build($this);
}
}
diff --git a/src/Components/FieldDefinition.php b/src/Components/FieldDefinition.php
index 22719eb..0217964 100644
--- a/src/Components/FieldDefinition.php
+++ b/src/Components/FieldDefinition.php
@@ -53,6 +53,8 @@ class FieldDefinition extends Component
'AS' => array(2, 'expr', array('bracketsDelimited' => true)),
'VIRTUAL' => 3,
'PERSISTENT' => 3,
+ // 'UNIQUE' => 4, // common
+ // 'UNIQUE KEY' => 4, // common
);
/**
diff --git a/src/Statement.php b/src/Statement.php
index f2d72b3..3739310 100644
--- a/src/Statement.php
+++ b/src/Statement.php
@@ -300,7 +300,8 @@ abstract class Statement
*
* @return string
*/
- public function __toString() {
+ public function __toString()
+ {
return static::build($this);
}
}
diff --git a/src/Utils/Table.php b/src/Utils/Table.php
index aa8cea6..6b17457 100644
--- a/src/Utils/Table.php
+++ b/src/Utils/Table.php
@@ -122,6 +122,11 @@ class Table
$ret[$field->name]['on_update_current_timestamp'] = true;
}
}
+
+ if (($option = $field->options->has('AS'))) {
+ $ret[$field->name]['generated'] = true;
+ $ret[$field->name]['expr'] = $option->expr;
+ }
}
}
diff --git a/tests/Utils/TableTest.php b/tests/Utils/TableTest.php
index bda6e78..9de7126 100644
--- a/tests/Utils/TableTest.php
+++ b/tests/Utils/TableTest.php
@@ -139,33 +139,33 @@ class TableTest extends TestCase
array(
'address_id' => array(
'type' => 'SMALLINT',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
),
'address' => array(
'type' => 'VARCHAR',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
),
'address2' => array(
'type' => 'VARCHAR',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
'default_value' => 'NULL',
),
'district' => array(
'type' => 'VARCHAR',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
),
'city_id' => array(
'type' => 'SMALLINT',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
),
'postal_code' => array(
'type' => 'VARCHAR',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
'default_value' => 'NULL',
),
'phone' => array(
'type' => 'VARCHAR',
- 'timestamp_not_null' => null,
+ 'timestamp_not_null' => false,
),
'last_update' => array(
'type' => 'TIMESTAMP',
@@ -176,6 +176,36 @@ class TableTest extends TestCase
)
)
),
+ array(
+ 'CREATE TABLE table1 (
+ a INT NOT NULL,
+ b VARCHAR(32),
+ c INT AS (a mod 10) VIRTUAL,
+ d VARCHAR(5) AS (left(b,5)) PERSISTENT
+ )',
+ array(
+ 'a' => array(
+ 'type' => 'INT',
+ 'timestamp_not_null' => false,
+ ),
+ 'b' => array(
+ 'type' => 'VARCHAR',
+ 'timestamp_not_null' => false,
+ ),
+ 'c' => array(
+ 'type' => 'INT',
+ 'timestamp_not_null' => false,
+ 'generated' => true,
+ 'expr' => '(a mod 10)',
+ ),
+ 'd' => array(
+ 'type' => 'VARCHAR',
+ 'timestamp_not_null' => false,
+ 'generated' => true,
+ 'expr' => '(left(b,5))',
+ ),
+ ),
+ ),
);
}
}