SQLEngine/Driver/Pg.pm untested

filter: Statementstmt 0.0% 0 / 18 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 47 CC 4 SCAR 21.5
CC
4
Cov
0%
sql_limit
20.0
do_insert_with_sequence
2.0
seq_increment
2.0
CRAP 8.5
1 =head1 NAME
2  
3 DBIx::SQLEngine::Driver::Pg - Support DBD::Pg
4  
5 =head1 SYNOPSIS
6  
7 B<DBI Wrapper>: Adds methods to a DBI database handle.
8  
9 my $sqldb = DBIx::SQLEngine->new( 'dbi:pg:test' );
10
11 B<Portability Subclasses:> Uses driver's idioms or emulation.
12  
13 $hash_ary = $sqldb->fetch_select(
14 table => 'students'
15 limit => 5, offset => 10
16 );
17  
18 =head1 DESCRIPTION
19  
20 This package provides a subclass of DBIx::SQLEngine which compensates for Postgres's idiosyncrasies.
21  
22 =head2 About Driver Subclasses
23  
24 You do not need to use this package directly; when you connect to a database, the SQLEngine object is automatically re-blessed in to the appropriate subclass.
25  
26 =cut
27  
28 ########################################################################
29  
30 package DBIx::SQLEngine::Driver::Pg;
31  
32 use strict;
33 use Carp;
34  
35 ########################################################################
36  
37 =head2 sql_limit
38  
39 $sqldb->sql_limit( $limit, $offset, $sql, @params ) : $sql, @params
40  
41 Adds support for SQL select limit clause.
42  
43 =cut
44  
45 sub sql_limit {
46 my $self = shift;
47 my ( $limit, $offset, $sql, @params ) = @_;
48  
49 # You can't apply "limit" to non-table fetches like "select LAST_INSERT_ID"
50 if ( $sql =~ /\bfrom\b/i and defined $limit or defined $offset) {
51 $sql .= " limit $limit" if $limit;
52 $sql .= " offset $offset" if $offset;
53 }
54
55 return ($sql, @params);
56 }
57  
58 ########################################################################
59  
60 =head2 do_insert_with_sequence
61  
62 $sqldb->do_insert_with_sequence( $sequence_name, %sql_clauses ) : $row_count
63  
64 Implemented using _seq_do_insert_preinc and seq_increment.
65  
66 =head2 seq_increment
67  
68 $sqldb->seq_increment( $table, $field ) : $new_value
69  
70 Increments the sequence, and returns the newly allocated value.
71  
72 =cut
73  
74 # $rows = $self->do_insert_with_sequence( $sequence, %clauses );
75 sub do_insert_with_sequence {
76 (shift)->_seq_do_insert_preinc( @_ )
77 }
78  
79 # $current_id = $sqldb->seq_increment( $table, $field );
80 sub seq_increment {
81 my ($self, $table, $field) = @_;
82 $self->fetch_one_value(
83 sql => "SELECT nextval('${table}_${field}_seq')"
84 );
85 }
86  
87 ########################################################################
88  
89 =head2 dbms_create_column_types
90  
91 $sqldb->dbms_create_column_types () : %column_type_codes
92  
93 Implemented using Pg's bytea and serial types.
94  
95 =head2 dbms_create_column_text_long_type
96  
97 $sqldb->dbms_create_column_text_long_type () : $col_type_str
98  
99 Implemented using Pg's text type.
100  
101 =cut
102  
103 sub dbms_create_column_types {
104 'sequential' => 'serial',
105 'binary' => 'bytea',
106 }
107  
108 sub dbms_create_column_text_long_type {
109 'text'
110 }
111  
112 ########################################################################
113  
114 =head2 recoverable_query_exceptions
115  
116 $sqldb->recoverable_query_exceptions() : @common_error_messages
117  
118 Provides a list of error messages which represent common
119 communication failures or other incidental errors.
120  
121 =cut
122  
123 sub recoverable_query_exceptions {
124 'backend closed the channel unexpectedly',
125 'there is no connection to the backend',
126 'reconnect to the database system and repeat your query',
127 'no statement executing',
128 'fetch without execute',
129 'field number \d+ is out of range 0\.\.\-1',
130 }
131  
132 ########################################################################
133  
134 =head1 SEE ALSO
135  
136 See L<DBIx::SQLEngine> for the overall interface and developer documentation.
137  
138 See L<DBIx::SQLEngine::Docs::ReadMe> for general information about
139 this distribution, including installation and license information.
140  
141 =cut
142  
143 ########################################################################
144  
145 1;