| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package DBIx::Fast::Schema; |
|
2
|
|
|
|
|
|
|
|
|
3
|
15
|
|
|
15
|
|
273
|
use v5.38; |
|
|
15
|
|
|
|
|
74
|
|
|
4
|
15
|
|
|
15
|
|
89
|
use Object::Pad 0.807; |
|
|
15
|
|
|
|
|
179
|
|
|
|
15
|
|
|
|
|
1247
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
15
|
|
|
15
|
|
12736
|
class DBIx::Fast::Schema :isa(DBIx::Fast::Base) { |
|
|
15
|
|
|
|
|
147
|
|
|
|
15
|
|
|
|
|
2112
|
|
|
7
|
|
|
|
|
|
|
field $tables :reader = {}; |
|
8
|
|
|
|
|
|
|
|
|
9
|
0
|
|
|
0
|
1
|
0
|
method _set_tables ($t) { $tables = $t } |
|
|
0
|
|
|
5
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
27
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
5
|
method _load_tables_name () { |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
3
|
|
|
12
|
2
|
|
|
|
|
13
|
my $driver = $self->dbix->dbd; |
|
13
|
2
|
|
|
|
|
7
|
my $sql = ''; |
|
14
|
|
|
|
|
|
|
|
|
15
|
2
|
50
|
33
|
|
|
16
|
if ( $driver eq 'MariaDB' || $driver eq 'mysql' ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
$sql = 'SHOW TABLES'; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
elsif ( $driver eq 'SQLite' ) { |
|
19
|
2
|
|
|
|
|
6
|
$sql = "SELECT name FROM sqlite_master WHERE type='table'"; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
elsif ( $driver eq 'Pg' ) { |
|
22
|
0
|
|
|
|
|
0
|
$sql = "SELECT tablename as name FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema'"; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
else { |
|
25
|
0
|
|
|
|
|
0
|
$self->dbix->Exception("Error driver - _load_tables_name"); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
2
|
|
|
|
|
3
|
my $table_list; |
|
29
|
|
|
|
|
|
|
|
|
30
|
2
|
|
|
|
|
5
|
for my $table ( @{ $self->dbix->array($sql) } ) { |
|
|
2
|
|
|
|
|
8
|
|
|
31
|
10
|
|
|
|
|
31
|
$table_list->{$table} = time(); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
17
|
$tables = $table_list; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
1
|
3
|
method clear_cache () { $tables = {} } |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
1
|
|
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
0
|
method get_indexes ($table) { |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
40
|
0
|
0
|
|
|
|
0
|
$self->dbix->Exception("Table required") unless $table; |
|
41
|
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
my $driver = $self->dbix->dbd; |
|
43
|
0
|
|
|
|
|
0
|
my $qtable = $self->dbix->_safe_id($table); |
|
44
|
0
|
|
|
|
|
0
|
my $sql = ''; |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
0
|
0
|
|
|
0
|
if ( $driver eq 'MariaDB' || $driver eq 'mysql' ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
$sql = "SHOW INDEX FROM $qtable"; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
elsif ( $driver eq 'Pg' ) { |
|
50
|
0
|
|
|
|
|
0
|
$sql = qq{ |
|
51
|
|
|
|
|
|
|
SELECT |
|
52
|
|
|
|
|
|
|
i.relname as index_name, |
|
53
|
|
|
|
|
|
|
a.attname as column_name, |
|
54
|
|
|
|
|
|
|
ix.indisunique as is_unique |
|
55
|
|
|
|
|
|
|
FROM |
|
56
|
|
|
|
|
|
|
pg_class t, |
|
57
|
|
|
|
|
|
|
pg_class i, |
|
58
|
|
|
|
|
|
|
pg_index ix, |
|
59
|
|
|
|
|
|
|
pg_attribute a |
|
60
|
|
|
|
|
|
|
WHERE |
|
61
|
|
|
|
|
|
|
t.oid = ix.indrelid |
|
62
|
|
|
|
|
|
|
AND i.oid = ix.indexrelid |
|
63
|
|
|
|
|
|
|
AND a.attrelid = t.oid |
|
64
|
|
|
|
|
|
|
AND a.attnum = ANY(ix.indkey) |
|
65
|
|
|
|
|
|
|
AND t.relkind = 'r' |
|
66
|
|
|
|
|
|
|
AND t.relname = ? |
|
67
|
|
|
|
|
|
|
}; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
elsif ( $driver eq 'SQLite' ) { |
|
70
|
0
|
|
|
|
|
0
|
$sql = "SELECT * FROM sqlite_master WHERE type='index' AND tbl_name=?"; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
0
|
my $sth = $self->dbix->db->dbh->prepare($sql); |
|
74
|
0
|
0
|
|
|
|
0
|
$sth->execute( $driver =~ /^(Pg|SQLite)$/ ? $table : () ); |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
return $sth->fetchall_arrayref( {} ); |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Deprecated alias |
|
80
|
0
|
|
|
0
|
0
|
0
|
method get_indexs ($table) { return $self->get_indexes($table) } |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
1
|
|
|
1
|
1
|
3
|
method primary_keys ($table) { |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1
|
|
|
83
|
1
|
50
|
|
|
|
3
|
$self->dbix->Exception("Table name required") unless $table; |
|
84
|
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
4
|
my $driver = $self->dbix->dbd; |
|
86
|
1
|
|
|
|
|
3
|
my $qtable = $self->dbix->_safe_id($table); |
|
87
|
1
|
|
|
|
|
2
|
my $sql = ''; |
|
88
|
|
|
|
|
|
|
|
|
89
|
1
|
50
|
33
|
|
|
9
|
if ( $driver eq 'MariaDB' || $driver eq 'mysql' ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
$sql = "SHOW KEYS FROM $qtable WHERE Key_name = 'PRIMARY'"; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
elsif ( $driver eq 'Pg' ) { |
|
93
|
0
|
|
|
|
|
0
|
$sql = qq{ |
|
94
|
|
|
|
|
|
|
SELECT a.attname |
|
95
|
|
|
|
|
|
|
FROM pg_index i |
|
96
|
|
|
|
|
|
|
JOIN pg_attribute a ON a.attrelid = i.indrelid |
|
97
|
|
|
|
|
|
|
AND a.attnum = ANY(i.indkey) |
|
98
|
|
|
|
|
|
|
WHERE i.indrelid = ?::regclass |
|
99
|
|
|
|
|
|
|
AND i.indisprimary |
|
100
|
|
|
|
|
|
|
}; |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
elsif ( $driver eq 'SQLite' ) { |
|
103
|
1
|
|
|
|
|
41
|
$sql = "PRAGMA table_info($qtable)"; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
4
|
my $sth = $self->dbix->db->dbh->prepare($sql); |
|
107
|
1
|
50
|
|
|
|
127
|
$sth->execute( $driver eq 'Pg' ? $table : () ); |
|
108
|
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
2
|
my @keys; |
|
110
|
1
|
50
|
|
|
|
3
|
if ( $driver eq 'SQLite' ) { |
|
111
|
1
|
|
|
|
|
23
|
while ( my $row = $sth->fetchrow_hashref ) { |
|
112
|
4
|
100
|
|
|
|
39
|
push @keys, $row->{name} if $row->{pk}; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
else { |
|
116
|
0
|
0
|
|
|
|
0
|
@keys = map { $_->{Column_name} || $_->{attname} } |
|
117
|
0
|
|
|
|
|
0
|
@{ $sth->fetchall_arrayref( {} ) }; |
|
|
0
|
|
|
|
|
0
|
|
|
118
|
|
|
|
|
|
|
} |
|
119
|
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
14
|
return \@keys; |
|
121
|
|
|
|
|
|
|
} |
|
122
|
|
|
|
|
|
|
|
|
123
|
4
|
|
|
4
|
1
|
12
|
method table_info ($table = undef) { |
|
|
4
|
|
|
|
|
13
|
|
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
8
|
|
|
124
|
4
|
100
|
|
|
|
18
|
$self->dbix->Exception("Table name required") unless $table; |
|
125
|
|
|
|
|
|
|
|
|
126
|
3
|
|
|
|
|
91
|
my $driver = $self->dbix->dbd; |
|
127
|
3
|
|
|
|
|
11
|
my $qtable = $self->dbix->_safe_id($table); |
|
128
|
3
|
|
|
|
|
7
|
my $sql = ''; |
|
129
|
|
|
|
|
|
|
|
|
130
|
3
|
50
|
33
|
|
|
37
|
if ( $driver eq 'MariaDB' || $driver eq 'mysql' ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
0
|
$sql = "SHOW CREATE TABLE $qtable"; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
elsif ( $driver eq 'Pg' ) { |
|
134
|
0
|
|
|
|
|
0
|
$sql = qq{SELECT column_name, data_type, character_maximum_length FROM information_schema.columns WHERE table_name = ?}; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
elsif ( $driver eq 'SQLite' ) { |
|
137
|
3
|
|
|
|
|
10
|
$sql = "PRAGMA table_info($qtable)"; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
3
|
|
|
|
|
10
|
my @params; |
|
141
|
3
|
50
|
|
|
|
13
|
push @params, $table if $driver eq 'Pg'; |
|
142
|
|
|
|
|
|
|
|
|
143
|
3
|
|
|
|
|
11
|
my $sth = $self->dbix->db->dbh->prepare($sql); |
|
144
|
3
|
|
|
|
|
740
|
$sth->execute(@params); |
|
145
|
|
|
|
|
|
|
|
|
146
|
3
|
|
|
|
|
57
|
return $sth->fetchall_arrayref( {} ); |
|
147
|
|
|
|
|
|
|
} |
|
148
|
|
|
|
|
|
|
|
|
149
|
1
|
|
|
1
|
1
|
3
|
method table_size ($table) { |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
2
|
|
|
150
|
1
|
50
|
|
|
|
9
|
$self->dbix->Exception("Table name required") unless $table; |
|
151
|
|
|
|
|
|
|
|
|
152
|
1
|
|
|
|
|
7
|
my $driver = $self->dbix->dbd; |
|
153
|
1
|
|
|
|
|
5
|
my $qtable = $self->dbix->_safe_id($table); |
|
154
|
1
|
|
|
|
|
3
|
my $sql = ''; |
|
155
|
1
|
|
|
|
|
2
|
my @params; |
|
156
|
|
|
|
|
|
|
|
|
157
|
1
|
50
|
33
|
|
|
15
|
if ( $driver eq 'MariaDB' || $driver eq 'mysql' ) { |
|
|
|
50
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
$sql = "SELECT table_rows as `rows`, data_length + index_length as size_bytes FROM information_schema.tables WHERE table_schema = DATABASE() AND table_name = ?"; |
|
159
|
0
|
|
|
|
|
0
|
@params = ($table); |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
elsif ( $driver eq 'Pg' ) { |
|
162
|
0
|
|
|
|
|
0
|
$sql = q{SELECT reltuples::bigint as rows, pg_total_relation_size(?) as size_bytes FROM pg_class WHERE relname = ?}; |
|
163
|
0
|
|
|
|
|
0
|
@params = ( $table, $table ); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
elsif ( $driver eq 'SQLite' ) { |
|
166
|
1
|
|
|
|
|
3
|
$sql = "SELECT count(*) as rows FROM $qtable"; |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
1
|
|
|
|
|
3
|
my $sth = $self->dbix->db->dbh->prepare($sql); |
|
170
|
1
|
|
|
|
|
198
|
$sth->execute(@params); |
|
171
|
|
|
|
|
|
|
|
|
172
|
1
|
|
|
|
|
46
|
return $sth->fetchrow_hashref; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |