db2 driver updates
This commit is contained in:
@@ -27,7 +27,7 @@ class Db2SchemaBuilder extends Builder
|
||||
{
|
||||
$schema = $this->connection->getConfig('schema');
|
||||
|
||||
if (!$schema || !preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $schema)) {
|
||||
if (! $schema || ! preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $schema)) {
|
||||
throw new \RuntimeException('A valid Db2 schema is required for db:wipe.');
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ class Db2SchemaBuilder extends Builder
|
||||
throw new \RuntimeException('Unable to read Db2 table name.');
|
||||
}
|
||||
|
||||
$qualified = '"' . str_replace('"', '""', $schema) . '"."' .
|
||||
str_replace('"', '""', trim($name)) . '"';
|
||||
$qualified = '"'.str_replace('"', '""', $schema).'"."'.
|
||||
str_replace('"', '""', trim($name)).'"';
|
||||
|
||||
$this->connection->statement(
|
||||
"DROP TABLE {$qualified}"
|
||||
@@ -58,14 +58,13 @@ class Db2SchemaBuilder extends Builder
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// BEGIN DB2 SCHEMA INSPECTION
|
||||
|
||||
private function db2Schema($schema = null)
|
||||
{
|
||||
$schema = $schema ?? $this->connection->getConfig('schema');
|
||||
|
||||
if (!is_string($schema) || $schema === '') {
|
||||
if (! is_string($schema) || $schema === '') {
|
||||
throw new \RuntimeException('Invalid Db2 schema.');
|
||||
}
|
||||
|
||||
@@ -76,12 +75,13 @@ class Db2SchemaBuilder extends Builder
|
||||
$schema = str_replace('""', '"', $schema);
|
||||
}
|
||||
|
||||
if (!preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $schema)) {
|
||||
if (! preg_match('/^[A-Za-z_][A-Za-z0-9_]*$/', $schema)) {
|
||||
throw new \RuntimeException('Invalid Db2 schema.');
|
||||
}
|
||||
|
||||
return strtoupper($schema);
|
||||
}
|
||||
|
||||
public function getTables($schema = null)
|
||||
{
|
||||
$schema = $this->db2Schema($schema);
|
||||
@@ -102,9 +102,8 @@ class Db2SchemaBuilder extends Builder
|
||||
return [
|
||||
'name' => $name,
|
||||
'schema' => $schema,
|
||||
'schema_qualified_name' =>
|
||||
'"' . str_replace('"', '""', $schema) .
|
||||
'"."' . str_replace('"', '""', $name) . '"',
|
||||
'schema_qualified_name' => '"'.str_replace('"', '""', $schema).
|
||||
'"."'.str_replace('"', '""', $name).'"',
|
||||
'type' => $row->TYPE === 'V' ? 'view' : 'table',
|
||||
'size' => null,
|
||||
'engine' => null,
|
||||
@@ -140,11 +139,11 @@ class Db2SchemaBuilder extends Builder
|
||||
$type = $typeName === 'CHARACTER' ? 'CHAR' : $typeName;
|
||||
|
||||
if (in_array(strtoupper($type), ['VARCHAR', 'CHAR', 'VARGRAPHIC', 'GRAPHIC'])) {
|
||||
$type .= '(' . (int) $row->LENGTH . ')';
|
||||
$type .= '('.(int) $row->LENGTH.')';
|
||||
} elseif (in_array(strtoupper($type), ['DECIMAL', 'NUMERIC'])) {
|
||||
$type .= '(' . (int) $row->LENGTH . ',' . (int) $row->SCALE . ')';
|
||||
$type .= '('.(int) $row->LENGTH.','.(int) $row->SCALE.')';
|
||||
} elseif (strtoupper($type) === 'TIMESTAMP') {
|
||||
$type .= '(' . (int) $row->SCALE . ')';
|
||||
$type .= '('.(int) $row->SCALE.')';
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -167,7 +166,7 @@ class Db2SchemaBuilder extends Builder
|
||||
$schema = $this->db2Schema($schema);
|
||||
|
||||
$rows = $this->connection->select(
|
||||
"SELECT I.INDNAME, I.UNIQUERULE,
|
||||
'SELECT I.INDNAME, I.UNIQUERULE,
|
||||
C.COLNAME, C.COLSEQ
|
||||
FROM SYSCAT.INDEXES I
|
||||
JOIN SYSCAT.INDEXCOLUSE C
|
||||
@@ -175,7 +174,7 @@ class Db2SchemaBuilder extends Builder
|
||||
AND I.INDNAME = C.INDNAME
|
||||
WHERE I.TABSCHEMA = ?
|
||||
AND I.TABNAME = ?
|
||||
ORDER BY I.INDNAME, C.COLSEQ",
|
||||
ORDER BY I.INDNAME, C.COLSEQ',
|
||||
[$schema, $table]
|
||||
);
|
||||
|
||||
@@ -184,7 +183,7 @@ class Db2SchemaBuilder extends Builder
|
||||
foreach ($rows as $row) {
|
||||
$name = trim($row->INDNAME);
|
||||
|
||||
if (!isset($indexes[$name])) {
|
||||
if (! isset($indexes[$name])) {
|
||||
$indexes[$name] = [
|
||||
'name' => $name,
|
||||
'columns' => [],
|
||||
@@ -208,7 +207,7 @@ class Db2SchemaBuilder extends Builder
|
||||
$schema = $this->db2Schema($schema);
|
||||
|
||||
$rows = $this->connection->select(
|
||||
"SELECT R.CONSTNAME,
|
||||
'SELECT R.CONSTNAME,
|
||||
R.REFTABSCHEMA,
|
||||
R.REFTABNAME,
|
||||
R.DELETERULE,
|
||||
@@ -232,7 +231,7 @@ class Db2SchemaBuilder extends Builder
|
||||
AND RK.COLSEQ = K.COLSEQ
|
||||
WHERE R.TABSCHEMA = ?
|
||||
AND R.TABNAME = ?
|
||||
ORDER BY R.CONSTNAME, K.COLSEQ",
|
||||
ORDER BY R.CONSTNAME, K.COLSEQ',
|
||||
[$schema, $table]
|
||||
);
|
||||
|
||||
@@ -242,7 +241,7 @@ class Db2SchemaBuilder extends Builder
|
||||
foreach ($rows as $row) {
|
||||
$name = trim($row->CONSTNAME);
|
||||
|
||||
if (!isset($foreignKeys[$name])) {
|
||||
if (! isset($foreignKeys[$name])) {
|
||||
$foreignKeys[$name] = [
|
||||
'name' => $name,
|
||||
'columns' => [],
|
||||
@@ -278,5 +277,4 @@ class Db2SchemaBuilder extends Builder
|
||||
trim($name, '"'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user