Skip to content

Commit 115222b

Browse files
committed
fix: building of default columns vs table schema
1 parent d9d2ff5 commit 115222b

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"illuminate/database": "^10.0|^11.0",
2222
"illuminate/support": "^10.0|^11.0",
2323
"illuminate/filesystem": "^10.0|^11.0",
24-
"yajra/laravel-oci8": "^10.0|^11.0"
24+
"yajra/laravel-oci8": "^10.6|^11.0"
2525
},
2626
"require-dev": {
2727
"larastan/larastan": "^2.9.1",

src/SQLLoader.php

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,42 +83,49 @@ public function into(
8383
];
8484
}
8585

86-
$this->tables[] = new TableDefinition($table, $columns, $terminatedBy, $enclosedBy, $trailing, $formatOptions, $when);
86+
$this->tables[] = new TableDefinition(
87+
$table, $columns, $terminatedBy, $enclosedBy, $trailing, $formatOptions, $when
88+
);
8789

8890
return $this;
8991
}
9092

9193
protected function buildDefaultColumns(string $table, array $columns): array
9294
{
93-
$columns = $this->defaultColumns;
95+
$columns = array_map('strtolower', $this->defaultColumns);
9496
$schemaColumns = collect(Schema::connection(config('sql-loader.connection'))->getColumns($table));
9597

9698
$dates = $schemaColumns->filter(fn ($column) => in_array($column['type'], [
97-
'DATE',
98-
'DATETIME',
99-
'TIMESTAMP',
100-
'TIMESTAMP(6)',
99+
'date',
100+
'datetime',
101+
'timestamp',
102+
'timestamp(6)',
101103
]))->pluck('name')->toArray();
102104

103-
$booleans = $schemaColumns->filter(fn ($column) => $column['nullable'] === 'N' && $column['type'] === 'CHAR')->pluck('name')->toArray();
105+
$booleans = $schemaColumns->filter(
106+
fn ($column) => $column['nullable'] === false && $column['type'] === 'char'
107+
)->pluck('name')->toArray();
104108

105109
foreach ($columns as $key => $column) {
106-
$column = strtoupper((string) $column);
110+
$escapedColumn = '"'.strtoupper((string) $column).'"';
107111

108112
if (in_array($column, $dates)) {
109-
$columns[$key] = "\"$column\" DATE";
113+
$columns[$key] = "{$escapedColumn} DATE";
110114

111115
continue;
112116
}
113117

114118
if (in_array($column, $booleans)) {
115119
$default = $schemaColumns->where('name', $column)->first()['default'];
116-
$columns[$key] = "\"$column\" \"DECODE(:$column, '', $default, :$column)\"";
120+
$columns[$key] = "{$escapedColumn} \"DECODE(:$column, '', $default, :$column)\"";
117121

118122
continue;
119123
}
120124

121-
$columns[$key] = "\"$column\"";
125+
continue;
126+
}
127+
128+
$columns[$key] = "{$escapedColumn}";
122129
}
123130

124131
return $columns;
@@ -237,6 +244,11 @@ public static function make(array $options = []): SQLLoader
237244
return new self($options);
238245
}
239246

247+
public function getConnection(): string
248+
{
249+
return $this->connection ?? config('sql-loader.connection', 'oracle');
250+
}
251+
240252
/**
241253
* Get the SQL Loader binary path.
242254
*/
@@ -445,9 +457,4 @@ public function dateFormat(string $format): static
445457

446458
return $this;
447459
}
448-
449-
public function getConnection(): string
450-
{
451-
return $this->connection ?? config('sql-loader.connection', 'oracle');
452-
}
453460
}

0 commit comments

Comments
 (0)