Skip to content

Commit d2b2908

Browse files
committed
Fix builder
1 parent 6f6dbca commit d2b2908

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/Builder/ExtractBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function setModel(mixed $model): self
7171
public function build(): string
7272
{
7373
if (! isset($this->builder)) {
74-
throw new RuntimeException('Builder not initialized. Call asCsv() or asSql() first.');
74+
throw new RuntimeException('Builder not initialized. Call createBuilder(), asCsv() or asSql() first.');
7575
}
7676

7777
if (! isset($this->model)) {

src/Builder/SqlBuilder.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,24 @@ public function build(): string
1111
{
1212
$sql = '';
1313

14-
foreach ($this->data as $row) {
15-
$values = [];
16-
foreach ($this->columns as $column) {
17-
$value = $row[$column] ?? null;
14+
foreach ($this->columns as $column) {
15+
$value = $this->data[$column];
1816

19-
if (is_array($value)) {
20-
$values[] = "'".json_encode($value, JSON_UNESCAPED_UNICODE)."'";
21-
} elseif (is_null($value)) {
22-
$values[] = 'NULL';
23-
} elseif (is_numeric($value)) {
24-
$values[] = $value;
25-
} elseif (is_bool($value)) {
26-
$values[] = ($value ? "'1'" : "'0'");
27-
} else {
28-
$values[] = "'".addslashes($value)."'";
29-
}
17+
if (is_array($value)) {
18+
$values[] = "'".json_encode($value, JSON_UNESCAPED_UNICODE)."'";
19+
} elseif (is_null($value)) {
20+
$values[] = 'NULL';
21+
} elseif (is_numeric($value)) {
22+
$values[] = $value;
23+
} elseif (is_bool($value)) {
24+
$values[] = ($value ? "'1'" : "'0'");
25+
} else {
26+
$values[] = "'".addslashes($value)."'";
3027
}
31-
32-
$sql .= "INSERT INTO {$this->schemaName} (".implode(', ', $this->columns).') VALUES ('.implode(', ', $values).");\n";
3328
}
3429

30+
$sql .= "INSERT INTO {$this->schemaName} (".implode(', ', $this->columns).') VALUES ('.implode(', ', $values).");\n";
31+
3532
return $sql;
3633
}
3734
}

0 commit comments

Comments
 (0)