Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
SqliteDriverMetas.php
Go to the documentation of this file.
1<?php
2
4
14
15 public function getForeignKeys($tableName, $pkName, $dbName = null): array {
16
17 // SQL lite may return error if key is not found when manual model editing can cause it by mistype of model field name.
18 $recordset = $this->dbInstance->query ( "SELECT \"TABLE\" as TABLE_NAME , \"to\" as COLUMN_NAME , \"from\" as REFERENCED_TABLE_SCHEMA FROM pragma_foreign_key_list('" . $tableName . "') WHERE \"to\"='" . $pkName . "';" );
19 return $recordset->fetchAll ( \PDO::FETCH_ASSOC );
20 }
21
22 public function getTablesName(): array {
23 $query = $this->dbInstance->query ( 'SELECT name FROM sqlite_master WHERE type=\'table\';' );
24 return $query->fetchAll ( \PDO::FETCH_COLUMN );
25 }
26
27 public function getPrimaryKeys($tableName): array {
28 $fieldkeys = array ();
29 $recordset = $this->dbInstance->query ( "PRAGMA TABLE_INFO(" . $tableName . ");" );
30 $keys = $recordset->fetchAll ( \PDO::FETCH_ASSOC );
31 foreach ( $keys as $key ) {
32 if ($key ['pk'] == 1) {
33 $fieldkeys [] = $key ['name'];
34 }
35 }
36 return $fieldkeys;
37 }
38
39 public function getFieldsInfos($tableName): array {
40 $fieldsInfos = array ();
41 $recordset = $this->dbInstance->query ( "PRAGMA TABLE_INFO(" . $tableName . ");" );
42 $fields = $recordset->fetchAll ( \PDO::FETCH_ASSOC );
43 foreach ( $fields as $field ) {
44 $fieldsInfos [$field ['name']] = [ "Type" => $field ['type'],"Nullable" => $field ["notnull"] ];
45 }
46 return $fieldsInfos;
47 }
48
49 public function getRowNum(string $tableName, string $pkName, string $condition): int {
50 $query = $this->dbInstance->query ( "SELECT num FROM (SELECT *,row_number() OVER (ORDER BY {$pkName}) AS num FROM \"{$tableName}\") x where " . $condition );
51 if ($query) {
52 return $query->fetchColumn ( 0 );
53 }
54 return 0;
55 }
56
57 public function groupConcat(string $fields, string $separator): string {
58 return "GROUP_CONCAT({$fields},'{$separator}')";
59 }
60}
61
Ubiquity\db\providers$DriverMetaDatas This class is part of Ubiquity.
Ubiquity\db\providers\pdo\drivers$SqliteDriverMetas This class is part of Ubiquity.
getForeignKeys($tableName, $pkName, $dbName=null)
groupConcat(string $fields, string $separator)
Returns the SQL callback for fields concatenation.
getRowNum(string $tableName, string $pkName, string $condition)
Returns the line number of a data record.
getTablesName()
Returns all table names in the database.