Skip to content

Commit 1b95158

Browse files
committed
feat: Optionally supply sqlType to addColumnOptions
1 parent c2d525d commit 1b95158

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
lines changed

lib/Horde/Db/Adapter/Base/Schema.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,20 +638,21 @@ public function addColumn(
638638
'unsigned' => null],
639639
$options
640640
);
641-
642-
$sql = sprintf(
643-
'ALTER TABLE %s ADD %s %s',
644-
$this->quoteTableName($tableName),
645-
$this->quoteColumnName($columnName),
646-
$this->typeToSql(
641+
$sqlType = $this->typeToSql(
647642
$type,
648643
$options['limit'],
649644
$options['precision'],
650645
$options['scale'],
651646
$options['unsigned']
652-
)
653647
);
654-
$sql = $this->addColumnOptions($sql, $options);
648+
649+
$sql = sprintf(
650+
'ALTER TABLE %s ADD %s %s',
651+
$this->quoteTableName($tableName),
652+
$this->quoteColumnName($columnName),
653+
$sqlType
654+
);
655+
$sql = $this->addColumnOptions($sql, $options, $sqlType);
655656

656657
return $this->execute($sql);
657658
}
@@ -986,7 +987,7 @@ public function typeToSql(
986987
*
987988
* @return string The manipulated SQL definition.
988989
*/
989-
public function addColumnOptions($sql, $options)
990+
public function addColumnOptions($sql, $options, string $sqlType = '')
990991
{
991992
/* 'autoincrement' is not handled here - it varies too much between
992993
* DBs. Do autoincrement-specific handling in the driver. */

lib/Horde/Db/Adapter/Mysql/Schema.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,15 @@ public function typeToSql(
566566
*
567567
* @return string The manipulated SQL definition.
568568
*/
569-
public function addColumnOptions($sql, $options)
569+
public function addColumnOptions($sql, $options, string $sqlType = '')
570570
{
571-
$sql = parent::addColumnOptions($sql, $options);
571+
$sql = parent::addColumnOptions($sql, $options, $sqlType);
572572
if (isset($options['after'])) {
573573
$sql .= ' AFTER ' . $this->quoteColumnName($options['after']);
574574
}
575+
if (isset($options['default'])) {
576+
$options['default'] = self::filterDefault($options['default'], $sqlType);
577+
}
575578
if (!empty($options['autoincrement'])) {
576579
$sql .= ' AUTO_INCREMENT';
577580
}

lib/Horde/Db/Adapter/Oracle/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ public function currentDatabase()
862862
*
863863
* @return string The manipulated SQL definition.
864864
*/
865-
public function addColumnOptions($sql, $options)
865+
public function addColumnOptions($sql, $options, string $sqlType = '')
866866
{
867867
/* 'autoincrement' is not handled here - it varies too much between
868868
* DBs. Do autoincrement-specific handling in the driver. */

src/Adapter/Base/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ public function typeToSql(
10031003
*
10041004
* @return string The manipulated SQL definition.
10051005
*/
1006-
public function addColumnOptions($sql, $options)
1006+
public function addColumnOptions($sql, $options, string $sqlType = '')
10071007
{
10081008
/* 'autoincrement' is not handled here - it varies too much between
10091009
* DBs. Do autoincrement-specific handling in the driver. */

src/Adapter/Mysql/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public function typeToSql(
550550
*
551551
* @return string The manipulated SQL definition.
552552
*/
553-
public function addColumnOptions($sql, $options)
553+
public function addColumnOptions($sql, $options, string $sqlType = '')
554554
{
555555
$sql = parent::addColumnOptions($sql, $options);
556556
if (isset($options['after'])) {

src/Adapter/Oracle/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ public function currentDatabase()
869869
*
870870
* @return string The manipulated SQL definition.
871871
*/
872-
public function addColumnOptions($sql, $options)
872+
public function addColumnOptions($sql, $options, string $sqlType = '')
873873
{
874874
/* 'autoincrement' is not handled here - it varies too much between
875875
* DBs. Do autoincrement-specific handling in the driver. */

0 commit comments

Comments
 (0)