| 1 | package SPOPS::DBI::SQLite; | ||
| 2 | |||
| 3 | # $Id: SQLite.pm,v 3.5 2004/06/02 00:48:22 lachoy Exp $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use Log::Log4perl qw( get_logger ); | ||
| 7 | |||
| 8 | use DBI qw( SQL_VARCHAR ); | ||
| 9 | use SPOPS; | ||
| 10 | use SPOPS::DBI::TypeInfo; | ||
| 11 | use SPOPS::Utility; | ||
| 12 | |||
| 13 | my $log = get_logger(); | ||
| 14 | |||
| 15 | $SPOPS::DBI::SQLite::VERSION = sprintf("%d.%02d", q$Revision: 3.5 $ =~ /(\d+)\.(\d+)/); | ||
| 16 | |||
| 17 | sub sql_current_date { return SPOPS::Utility->now } | ||
| 18 | |||
| 19 | |||
| 20 | ######################################## | ||
| 21 | # KEY GENERATION | ||
| 22 | |||
| 23 | sub pre_fetch_id { return undef } | ||
| 24 | |||
| 25 | sub post_fetch_id { | ||
| 26 | my ( $class, $p ) = @_; | ||
| 27 | return undef unless ( $class->CONFIG->{increment_field} ); | ||
| 28 | return $p->{db}->func( 'last_insert_rowid' ); | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | ######################################## | ||
| 33 | # TYPE MAPPING | ||
| 34 | |||
| 35 | # Since SQLite is typeless, just assume everything is a text field | ||
| 36 | |||
| 37 | my %TYPE_INFO = (); | ||
| 38 | |||
| 39 | sub db_discover_types { | ||
| 40 | my ( $class, $table, $p ) = @_; | ||
| 41 | my $db = $p->{db} || $class->global_datasource_handle; | ||
| 42 | my $type_idx = join( '-', lc $db->{Name}, lc $table ); | ||
| 43 | unless ( $TYPE_INFO{ $type_idx } ) { | ||
| 44 | my $fields = $class->field_list; | ||
| 45 | my $type_info = SPOPS::DBI::TypeInfo->new({ database => $db->{Name}, | ||
| 46 | table => $table }); | ||
| 47 | foreach my $field ( @{ $fields } ) { | ||
| 48 | $type_info->add_type( $field, SQL_VARCHAR ); | ||
| 49 | } | ||
| 50 | $TYPE_INFO{ $type_idx } = $type_info; | ||
| 51 | } | ||
| 52 | return $TYPE_INFO{ $type_idx } | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | __END__ |