Commit | Line | Data |
6a9f7bae |
1 | package SQL::Translator::Parser::DBI::SQLite; |
2 | |
3 | # ------------------------------------------------------------------- |
4 | # $Id: SQLite.pm,v 1.1 2003-10-03 00:21:41 kycl4rk Exp $ |
5 | # ------------------------------------------------------------------- |
6 | # Copyright (C) 2003 Ken Y. Clark <kclark@cpan.org>. |
7 | # |
8 | # This program is free software; you can redistribute it and/or |
9 | # modify it under the terms of the GNU General Public License as |
10 | # published by the Free Software Foundation; version 2. |
11 | # |
12 | # This program is distributed in the hope that it will be useful, but |
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | # General Public License for more details. |
16 | # |
17 | # You should have received a copy of the GNU General Public License |
18 | # along with this program; if not, write to the Free Software |
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
20 | # 02111-1307 USA |
21 | # ------------------------------------------------------------------- |
22 | |
23 | =head1 NAME |
24 | |
25 | SQL::Translator::Parser::DBI::SQLite - parser for DBD::SQLite |
26 | |
27 | =head1 SYNOPSIS |
28 | |
29 | See SQL::Translator::Parser::DBI. |
30 | |
31 | =head1 DESCRIPTION |
32 | |
33 | Queries the "sqlite_master" table for schema definition. |
34 | |
35 | =cut |
36 | |
37 | use strict; |
38 | use DBI; |
39 | use SQL::Translator::Parser::SQLite; |
40 | use Data::Dumper; |
41 | |
42 | use vars qw[ $DEBUG $VERSION @EXPORT_OK ]; |
43 | $VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/; |
44 | $DEBUG = 0 unless defined $DEBUG; |
45 | |
46 | # ------------------------------------------------------------------- |
47 | sub parse { |
48 | my ( $tr, $dbh ) = @_; |
49 | |
50 | my $data = $dbh->selectall_arrayref( |
51 | 'select * from sqlite_master', { Columns => {} } |
52 | ); |
53 | |
54 | $tr->debug( "sqlite_master =\n", Dumper( $data ) ); |
55 | |
56 | my $schema = $tr->schema; |
57 | |
58 | my $create; |
59 | for my $rec ( @$data ) { |
60 | my $sql = $rec->{'sql'} or next; |
61 | $create .= "$sql;\n"; |
62 | } |
63 | |
64 | $tr->debug( "create =\n$create\n" ); |
65 | |
66 | SQL::Translator::Parser::SQLite::parse( $tr, $create ); |
67 | return 1; |
68 | } |
69 | |
70 | 1; |
71 | |
72 | # ------------------------------------------------------------------- |
73 | # Where man is not nature is barren. |
74 | # William Blake |
75 | # ------------------------------------------------------------------- |
76 | |
77 | =pod |
78 | |
79 | =head1 AUTHOR |
80 | |
81 | Ken Y. Clark E<lt>kclark@cpan.orgE<gt>, |
82 | Chris Mungall E<lt>cjm@fruitfly.orgE<gt>. |
83 | |
84 | =head1 SEE ALSO |
85 | |
86 | perl(1), Parse::RecDescent, SQL::Translator::Schema. |
87 | |
88 | =cut |