Changeset 1521

Show
Ignore:
Timestamp:
03/17/05 18:18:11
Author:
miyagawa
Message:

0.08

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Class-DBI-SQLite/trunk/Changes

    r1520 r1521  
    11Revision history for Perl extension Class::DBI::SQLite 
     2 
     30.08  Thu Mar 17 18:17:34 JST 2005 
     4        - Kiss SQL::Parser goodbye 
     5          (Markus Ramberg) 
    26 
    370.07  Fri Jan 28 03:02:10 JST 2005 
  • Class-DBI-SQLite/trunk/Makefile.PL

    r1499 r1521  
    88        'Ima::DBI'   => 0.27, 
    99        'DBD::SQLite' => 0.07, 
    10         'SQL::Parser' => 1.004, 
    11         'SQL::Dialects::AnyData' => 0, 
    1210    }, 
    1311); 
  • Class-DBI-SQLite/trunk/lib/Class/DBI/SQLite.pm

    r1520 r1521  
    33use strict; 
    44use vars qw($VERSION); 
    5 $VERSION = 0.07
     5$VERSION = "0.08"
    66 
    77require Class::DBI; 
    88use base qw(Class::DBI); 
    9 use SQL::Statement; 
    109 
    1110sub _auto_increment_value { 
     
    3332    my($sql) = $sth->fetchrow_array; 
    3433    $sth->finish; 
    35  
    36     # sri: Needed for auto relationships with Class::DBI::Loader 
    37     $sql =~ s/REFERENCES\s+\w+//gsi; 
    38  
    39     my $parser = SQL::Parser->new('AnyData', { RaiseError => 1}); 
    40     $parser->feature("valid_data_types","TIMESTAMP",1); 
    41     $parser->parse($sql); 
    42     my $structure = $parser->structure; 
    43     my $primary; 
    44     foreach my $key (keys %{$structure->{column_defs}}) { 
    45         my $def = $structure->{column_defs}->{$key}; 
    46         next unless $def->{constraints}; 
    47         foreach my $constraint(@{$def->{constraints}}) { 
    48             if (uc($constraint) eq 'PRIMARY KEY') { 
    49                 $primary = $key; 
    50                 last; 
    51             } 
    52         } 
     34    my ($primary) = $sql =~ m/ 
     35    (?:\(|\,) # either a ( to start the definition or a , for next  
     36    \s* # maybe some whitespace 
     37    (\w+) # the col name 
     38    [^,]* #anything but the end or a ',' for next column 
     39    PRIMARY\sKEY/sxi; 
     40    my @mpks; 
     41    unless ($primary) {  
     42        my ($mpks)= $sql =~ m/PRIMARY\s+KEY\s*\(\s*(.+)\s*\)/; 
     43        @mpks = split m/\s*\,\s*/,$mpks; 
    5344    } 
    5445    $class->table($table); 
    5546    $class->columns(All => @columns); 
    56     $class->columns(Primary => $primary); 
     47    $class->columns(Primary => $primary || @mpks); 
    5748} 
    5849 
     
    8576 
    8677C<set_up_table> method allows you to automate the setup of columns and 
    87 primary key by using of SQLite PRAGMA statement (with SQL::Statement 
    88 module) 
     78primary key by using of SQLite PRAGMA statement  
    8979 
    9080=head1 AUTHOR 
     
    9989=head1 SEE ALSO 
    10090 
    101 L<Class::DBI>, L<DBD::SQLite> L<SQL::Statement> 
     91L<Class::DBI>, L<DBD::SQLite>  
    10292 
    10393=cut