e88bd9bd41e44aa79e6a14f3294a00ab8fb30ed9
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / DBI / SQLite.pm
1 package SQL::Translator::Parser::DBI::SQLite;
2
3 # -------------------------------------------------------------------
4 # Copyright (C) 2002-2009 SQLFairy Authors
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; version 2.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 # 02111-1307  USA
19 # -------------------------------------------------------------------
20
21 =head1 NAME
22
23 SQL::Translator::Parser::DBI::SQLite - parser for DBD::SQLite
24
25 =head1 SYNOPSIS
26
27 See SQL::Translator::Parser::DBI.
28
29 =head1 DESCRIPTION
30
31 Queries the "sqlite_master" table for schema definition.  The schema
32 is held in this table simply as CREATE statements for the database
33 objects, so it really just builds up a string of all these and passes
34 the result to the regular SQLite parser.  Therefore there is no gain
35 (at least in performance) to using this module over simply dumping the
36 schema to a text file and parsing that.
37
38 =cut
39
40 use strict;
41 use DBI;
42 use SQL::Translator::Parser::SQLite;
43 use Data::Dumper;
44
45 use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
46 $VERSION = '1.59';
47 $DEBUG   = 0 unless defined $DEBUG;
48
49 sub parse {
50     my ( $tr, $dbh ) = @_;
51
52     my $create = join(";\n",
53         map { $_ || () }
54         @{ $dbh->selectcol_arrayref('select sql from sqlite_master') },
55     );
56     $create .= ";";
57     $tr->debug( "create =\n$create\n" );
58
59     my $schema = $tr->schema;
60
61     SQL::Translator::Parser::SQLite::parse( $tr, $create );
62     return 1;
63 }
64
65 1;
66
67 # -------------------------------------------------------------------
68 # Where man is not nature is barren.
69 # William Blake
70 # -------------------------------------------------------------------
71
72 =pod
73
74 =head1 AUTHOR
75
76 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
77
78 =head1 SEE ALSO
79
80 SQL::Translator::Parser::SQLite.
81
82 =cut