Test Failed
Pull Request — master (#100)
by
unknown
17:04
created

SqliteDriverMetas   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 32
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPrimaryKeys() 0 10 3
A getFieldsInfos() 0 8 2
A getForeignKeys() 0 3 1
A getTablesName() 0 3 1
1
<?php
2
3
namespace Ubiquity\db\providers\pdo\drivers;
4
5
/**
6
 * Ubiquity\db\providers\pdo\drivers$SqliteDriverMetas
7
 * This class is part of Ubiquity
8
 *
9
 * @author
10
 * @version 1.0.0
11
 *
12
 */
13
class SqliteDriverMetas extends AbstractDriverMetaDatas {
14
15
	public function getForeignKeys($tableName, $pkName, $dbName = null): array {
16
		$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."';");
17
		return $recordset->fetchAll ( \PDO::FETCH_ASSOC );
18
	}
19
20
	public function getTablesName(): array {
21
		$query = $this->dbInstance->query ( 'SELECT name FROM sqlite_master WHERE type=\'table\';'  );
22
		return $query->fetchAll ( \PDO::FETCH_COLUMN );
23
	}
24
25
	public function getPrimaryKeys($tableName): array {
26
		$fieldkeys = array ();
27
		$recordset = $this->dbInstance->query ( "PRAGMA TABLE_INFO(".$table_name.");" );
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $table_name does not exist. Did you maybe mean $tableName?
Loading history...
28
		$keys = $recordset->fetchAll ( \PDO::FETCH_ASSOC );
29
		foreach ( $keys as $key ) {
30
            if ($key['pk']==1) {
31
                $fieldkeys[] = $key['name'];
32
            }			
33
		}
34
		return $fieldkeys;
35
	}
36
37
	public function getFieldsInfos($tableName): array {
38
		$fieldsInfos = array ();
39
		$recordset = $this->dbInstance->query (  "PRAGMA TABLE_INFO(".$table_name.");" );
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $table_name does not exist. Did you maybe mean $tableName?
Loading history...
40
		$fields = $recordset->fetchAll ( \PDO::FETCH_ASSOC );
41
		foreach ( $fields as $field ) {
42
			$fieldsInfos [$field ['name']] = [ "Type" => $field ['type'],"Nullable" => $field ["notnull"] ];
43
		}
44
		return $fieldsInfos;
45
	}
46
}
47
48