Skip to content

Commit 51e263d

Browse files
committed
Revert some PostGre porting
1 parent 80a3d7e commit 51e263d

File tree

3 files changed

+22
-36
lines changed

3 files changed

+22
-36
lines changed

src/PHPFUI/ORM/PDOInstance.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function getIndexes(string $table) : array
196196

197197
if (\str_starts_with($this->dsn, 'mysql'))
198198
{
199-
$rows = $this->getRows('SHOW INDEXES FROM ?', [$table]);
199+
$rows = $this->getRows('SHOW INDEXES FROM ' . $table);
200200
}
201201
elseif ($this->postGre)
202202
{
@@ -250,26 +250,12 @@ public function getIndexes(string $table) : array
250250
}
251251
else
252252
{
253-
$rows = $this->getRows("SELECT * FROM sqlite_master WHERE type = 'index' and tbl_name=?", [$table]);
253+
$rows = $this->getRows("SELECT * FROM sqlite_master WHERE type = 'index' and tbl_name='{$table}'");
254254
}
255255

256256
foreach ($rows as $row)
257257
{
258-
$index = new \PHPFUI\ORM\Schema\Index();
259-
260-
if (\str_starts_with($this->getDSN(), 'mysql'))
261-
{
262-
$index->primaryKey = 'PRIMARY' == $row['Key_name'];
263-
$index->name = $row['Column_name'];
264-
$index->extra = \implode(',', $row);
265-
}
266-
else
267-
{
268-
$index->name = $row['name'];
269-
$index->extra = $row['sql'] ?? '';
270-
$index->primaryKey = false;
271-
}
272-
$fields[$index->name] = $index;
258+
$fields[] = new \PHPFUI\ORM\Schema\Index($this, $row);
273259
}
274260

275261
return $fields;

src/PHPFUI/ORM/Schema/Field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(\PHPFUI\ORM\PDOInstance $pdo, array $fields, bool $a
2929
$this->type = \strtolower($fields['Type']);
3030
$this->nullable = 'YES' == $fields['Null'];
3131
$this->defaultValue = $fields['Default'];
32-
$this->primaryKey = 'PRI' == $fields['Key'];
32+
$this->primaryKey = false; // use indexes to find primary keys
3333
$this->autoIncrement = \str_contains($fields['Extra'], 'auto_increment');
3434
$this->extra = \str_replace('auto_increment', '', $fields['Extra']);
3535

src/PHPFUI/ORM/Schema/Index.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ class Index
1010

1111
public bool $primaryKey;
1212

13-
// /**
14-
// * @param array<string,mixed> $fields
15-
// */
16-
// public function __construct(\PHPFUI\ORM\PDOInstance $pdo, array $fields, bool $primaryKey = false)
17-
// {
18-
// if (\str_starts_with($pdo->getDSN(), 'mysql'))
19-
// {
20-
// $this->primaryKey = 'PRIMARY' == $fields['Key_name'];
21-
// $this->name = $fields['Column_name'];
22-
// $this->extra = \implode(',', $fields);
23-
// }
24-
// else
25-
// {
26-
// $this->name = $fields['name'];
27-
// $this->extra = $fields['sql'] ?? '';
28-
// $this->primaryKey = $primaryKey;
29-
// }
30-
// }
13+
/**
14+
* @param array<string,mixed> $fields
15+
*/
16+
public function __construct(\PHPFUI\ORM\PDOInstance $pdo, array $fields)
17+
{
18+
if (\str_starts_with($pdo->getDSN(), 'mysql'))
19+
{
20+
$this->primaryKey = 'PRIMARY' == $fields['Key_name'];
21+
$this->name = $fields['Column_name'];
22+
$this->extra = \implode(',', $fields);
23+
}
24+
else
25+
{
26+
$this->name = $fields['name'];
27+
$this->extra = $fields['sql'] ?? '';
28+
$this->primaryKey = false;
29+
}
30+
}
3131
}

0 commit comments

Comments
 (0)