File Coverage

blib/lib/Data/Model/Driver/DBI/DBD/SQLite.pm
Criterion Covered Total %
statement 47 49 95.9
branch 16 18 88.8
condition 9 12 75.0
subroutine 10 11 90.9
pod 0 2 0.0
total 82 92 89.1


line stmt bran cond sub pod time code
1             package Data::Model::Driver::DBI::DBD::SQLite;
2 48     48   279 use strict;
  48         100  
  48         1957  
3 48     48   275 use warnings;
  48         97  
  48         1645  
4 48     48   405 use base 'Data::Model::Driver::DBI::DBD';
  48         94  
  48         32030  
5              
6 92     92 0 8406 sub fetch_last_id { $_[3]->func('last_insert_rowid') }
7              
8             sub bind_param_attributes {
9 1302     1302 0 2456 my($self, $data_type) = @_;
10 1302 50       3883 if ($data_type) {
11 1302 100 66     27451 if ($data_type =~ /blob/i || $data_type =~ /bin/i || $data_type =~ /\Abigint\Z/i) {
      100        
12 67         380 return DBI::SQL_BLOB;
13             }
14             }
15 1235         4079 return;
16             }
17              
18              
19              
20             sub _as_sql_column {
21 236     236   466 my($self, $c, $column, $args) = @_;
22              
23             # for primary key
24 236 100 66     1073 if (exists $args->{options}->{auto_increment} && $args->{options}->{auto_increment}) {
25 48         108 $c->{_sqlite_output_primary_key} = 1;
26 48         376 return sprintf('%-15s %-15s', $column, 'INTEGER') . ' NOT NULL PRIMARY KEY';
27             }
28              
29             # binary flagged is COLLATE BINARY
30 188 100 66     850 if (exists $args->{options}->{binary} && $args->{options}->{binary}) {
31 2         16 return sprintf('%-15s %-15s', $column, 'COLLATE BINARY');
32             }
33              
34             # TODO: you need COLLATE NOCASE suppor?
35              
36 186         777 return;
37             }
38              
39             sub _as_sql_column_type {
40 186     186   350 my($self, $c, $column, $args) = @_;
41 186         369 my $type = uc($args->{type});
42 186 100       544 if ($type =~ /BIN/) {
43 5         11 $args->{options}->{binary} = 0;
44 5         23 return "BLOB";
45             }
46              
47             # for pseudo bigint emulation
48 181 100       433 if ($type eq 'BIGINT') {
49 2         5 $args->{options}->{binary} = 0;
50 2         11 return "BLOB";
51             }
52              
53 179         717 return;
54             }
55              
56 0     0   0 sub _as_sql_unsigned { '' }
57              
58             sub _as_sql_primary_key {
59 96     96   336 my($self, $c) = @_;
60 96 100       611 return '' if $c->{_sqlite_output_primary_key};
61 48         359 return;
62             }
63              
64             sub _as_sql_unique {
65 96     96   185 my($self, $c, $unique) = @_;
66 96 100       126 return () unless @{ $unique };
  96         530  
67              
68 10         24 my @sql = ();
69 10         27 for my $data (@{ $unique }) {
  10         24  
70 12         26 my($name, $columns) = @{ $data };
  12         24  
71 12         20 push(@sql, 'UNIQUE (' . join(', ', @{ $columns }) . ')');
  12         58  
72             }
73 10         46 return @sql;
74             }
75              
76             sub _as_sql_get_table_attributes {
77 96     96   160 my($self, $c, $attributes) = @_;
78 96 50       574 return '' unless $attributes->{SQLite};
79 0           return $attributes->{SQLite};
80             }
81              
82             1;