Skip to content

Commit 525e1de

Browse files
committed
corrections, update version for BC release
1 parent 8c941de commit 525e1de

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

lib/Constants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* ezsqlModel Constants
77
*/
8-
\defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.0.0');
8+
\defined('EZSQL_VERSION') or \define('EZSQL_VERSION', '5.1.0');
99
\defined('OBJECT') or \define('OBJECT', 'OBJECT');
1010
\defined('ARRAY_A') or \define('ARRAY_A', 'ARRAY_A');
1111
\defined('ARRAY_N') or \define('ARRAY_N', 'ARRAY_N');
@@ -174,7 +174,7 @@
174174
\define('DROP', 'DROP COLUMN');
175175
\define('CHANGE', 'CHANGE COLUMN');
176176
\define('ALTER', 'ALTER COLUMN');
177-
\define('MODIFY', 'MODIFY');
177+
\define('MODIFY', 'MODIFY COLUMN');
178178
\define('RENAME', 'RENAME TO');
179179
\define('CHANGER', '__modifyingColumns__');
180180

lib/ezQuery.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -955,20 +955,37 @@ public function create(string $table = null, ...$schemas)
955955
return false;
956956
}
957957

958-
// todo not finish, not tested
959-
public function alter(string $table = null, ...$schemas)
958+
/**
959+
* Modify columns in an existing database table, by either:
960+
*```js
961+
* - array( column_name, datatype, ...value/options arguments ) // calls create_schema()
962+
* - addColumn( column_name, datatype, ...value/options arguments ) // returns string
963+
* - dropColumn( column_name ) // returns string
964+
* - changingColumn( column_name, datatype, ...value/options arguments ) // returns string
965+
*```
966+
* @param string $table The name of the db table that you wish to alter
967+
* @param array ...$alteringSchema An array of:
968+
*
969+
* - @param string `$name,` - column name
970+
* - @param string `$type,` - data type for the column
971+
* - @param mixed `$size,` | `$value,`
972+
* - @param mixed `...$anyOtherArgs`
973+
*
974+
* @return mixed results of query() call
975+
*/
976+
public function alter(string $table = null, ...$alteringSchema)
960977
{
961-
if (empty($table) || empty($schemas))
978+
if (empty($table) || empty($alteringSchema))
962979
return false;
963980

964981
$sql = 'ALTER TABLE ' . $table . ' ';
965982

966983
$skipSchema = false;
967-
if (\is_string($schemas[0])) {
984+
if (\is_string($alteringSchema[0])) {
968985
$data = '';
969986
$allowedTypes = ezSchema::ALTERS;
970987
$pattern = "/" . \implode('|', $allowedTypes) . "/i";
971-
foreach ($schemas as $types) {
988+
foreach ($alteringSchema as $types) {
972989
if (\preg_match($pattern, $types)) {
973990
$data .= $types;
974991
$skipSchema = true;
@@ -978,7 +995,7 @@ public function alter(string $table = null, ...$schemas)
978995
}
979996

980997
if (!$skipSchema)
981-
$schema = $this->create_schema(...$schemas);
998+
$schema = $this->create_schema(...$alteringSchema);
982999

9831000
$alterTable = !empty($schema) ? $sql . $schema . ';' : null;
9841001
if (\is_string($alterTable))

lib/ezSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class ezSchema
6868
const OPTIONS = ['CONSTRAINT', 'PRIMARY KEY', 'FOREIGN KEY', 'UNIQUE', 'INDEX', 'REFERENCES'];
6969
const ALTERS = ['ADD', 'DROP COLUMN', 'CHANGE COLUMN', 'RENAME TO', 'MODIFY', 'ALTER COLUMN'];
7070
const CHANGES = [
71-
'mysqli' => 'MODIFY',
71+
'mysqli' => 'MODIFY COLUMN',
7272
'pgsql' => 'ALTER COLUMN',
7373
'sqlsrv' => 'ALTER COLUMN',
7474
'sqlite3' => ''

0 commit comments

Comments
 (0)