| 1 | =head1 NAME | ||
| 2 | |||
| 3 | DBIx::SQLEngine::Driver::SQLite - Support DBD::SQLite driver | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | B<DBI Wrapper>: Adds methods to a DBI database handle. | ||
| 8 | |||
| 9 | my $sqldb = DBIx::SQLEngine->new( 'dbi:SQLite:dbname=mydatafile.sqlite' ); | ||
| 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 SQLite'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::SQLite; | ||
| 31 | |||
| 32 | use strict; | ||
| 33 | use Carp; | ||
| 34 | |||
| 35 | ######################################################################## | ||
| 36 | |||
| 37 | =head2 sql_limit | ||
| 38 | |||
| 39 | Adds support for SQL select limit clause. | ||
| 40 | |||
| 41 | =cut | ||
| 42 | |||
| 43 | sub sql_limit { | ||
| 44 | my $self = shift; | ||
| 45 | my ( $limit, $offset, $sql, @params ) = @_; | ||
| 46 | |||
| 47 | # You can't apply "limit" to non-table fetches like "select LAST_INSERT_ID" | ||
| 48 | if ( $sql =~ /\bfrom\b/i and defined $limit or defined $offset) { | ||
| 49 | $sql .= " limit $limit" if $limit; | ||
| 50 | $sql .= " offset $offset" if $offset; | ||
| 51 | } | ||
| 52 | |||
| 53 | return ($sql, @params); | ||
| 54 | } | ||
| 55 | |||
| 56 | ######################################################################## | ||
| 57 | |||
| 58 | =head2 do_insert_with_sequence | ||
| 59 | |||
| 60 | $sqldb->do_insert_with_sequence( $sequence_name, %sql_clauses ) : $row_count | ||
| 61 | |||
| 62 | Implemented using _seq_do_insert_postfetch and seq_fetch_current. | ||
| 63 | |||
| 64 | =head2 seq_fetch_current | ||
| 65 | |||
| 66 | $sqldb->seq_fetch_current( ) : $current_value | ||
| 67 | |||
| 68 | Implemented using SQLite's dbh_func() "last_insert_rowid". Note that this | ||
| 69 | doesn't fetch the current sequence value for a given table, since | ||
| 70 | it doesn't respect the table and field arguments, but merely returns | ||
| 71 | the last sequencial value created during this session. | ||
| 72 | |||
| 73 | =cut | ||
| 74 | |||
| 75 | # $rows = $self->do_insert_with_sequence( $sequence, %clauses ); | ||
| 76 | sub do_insert_with_sequence { | ||
| 77 | (shift)->_seq_do_insert_postfetch( @_ ) | ||
| 78 | } | ||
| 79 | |||
| 80 | # $current_id = $sqldb->seq_fetch_current( ); | ||
| 81 | sub seq_fetch_current { | ||
| 82 | my $self = shift; | ||
| 83 | $self->dbh_func('last_insert_rowid'); | ||
| 84 | } | ||
| 85 | |||
| 86 | ######################################################################## | ||
| 87 | |||
| 88 | =head2 detect_any | ||
| 89 | |||
| 90 | $sqldb->detect_any ( ) : $boolean | ||
| 91 | |||
| 92 | Returns 1, as we presume that the requisite driver modules are | ||
| 93 | available or we wouldn't have reached this point. | ||
| 94 | |||
| 95 | =head2 sql_detect_table | ||
| 96 | |||
| 97 | $sqldb->sql_detect_table ( $tablename ) : %sql_select_clauses | ||
| 98 | |||
| 99 | Implemented using SQLite's "select * from $tablename limit 1". | ||
| 100 | |||
| 101 | =cut | ||
| 102 | |||
| 103 | sub detect_any { | ||
| 104 | return 1; | ||
| 105 | } | ||
| 106 | |||
| 107 | sub sql_detect_table { | ||
| 108 | my ($self, $tablename) = @_; | ||
| 109 | return ( sql => "select * from $tablename limit 1" ); | ||
| 110 | } | ||
| 111 | |||
| 112 | ######################################################################## | ||
| 113 | |||
| 114 | =head2 dbms_create_column_types | ||
| 115 | |||
| 116 | $sqldb->dbms_create_column_types () : %column_type_codes | ||
| 117 | |||
| 118 | Implemented using SQLite's blob and int auto_increment types. | ||
| 119 | |||
| 120 | =head2 dbms_create_column_text_long_type | ||
| 121 | |||
| 122 | $sqldb->dbms_create_column_text_long_type () : $col_type_str | ||
| 123 | |||
| 124 | Implemented using SQLite's blob type. | ||
| 125 | |||
| 126 | =cut | ||
| 127 | |||
| 128 | sub dbms_create_column_types { | ||
| 129 | 'sequential' => 'integer primary key', | ||
| 130 | 'binary' => 'blob', | ||
| 131 | } | ||
| 132 | |||
| 133 | sub dbms_create_column_text_long_type { | ||
| 134 | 'blob' | ||
| 135 | } | ||
| 136 | |||
| 137 | ######################################################################## | ||
| 138 | |||
| 139 | =head2 dbms_column_types_unsupported | ||
| 140 | |||
| 141 | $sqldb->dbms_column_types_unsupported () : 1 | ||
| 142 | |||
| 143 | Capability Limitation: This driver does not store column type information. | ||
| 144 | |||
| 145 | =head2 dbms_indexes_unsupported | ||
| 146 | |||
| 147 | $sqldb->dbms_indexes_unsupported () : 1 | ||
| 148 | |||
| 149 | Capability Limitation: This driver does not support indexes. | ||
| 150 | |||
| 151 | =head2 dbms_storedprocs_unsupported | ||
| 152 | |||
| 153 | $sqldb->dbms_storedprocs_unsupported () : 1 | ||
| 154 | |||
| 155 | Capability Limitation: This driver does not support stored procedures. | ||
| 156 | |||
| 157 | =head2 dbms_detect_tables_unsupported | ||
| 158 | |||
| 159 | $sqldb->dbms_detect_tables_unsupported () : 1 | ||
| 160 | |||
| 161 | Capability Limitation: This driver does not return a list of available tables. | ||
| 162 | |||
| 163 | =cut | ||
| 164 | |||
| 165 | use DBIx::SQLEngine::Driver::Trait::NoColumnTypes ':all'; | ||
| 166 | |||
| 167 | sub dbms_indexes_unsupported { 1 } | ||
| 168 | sub dbms_storedprocs_unsupported { 1 } | ||
| 169 | |||
| 170 | sub dbms_detect_tables_unsupported { 1 } | ||
| 171 | |||
| 172 | ######################################################################## | ||
| 173 | |||
| 174 | # sub catch_query_exception { | ||
| 175 | # if ( $error =~ /\Q{TYPE}: unrecognised attribute\E/i ) { | ||
| 176 | # This means the query failed; we'll return nothing. | ||
| 177 | # return 'OK'; | ||
| 178 | # } | ||
| 179 | |||
| 180 | ######################################################################## | ||
| 181 | |||
| 182 | =head1 SEE ALSO | ||
| 183 | |||
| 184 | See L<DBIx::SQLEngine> for the overall interface and developer documentation. | ||
| 185 | |||
| 186 | See L<DBIx::SQLEngine::Docs::ReadMe> for general information about | ||
| 187 | this distribution, including installation and license information. | ||
| 188 | |||
| 189 | =cut | ||
| 190 | |||
| 191 | ######################################################################## | ||
| 192 | |||
| 193 | 1; |