Compatibilité avec DB2 Express C

This commit is contained in:
alebreton 2017-06-09 08:37:00 +02:00
parent 96670e0eaa
commit ebf2348485
8 changed files with 166 additions and 108 deletions

View File

@ -17,14 +17,15 @@ class ODBCZOSConnector extends ODBCConnector
protected function getDsn(array $config) protected function getDsn(array $config)
{ {
$dsnParts = [ $dsnParts = [
'odbc:DRIVER={IBM DB2 ODBC DRIVER}', "odbc:DRIVER=$driverName",
'Database=%s', 'Database=%s',
'Hostname=%s', 'Hostname=%s',
'Port=%s', 'Port=%s',
'Protocol=TCPIP', 'Protocol=TCPIP',
'Uid=%s', 'Uid=%s',
'Pwd=%s', 'Pwd=%s',
'', // Just to add a semicolon to the end of string '',
// Just to add a semicolon to the end of string
]; ];
$dsnConfig = [ $dsnConfig = [

View File

@ -101,7 +101,7 @@ class DB2Connection extends Connection
*/ */
protected function getDefaultSchemaGrammar() protected function getDefaultSchemaGrammar()
{ {
return $this->withTablePrefix(new SchemaGrammar()); return $this->withTablePrefix(new SchemaGrammar($this->config['driver'] == "odbc"?"i":"c"));
} }
/** /**
@ -115,6 +115,6 @@ class DB2Connection extends Connection
return new DB2ZOSProcessor(); return new DB2ZOSProcessor();
} }
return new DB2Processor(); return new DB2Processor($this->config['driver'] == "odbc"?"i":"c");
} }
} }

View File

@ -6,6 +6,7 @@ use Cooperl\Database\DB2\Connectors\ODBCConnector;
use Cooperl\Database\DB2\Connectors\IBMConnector; use Cooperl\Database\DB2\Connectors\IBMConnector;
use Cooperl\Database\DB2\Connectors\ODBCZOSConnector; use Cooperl\Database\DB2\Connectors\ODBCZOSConnector;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Config;
/** /**
* Class DB2ServiceProvider * Class DB2ServiceProvider
@ -38,21 +39,27 @@ class DB2ServiceProvider extends ServiceProvider
public function register() public function register()
{ {
// get the configs // get the configs
$conns = is_array(config('laravel-db2::database.connections')) ? config('laravel-db2::database.connections') : []; $conns = is_array(Config::get('laravel-db2::database.connections'))
? Config::get('laravel-db2::database.connections')
: [];
// Add my database configurations to the default set of configurations // Add my database configurations to the default set of configurations
config(['database.connections' => array_merge($conns, config('database.connections'))]); $this->app['config']['database.connections'] = array_merge(
$conns,
$this->app['config']['database.connections']
);
// Extend the connections with pdo_odbc and pdo_ibm drivers // Extend the connections with pdo_odbc and pdo_ibm drivers
foreach (config('database.connections') as $conn => $config) { foreach (Config::get('database.connections') as $conn => $config) {
// Only use configurations that feature a "odbc", "ibm" or "odbczos" driver // Only use configurations that feature a "odbc", "ibm" or "odbczos" driver
if (!isset($config['driver']) || !in_array($config['driver'], ['odbc', 'ibm', 'odbczos'])) { if (!isset($config['driver']) || !in_array($config['driver'], ['odbc', 'ibm', 'odbczos', 'odbcexpress'])) {
continue; continue;
} }
// Create a connector // Create a connector
$this->app['db']->extend($conn, function ($config) { $this->app['db']->extend($conn, function ($config) {
switch ($config['driver']) { switch ($config['driver']) {
case 'odbcexpress':
case 'odbc': case 'odbc':
$connector = new ODBCConnector(); $connector = new ODBCConnector();

View File

@ -181,16 +181,4 @@ class DB2Grammar extends Grammar
{ {
return 'Y-m-d H:i:s.u'; return 'Y-m-d H:i:s.u';
} }
/**
* Compile the random statement into SQL.
*
* @param string $seed
* @return string
*/
public function compileRandom($seed)
{
return "RAND($seed)";
}
} }

View File

@ -13,11 +13,23 @@ use Cooperl\Database\DB2\Query\Grammars\DB2Grammar;
*/ */
class DB2Processor extends Processor class DB2Processor extends Processor
{ {
private $bdType;
/**
* DB2Processor constructor.
*
* @param $bdType
*/
public function __construct($bdType)
{
$this->bdType = $bdType;
}
/** /**
* Process the results of a "select" query. * Process the results of a "select" query.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param array $results * @param array $results
* *
* @return array * @return array
*/ */
@ -37,13 +49,15 @@ class DB2Processor extends Processor
return $results; return $results;
}*/ }*/
/** /**
* Process an "insert get ID" query. * Process an "insert get ID" query.
* *
* @param \Illuminate\Database\Query\Builder $query * @param \Illuminate\Database\Query\Builder $query
* @param string $sql * @param string $sql
* @param array $values * @param array $values
* @param string $sequence * @param string $sequence
* *
* @return int/array * @return int/array
*/ */
@ -52,19 +66,24 @@ class DB2Processor extends Processor
$sequenceStr = $sequence ?: 'id'; $sequenceStr = $sequence ?: 'id';
if (is_array($sequence)) { if (is_array($sequence)) {
$grammar = new DB2Grammar(); $grammar = new DB2Grammar($this->bdType);
$sequenceStr = $grammar->columnize($sequence); $sequenceStr = $grammar->columnize($sequence);
} }
$sql = 'select '.$sequenceStr.' from new table ('.$sql; $sql = 'select ' . $sequenceStr . ' from new table (' . $sql;
$sql .= ')'; $sql .= ')';
$results = $query->getConnection()->select($sql, $values); $results = $query->getConnection()
->select($sql, $values);
if (is_array($sequence)) { if (is_array($sequence)) {
return array_values((array) $results[0]); return array_values((array) $results[0]);
} else { } else {
$result = (array) $results[0]; $result = (array) $results[0];
$id = $result[$sequenceStr]; if (isset($result[$sequenceStr])) {
$id = $result[$sequenceStr];
} else {
$id = $result[strtoupper($sequenceStr)];
}
return is_numeric($id) ? (int) $id : $id; return is_numeric($id) ? (int) $id : $id;
} }

View File

@ -28,7 +28,7 @@ class DB2ZOSProcessor extends Processor
$sequenceStr = $sequence ?: 'id'; $sequenceStr = $sequence ?: 'id';
if (is_array($sequence)) { if (is_array($sequence)) {
$grammar = new DB2Grammar(); $grammar = new DB2Grammar("z");
$sequenceStr = $grammar->columnize($sequence); $sequenceStr = $grammar->columnize($sequence);
} }

View File

@ -9,6 +9,28 @@ namespace Cooperl\Database\DB2\Schema;
*/ */
class Blueprint extends \Illuminate\Database\Schema\Blueprint class Blueprint extends \Illuminate\Database\Schema\Blueprint
{ {
public function synchro($index, $masterizable = false)
{
$this->string('id_sync', 20)
->index($index);
$this->string('hashcode', 32);
if (true === $masterizable) {
$this->boolean('data_master')
->default(true);
}
}
/**
* @param string $index
*/
public function dropSynchro($index)
{
$this->dropColumn('id_sync', 'hashcode');
$this->dropIndex($index);
}
/** /**
* Specify a system name for the table. * Specify a system name for the table.
* *
@ -37,11 +59,10 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
* @param string $type * @param string $type
* @param string|array $columns * @param string|array $columns
* @param string $index * @param string $index
* @param string|null $algorithm
* *
* @return \Illuminate\Support\Fluent * @return \Illuminate\Support\Fluent
*/ */
protected function indexCommand($type, $columns, $index, $algorithm = null) protected function indexCommand($type, $columns, $index, $algorithm = NULL)
{ {
$columns = (array) $columns; $columns = (array) $columns;
@ -50,7 +71,7 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
$indexSystem = false; $indexSystem = false;
if (!is_null($index)) { if (!is_null($index)) {
$indexSystem = $index; //$indexSystem = $index;
} }
$index = $this->createIndexName($type, $columns); $index = $this->createIndexName($type, $columns);

View File

@ -10,20 +10,42 @@ use Illuminate\Database\Schema\Blueprint;
class DB2Grammar extends Grammar class DB2Grammar extends Grammar
{ {
private $dbType;
/** /**
* The possible column modifiers. * The possible column modifiers.
* *
* @var array * @var array
*/ */
protected $preModifiers = ['ForColumn']; protected $preModifiers = ['ForColumn'];
protected $modifiers = ['Nullable', 'Default', 'Generated', 'Increment', 'StartWith', 'Before', 'ImplicitlyHidden']; protected $modifiers = [
'Nullable',
'Default',
'Generated',
'Increment',
'StartWith',
'Before',
'ImplicitlyHidden',
];
/** /**
* The possible column serials * The possible column serials
* *
* @var array * @var array
*/ */
protected $serials = ['smallInteger', 'integer', 'bigInteger']; protected $serials = [
'smallInteger',
'integer',
'bigInteger',
];
/**
* DB2Grammar constructor.
*
* @param $dbType
*/
public function __construct($dbType)
{
$this->dbType = $dbType;
}
/** /**
* Wrap a single string in keyword identifiers. * Wrap a single string in keyword identifiers.
@ -48,7 +70,11 @@ class DB2Grammar extends Grammar
*/ */
public function compileTableExists() public function compileTableExists()
{ {
return 'select * from information_schema.tables where table_schema = upper(?) and table_name = upper(?)'; if ($this->dbType == "i") {
return 'select * from information_schema.tables where table_schema = upper(?) and table_name = upper(?)';
} else {
return 'select * from syspublic.all_tables where table_schema = upper(?) and table_name = upper(?)';
}
} }
/** /**
@ -58,31 +84,39 @@ class DB2Grammar extends Grammar
*/ */
public function compileColumnExists() public function compileColumnExists()
{ {
return " if ($this->dbType == "i") {
return "
select column_name select column_name
from information_schema.columns from information_schema.columns
where table_schema = upper(?) where table_schema = upper(?)
and table_name = upper(?) and table_name = upper(?)
"; ";
} else {
return "
select column_name
from syspublic.all_ind_columns
where table_schema = upper(?)
and table_name = upper(?)
";
}
} }
/** /**
* Compile a create table command. * Compile a create table command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection * @param \Illuminate\Database\Connection $connection
* *
* @return string * @return string
*/ */
public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection) public function compileCreate(Blueprint $blueprint, Fluent $command, Connection $connection)
{ {
$columns = implode(', ', $this->getColumns($blueprint)); $columns = implode(', ', $this->getColumns($blueprint));
$sql = 'create table '.$this->wrapTable($blueprint); $sql = 'create table ' . $this->wrapTable($blueprint);
if (isset($blueprint->systemName)) { if (isset($blueprint->systemName)) {
$sql .= ' for system name '.$blueprint->systemName; $sql .= ' for system name ' . $blueprint->systemName;
} }
$sql .= " ($columns)"; $sql .= " ($columns)";
@ -94,14 +128,14 @@ class DB2Grammar extends Grammar
* Compile a label command. * Compile a label command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* @param \Illuminate\Database\Connection $connection * @param \Illuminate\Database\Connection $connection
* *
* @return string * @return string
*/ */
public function compileLabel(Blueprint $blueprint, Fluent $command, Connection $connection) public function compileLabel(Blueprint $blueprint, Fluent $command, Connection $connection)
{ {
return 'label on table '.$this->wrapTable($blueprint).' is \''.$command->label.'\''; return 'label on table ' . $this->wrapTable($blueprint) . ' is \'' . $command->label . '\'';
} }
/** /**
@ -121,7 +155,7 @@ class DB2Grammar extends Grammar
// used by the connection. The column's modifiers are compiled and added. // used by the connection. The column's modifiers are compiled and added.
//$sql = $this->wrap($column).' '.$this->getType($column); //$sql = $this->wrap($column).' '.$this->getType($column);
$sql = $this->addPreModifiers($this->wrap($column), $blueprint, $column); $sql = $this->addPreModifiers($this->wrap($column), $blueprint, $column);
$sql .= ' '.$this->getType($column); $sql .= ' ' . $this->getType($column);
$columns[] = $this->addModifiers($sql, $blueprint, $column); $columns[] = $this->addModifiers($sql, $blueprint, $column);
} }
@ -132,9 +166,9 @@ class DB2Grammar extends Grammar
/** /**
* Add the column modifiers to the definition. * Add the column modifiers to the definition.
* *
* @param string $sql * @param string $sql
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string * @return string
*/ */
@ -153,7 +187,7 @@ class DB2Grammar extends Grammar
* Compile a create table command. * Compile a create table command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -164,7 +198,7 @@ class DB2Grammar extends Grammar
$statements = []; $statements = [];
foreach ($columns as $column) { foreach ($columns as $column) {
$statements[] = 'alter table '.$table.' '.$column; $statements[] = 'alter table ' . $table . ' ' . $column;
} }
return $statements; return $statements;
@ -174,7 +208,7 @@ class DB2Grammar extends Grammar
* Compile a primary key command. * Compile a primary key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -187,7 +221,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
return "alter table {$table} add constraint {$command->index} primary key ({$columns})"; return "alter table {$table} add constraint {$command->index} primary key ({$columns})";
@ -197,7 +231,7 @@ class DB2Grammar extends Grammar
* Compile a foreign key command. * Compile a foreign key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -216,7 +250,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
$sql = "alter table {$table} add constraint {$command->index} "; $sql = "alter table {$table} add constraint {$command->index} ";
@ -240,7 +274,7 @@ class DB2Grammar extends Grammar
* Compile a unique key command. * Compile a unique key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -253,7 +287,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
return "alter table {$table} add constraint {$command->index} unique({$columns})"; return "alter table {$table} add constraint {$command->index} unique({$columns})";
@ -263,7 +297,7 @@ class DB2Grammar extends Grammar
* Compile a plain index key command. * Compile a plain index key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -276,7 +310,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
$sql = "create index {$command->index}"; $sql = "create index {$command->index}";
@ -295,33 +329,33 @@ class DB2Grammar extends Grammar
* Compile a drop table command. * Compile a drop table command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
public function compileDrop(Blueprint $blueprint, Fluent $command) public function compileDrop(Blueprint $blueprint, Fluent $command)
{ {
return 'drop table '.$this->wrapTable($blueprint); return 'drop table ' . $this->wrapTable($blueprint);
} }
/** /**
* Compile a drop table (if exists) command. * Compile a drop table (if exists) command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
public function compileDropIfExists(Blueprint $blueprint, Fluent $command) public function compileDropIfExists(Blueprint $blueprint, Fluent $command)
{ {
return 'drop table if exists '.$this->wrapTable($blueprint); return 'drop table if exists ' . $this->wrapTable($blueprint);
} }
/** /**
* Compile a drop column command. * Compile a drop column command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -330,27 +364,27 @@ class DB2Grammar extends Grammar
$columns = $this->prefixArray('drop', $this->wrapArray($command->columns)); $columns = $this->prefixArray('drop', $this->wrapArray($command->columns));
$table = $this->wrapTable($blueprint); $table = $this->wrapTable($blueprint);
return 'alter table '.$table.' '.implode(', ', $columns); return 'alter table ' . $table . ' ' . implode(', ', $columns);
} }
/** /**
* Compile a drop primary key command. * Compile a drop primary key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
public function compileDropPrimary(Blueprint $blueprint, Fluent $command) public function compileDropPrimary(Blueprint $blueprint, Fluent $command)
{ {
return 'alter table '.$this->wrapTable($blueprint).' drop primary key'; return 'alter table ' . $this->wrapTable($blueprint) . ' drop primary key';
} }
/** /**
* Compile a drop unique key command. * Compile a drop unique key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -362,7 +396,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
return "alter table {$table} drop index {$command->index}"; return "alter table {$table} drop index {$command->index}";
@ -372,7 +406,7 @@ class DB2Grammar extends Grammar
* Compile a drop index command. * Compile a drop index command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -384,7 +418,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
return "alter table {$table} drop index {$command->index}"; return "alter table {$table} drop index {$command->index}";
@ -394,7 +428,7 @@ class DB2Grammar extends Grammar
* Compile a drop foreign key command. * Compile a drop foreign key command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -406,7 +440,7 @@ class DB2Grammar extends Grammar
$schemaTable = explode(".", $table); $schemaTable = explode(".", $table);
if (count($schemaTable) > 1) { if (count($schemaTable) > 1) {
$command->index = str_replace($schemaTable[0]."_", "", $command->index); $command->index = str_replace($schemaTable[0] . "_", "", $command->index);
} }
return "alter table {$table} drop foreign key {$command->index}"; return "alter table {$table} drop foreign key {$command->index}";
@ -416,7 +450,7 @@ class DB2Grammar extends Grammar
* Compile a rename table command. * Compile a rename table command.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command * @param \Illuminate\Support\Fluent $command
* *
* @return string * @return string
*/ */
@ -424,7 +458,7 @@ class DB2Grammar extends Grammar
{ {
$from = $this->wrapTable($blueprint); $from = $this->wrapTable($blueprint);
return "rename table {$from} to ".$this->wrapTable($command->to); return "rename table {$from} to " . $this->wrapTable($command->to);
} }
/** /**
@ -474,7 +508,7 @@ class DB2Grammar extends Grammar
*/ */
protected function typeMediumText(Fluent $column) protected function typeMediumText(Fluent $column)
{ {
$colLength = ($column->length ? $column->length : 16369); $colLength = ($column->length ? $column->length : 16000);
return "varchar($colLength)"; return "varchar($colLength)";
} }
@ -488,7 +522,7 @@ class DB2Grammar extends Grammar
*/ */
protected function typeLongText(Fluent $column) protected function typeLongText(Fluent $column)
{ {
$colLength = ($column->length ? $column->length : 16369); $colLength = ($column->length ? $column->length : 16000);
return "varchar($colLength)"; return "varchar($colLength)";
} }
@ -550,7 +584,7 @@ class DB2Grammar extends Grammar
*/ */
protected function typeFloat(Fluent $column) protected function typeFloat(Fluent $column)
{ {
return "float({$column->total}, {$column->places})"; return "decimal({$column->total}, {$column->places})";
} }
/** /**
@ -592,14 +626,7 @@ class DB2Grammar extends Grammar
{ {
$definition = 'smallint constraint %s_%s_%s check(%s in(0, 1)) %s'; $definition = 'smallint constraint %s_%s_%s check(%s in(0, 1)) %s';
return sprintf( return sprintf($definition, $column->type, $column->prefix, $column->name, $column->name, is_null($column->default) ? ' default 0' : '');
$definition,
$column->type,
$column->prefix,
$column->name,
$column->name,
is_null($column->default) ? ' default 0' : ''
);
} }
/** /**
@ -611,7 +638,7 @@ class DB2Grammar extends Grammar
*/ */
protected function typeEnum(Fluent $column) protected function typeEnum(Fluent $column)
{ {
return "enum('".implode("', '", $column->allowed)."')"; return "enum('" . implode("', '", $column->allowed) . "')";
} }
/** /**
@ -639,7 +666,7 @@ class DB2Grammar extends Grammar
*/ */
protected function typeDateTime(Fluent $column) protected function typeDateTime(Fluent $column)
{ {
return 'timestamp default current_timestamp'; return 'datetime';
} }
/** /**
@ -690,7 +717,7 @@ class DB2Grammar extends Grammar
* Get the SQL for a nullable column modifier. * Get the SQL for a nullable column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
@ -703,14 +730,14 @@ class DB2Grammar extends Grammar
* Get the SQL for a default column modifier. * Get the SQL for a default column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
protected function modifyDefault(Blueprint $blueprint, Fluent $column) protected function modifyDefault(Blueprint $blueprint, Fluent $column)
{ {
if (!is_null($column->default)) { if (!is_null($column->default)) {
return " default ".$this->getDefaultValue($column->default); return " default " . $this->getDefaultValue($column->default);
} }
return null; return null;
@ -720,32 +747,31 @@ class DB2Grammar extends Grammar
* Get the SQL for an auto-increment column modifier. * Get the SQL for an auto-increment column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
protected function modifyIncrement(Blueprint $blueprint, Fluent $column) protected function modifyIncrement(Blueprint $blueprint, Fluent $column)
{ {
if (in_array($column->type, $this->serials) && $column->autoIncrement) { if (in_array($column->type, $this->serials) && $column->autoIncrement) {
return ' as identity constraint '.$blueprint->getTable().'_'.$column->name.'_primary primary key'; return ' generated by default as identity constraint ' . $blueprint->getTable() . '_' . $column->name . '_primary primary key';
} }
return null; return null;
} }
/** /**
* Get the SQL for an "before" column modifier. * Get the SQL for an "before" column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
protected function modifyBefore(Blueprint $blueprint, Fluent $column) protected function modifyBefore(Blueprint $blueprint, Fluent $column)
{ {
if (!is_null($column->before)) { if (!is_null($column->before)) {
return ' before '.$this->wrap($column->before); return ' before ' . $this->wrap($column->before);
} }
return null; return null;
@ -755,14 +781,14 @@ class DB2Grammar extends Grammar
* Get the SQL for an "for column" column modifier. * Get the SQL for an "for column" column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
protected function modifyForColumn(Blueprint $blueprint, Fluent $column) protected function modifyForColumn(Blueprint $blueprint, Fluent $column)
{ {
if (!is_null($column->forColumn)) { if (!is_null($column->forColumn)) {
return ' for column '.$this->wrap($column->forColumn); return ' for column ' . $this->wrap($column->forColumn);
} }
return null; return null;
@ -772,14 +798,14 @@ class DB2Grammar extends Grammar
* Get the SQL for a "generated" column modifier. * Get the SQL for a "generated" column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
protected function modifyGenerated(Blueprint $blueprint, Fluent $column) protected function modifyGenerated(Blueprint $blueprint, Fluent $column)
{ {
if (!is_null($column->generated)) { if (!is_null($column->generated)) {
return ' generated '.($column->generated === true ? 'always' : $this->wrap($column->generated)); return ' generated ' . ($column->generated === true ? 'always' : $this->wrap($column->generated));
} }
return null; return null;
@ -789,14 +815,14 @@ class DB2Grammar extends Grammar
* Get the SQL for a "startWith" column modifier. * Get the SQL for a "startWith" column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
protected function modifyStartWith(Blueprint $blueprint, Fluent $column) protected function modifyStartWith(Blueprint $blueprint, Fluent $column)
{ {
if (!is_null($column->startWith)) { if (!is_null($column->startWith)) {
return ' (start with '.$column->startWith.')'; return ' (start with ' . $column->startWith . ')';
} }
return null; return null;
@ -806,7 +832,7 @@ class DB2Grammar extends Grammar
* Get the SQL for an "implicitly hidden" column modifier. * Get the SQL for an "implicitly hidden" column modifier.
* *
* @param \Illuminate\Database\Schema\Blueprint $blueprint * @param \Illuminate\Database\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $column * @param \Illuminate\Support\Fluent $column
* *
* @return string|null * @return string|null
*/ */
@ -828,14 +854,10 @@ class DB2Grammar extends Grammar
*/ */
protected function getDefaultValue($value) protected function getDefaultValue($value)
{ {
if ( if ($value instanceof Expression || is_bool($value) || is_numeric($value)) {
$value instanceof Expression
|| is_bool($value)
|| is_numeric($value)
) {
return $value; return $value;
} }
return "'".strval($value)."'"; return "'" . strval($value) . "'";
} }
} }