OnlineDDL/Helper/SQLite.pm

filter: Statementstmt 100% 58 / 58 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 21 / 21 Podpod 100% 12 / 12 totaltotal 98.9% 92 / 93 CC 2 SCAR 0.9
CC
2
Cov
98%
post_connection_stmts
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« OnlineDDL/Helper/Base.pm ↑ Summary
1 package DBIx::OnlineDDL::Helper::SQLite;
2  
3 3 our $AUTHORITY = 'cpan:GSG';
4 # ABSTRACT: Private OnlineDDL helper for SQLite-specific code
5 3 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 our $VERSION = 'v1.1.1'; # VERSION
7  
8 3 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 extends 'DBIx::OnlineDDL::Helper::Base';
12  
13 3 ▶use Types::Standard qw( InstanceOf );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use Sub::Util qw( set_subname );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 ▶use namespace::clean; # don't export the above
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 #pod =encoding utf8
20 #pod
21 #pod =head1 DESCRIPTION
22 #pod
23 #pod This is a private helper module for any SQLite-specific code. B<As a private module, any
24 #pod methods or attributes here are subject to change.>
25 #pod
26 #pod You should really be reading documentation for L<DBIx::OnlineDDL>. Or, if you want to
27 #pod create a helper module for a different RDBMS, read the docs for
28 #pod L<DBIx::OnlineDDL::Helper::Base>.
29 #pod
30 #pod =cut
31  
32 82 ▶sub dbms_uses_global_fk_namespace { 0 }
Subroutine dbms_uses_global_fk_namespace: called CC=1 SCAR=0.0
Pod documented
33 81 ▶sub child_fks_need_adjusting { 0 }
Subroutine child_fks_need_adjusting: called CC=1 SCAR=0.0
Pod documented
34 27 ▶sub null_safe_equals_op { 'IS' }
Subroutine null_safe_equals_op: called CC=1 SCAR=0.0
Pod documented
35  
36 sub current_catalog_schema {
37 28 ▶ my $self = shift;
Subroutine current_catalog_schema: called CC=1 SCAR=0.0
Pod documented
38 28 my $dbh = $self->dbh;
39  
40 28 local $dbh->{FetchHashKeyName} = 'NAME_lc';
41 28 my $databases = $dbh->selectall_hashref('PRAGMA database_list', 'seq');
42 28 my $schema = $databases->{0}{name}; # probably 'main'
43 28 return (undef, $schema);
44 }
45  
46 sub insert_select_stmt {
47 27 ▶ my ($self, $column_list_str) = @_;
Subroutine insert_select_stmt: called CC=1 SCAR=0.0
Pod documented
48  
49 27 my $dbh = $self->dbh;
50  
51 27 my $id_name_quote = $dbh->quote_identifier( $self->copy_opts->{id_name} );
52  
53 27 my $orig_table_name_quote = $dbh->quote_identifier($self->table_name);
54 27 my $new_table_name_quote = $dbh->quote_identifier($self->new_table_name);
55  
56 # Use INSERT OR IGNORE to ignore dupe key errors
57 27 return join("\n",
58 "INSERT OR IGNORE INTO $new_table_name_quote",
59 " ($column_list_str)",
60 "SELECT",
61 " $column_list_str",
62 "FROM $orig_table_name_quote",
63 "WHERE $id_name_quote BETWEEN ? AND ?",
64 );
65 }
66  
67 sub post_connection_stmts {
68 28 ▶ my $self = shift;
Subroutine post_connection_stmts: called CC=2 SCAR=7.0
Pod documented
69  
70 28 my $db_timeouts = $self->db_timeouts;
71 my @stmts = (
72 # See FK comment in MySQL module. FKs in SQLite are a per-connection enabled
73 # feature, so this is always a "session" command.
74 'PRAGMA foreign_keys = OFF',
75  
76 # DB timeouts
77 28 'PRAGMA busy_timeout = '.int($db_timeouts->{lock_file} * 1_000), # busy_timeout uses ms
78 );
79  
80 # SQLite version 3.25.0 fixes table renames to also rename references to the table,
81 # ie: child FKs. Since SQLite doesn't yet have an DDL statement for renaming the FKs
82 # back to the old name, setting this PRAGMA variable is the only option.
83 #
84 # Also, while this change was introduced in 3.25.0, it seems to only manifest itself
85 # when the driver reports version 3.26.0, possibly due to how their production
86 # releases work.
87 28 ▶ push @stmts, 'PRAGMA legacy_alter_table = ON' if $self->mmver >= 3.026;
Branch: 1 branch
BranchTrueFalseTotal
if $self->mmver >= "3.026" 28 0 28
88  
89 28 return @stmts;
90 }
91  
92 sub is_error_retryable {
93 2 ▶ my ($self, $error) = @_;
Subroutine is_error_retryable: called CC=1 SCAR=0.0
Pod documented
94  
95 # Disable /x flag to allow for whitespace within string, but turn it on for newlines
96 # and comments.
97 2 return $error =~ m<
98 # Locks
99 (?-x:database( table)? is locked)|
100  
101 # Connections
102 (?-x:attempt to [\w\s]+ on inactive database handle)|
103  
104 # Queries
105 (?-x:query aborted)|
106 (?-x:interrupted)
107 >xi;
108 }
109  
110 sub create_table_sql {
111 56 ▶ my ($self, $table_name) = @_;
Subroutine create_table_sql: called CC=1 SCAR=0.0
Pod documented
112  
113 56 my $create_sql;
114 $self->dbh_runner(run => set_subname '_create_table_sql', sub {
115 56 ▶ ($create_sql) = $_->selectrow_array('SELECT sql FROM sqlite_master WHERE name = ?', undef, $table_name);
Subroutine __ANON__: called CC=1 SCAR=0.0
116 56 });
117  
118 56 return $create_sql;
119 }
120  
121 # Keep Base->rename_fks_in_table_sql (not used)
122  
123 sub has_conflicting_triggers_on_table {
124 28 ▶ my ($self, $table_name) = @_;
Subroutine has_conflicting_triggers_on_table: called CC=1 SCAR=0.0
Pod documented
125  
126 return $self->dbh_runner(run => set_subname '_has_triggers_on_table', sub {
127 28 ▶ $_->selectrow_array(
Subroutine __ANON__: called CC=1 SCAR=0.0
128 'SELECT name FROM sqlite_master WHERE type = ? AND tbl_name = ?',
129 undef, 'trigger', $table_name
130 );
131 28 });
132 }
133  
134 # Always zero; multiple triggers per table/type aren't allowed
135 27 ▶sub has_triggers_on_table_to_be_copied { 0 }
Subroutine has_triggers_on_table_to_be_copied: called CC=1 SCAR=0.0
Pod documented
136  
137 sub find_new_trigger_identifier {
138 84 ▶ my ($self, $trigger_name) = @_;
Subroutine find_new_trigger_identifier: called CC=1 SCAR=0.0
Pod documented
139  
140 return $self->find_new_identifier(
141 $trigger_name => sub {
142 84 ▶ $_[0]->selectrow_array(
Subroutine __ANON__: called CC=1 SCAR=0.0
143 'SELECT name FROM sqlite_master WHERE type = ? AND name = ?',
144 undef, 'trigger', $_[1]
145 );
146 },
147 84 );
148 }
149  
150 # Keep Base->modify_trigger_dml_stmts (nothing changed)
151  
152 sub analyze_table {
153 27 ▶ my ($self, $table_name) = @_;
Subroutine analyze_table: called CC=1 SCAR=0.0
Pod documented
154 27 my $table_name_quote = $self->dbh->quote_identifier($table_name);
155 27 $self->dbh_runner_do("ANALYZE $table_name_quote");
156 }
157  
158 # Keep Base->swap_tables (has transactional DDL)
159  
160 # Keep the trigger methods (not used)
161  
162 # Keep the other FK methods (not used)
163  
164 3 1;
165  
166 __END__
« OnlineDDL/Helper/Base.pm ↑ Summary