File Coverage

blib/lib/Module/Build/DBD/SQLite.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod 9 9 100.0
total 44 44 100.0


line stmt bran cond sub pod time code
1             package Module::Build::DBD::SQLite;
2              
3 3     3   29174 use strict;
  3         7  
  3         110  
4 3     3   24 use warnings;
  3         7  
  3         1164  
5             our $VERSION = '0.10';
6              
7 1     1 1 22 sub get_client { 'sqlite3' }
8              
9             sub get_db_and_command {
10 1     1 1 4 my ($class, $client, $params) = @_;
11              
12 1         4 my @cmd = (
13             $client,
14             '-noheader',
15             '-bail',
16             '-column',
17             );
18 1         11 return $params->{dbname}, \@cmd
19             }
20              
21             sub get_db_option {
22 3     3 1 6 my ($class, $db) = @_;
23 3         21 return $db;
24             }
25              
26             sub get_create_db_command {
27 1     1 1 3 my ($class, $cmd, $db) = @_;
28 1         6 return ($^X, '-e', 42); # Do nothing.
29             }
30              
31             sub get_drop_db_command {
32 1     1 1 4 my ($class, $cmd, $db) = @_;
33 1         5 return ( $^X, '-e', 'unlink shift', $db);
34             }
35              
36             sub get_check_db_command {
37 1     1 1 2 my ($class, $cmd, $db) = @_;
38 1         6 return ($^X, '-l', '-e', "print 1 if -e shift", $db);
39             }
40              
41             sub get_execute_command {
42 1     1 1 3 my ($class, $cmd, $db, $sql) = @_;
43             return (
44 1         5 @$cmd,
45             $class->get_db_option($db),
46             $sql,
47             );
48             }
49              
50             sub get_file_command {
51 1     1 1 4 my ($class, $cmd, $db, $fn) = @_;
52             return (
53 1         5 @$cmd,
54             $class->get_db_option($db),
55             ".read $fn"
56             );
57             }
58              
59             sub get_meta_table_sql {
60 1     1 1 3 my ($class, $table) = @_;
61 1         7 return qq{
62             CREATE TABLE $table (
63             label TEXT PRIMARY KEY,
64             value INT NOT NULL DEFAULT 0,
65             note TEXT NOT NULL
66             );
67             };
68             }
69              
70             1;
71              
72             =head1 Name
73              
74             Module::Build::DBD:SQLite - SQLite specifics for Module::Build::DB
75              
76             =head1 Description
77              
78             This module contains a number of class methods called by L
79             to handle SQLite specific tasks when detecting, building, and updating a
80             database.
81              
82             =head2 Methods
83              
84             All methods are class methods.
85              
86             =head3 C
87              
88             my $client = Module::Build::DBD::SQLite->get_client;
89              
90             Returns the name of the client to use to connect to SQLite. For now,
91             that's just C, which is fine if it's in your path. Some code to search
92             for a client might be added in the future. Either way, it's best to specify
93             use the C<--db_client> option to avoid all ambiguity.
94              
95             =head3 C
96              
97             my ($db_name, $cmd) = Module::Build::DBD::SQLite->get_db_and_command($client, $params);
98              
99             Returns a database name culled from C<$params> and an array reference with
100             C<$client> and all required options for all access to the database. C<$params>
101             contains both the contents of the context configuration file's DBI section and
102             the attributes defined in the driver DSN (e.g., C in
103             C).
104              
105             =head3 C
106              
107             my @opts = Module::Build::DBD::SQLite->get_db_option($db_name);
108              
109             Returns a list of options to be appended to the command returned by
110             C to connect to a specific database. For SQLite, that's
111             simply C<$dbname>.
112              
113             =head3 C
114              
115             my @command = Module::Build::DBD::SQLite->get_create_db_command($cmd, $db);
116              
117             Returns a command list suitable for passing to C that will create a
118             new database. C<$cmd> is the command returned by C and
119             C<$db> is the name of the database to be created.
120              
121             =head3 C
122              
123             my @command = Module::Build::DBD::SQLite->get_drop_db_command($cmd, $db);
124              
125             Returns a command list suitable for passing to C that will drop an
126             existing database. C<$cmd> is the command returned by C
127             and C<$db> is the name of the database to be dropped.
128              
129             =head3 C
130              
131             my @command = Module::Build::DBD::SQLite->get_check_db_command($cmd, $db);
132              
133             Returns a command list suitable for passing to C that will, when
134             executed, output a 1 when C<$db> exists and nothing when C<$db> does not
135             exist. C<$cmd> is the command returned by C and C<$db>
136             is the name of the database to be checked.
137              
138             =head3 C
139              
140             my @command = Module::Build::DBD::SQLite->get_execute_command($cmd, $db, $sql);
141              
142             Returns a command list suitable for passing to C that will execute
143             the SQL in C<$sql> and return its output, if any. C<$cmd> is the command
144             returned by C, C<$db> is the name of the database to be
145             connect to for the query, and C<$sql> is the SQL command or commands to be
146             executed.
147              
148             =head3 C
149              
150             my @command = Module::Build::DBD::SQLite->get_file_command($cmd, $db, $sql);
151              
152             Returns a command list suitable for passing to C that will execute
153             the SQL in C<$file> and return its output, if any. C<$cmd> is the command
154             returned by C, C<$db> is the name of the database to be
155             connect to for the query, and C<$file> is a file with SQL commands.
156              
157             =head3 C
158              
159             my $sql = Module::Build::DBD::SQLite->get_meta_table_sql($table_name);
160              
161             Returns an SQL string that creates a metadata table named C<$table_name>.
162              
163             =head1 Author
164              
165             David E. Wheeler
166              
167             =head1 Copyright
168              
169             Copyright (c) 2008-2010 David E. Wheeler. Some Rights Reserved.
170              
171             This module is free software; you can redistribute it and/or modify it under
172             the same terms as Perl itself.
173              
174              
175             =cut