1 package SQL::Translator::Producer;
3 # -------------------------------------------------------------------
4 # Copyright (C) 2002-4 SQLFairy Authors
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.
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.
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
19 # -------------------------------------------------------------------
22 use vars qw($VERSION);
27 # Do not rely on this if you are not bundled with SQL::Translator.
29 ## $exceptions contains an arrayref of paired values
30 ## Each pair contains a pattern match or string, and a value to be used as
31 ## the default if matched.
32 ## They are special per Producer, and provide support for the old 'now()'
33 ## default value exceptions
34 sub _apply_default_value {
35 my (undef, $field_ref, $default, $exceptions) = @_;
37 if ($exceptions and ! ref $default) {
38 for (my $i = 0; $i < @$exceptions; $i += 2) {
39 my ($pat, $val) = @$exceptions[ $i, $i + 1 ];
40 if (ref $pat and $default =~ $pat) {
43 } elsif (lc $default eq lc $pat) {
51 $$field_ref .= " DEFAULT $$default";
53 $$field_ref .= " DEFAULT '$default'";
60 # -------------------------------------------------------------------
61 # A burnt child loves the fire.
63 # -------------------------------------------------------------------
69 SQL::Translator::Producer - describes how to write a producer
73 Producer modules designed to be used with SQL::Translator need to
74 implement a single function, called B<produce>. B<produce> will be
75 called with the SQL::Translator object from which it is expected to
76 retrieve the SQL::Translator::Schema object which has been populated
77 by the parser. It is expected to return a string.
85 =item create_table($table)
87 =item create_field($field)
89 =item create_view($view)
91 =item create_index($index)
93 =item create_constraint($constraint)
95 =item create_trigger($trigger)
97 =item alter_field($from_field, $to_field)
99 =item add_field($table, $new_field)
101 =item drop_field($table, $old_field)
105 Darren Chamberlain E<lt>darren@cpan.orgE<gt>,
106 Ken Y. Clark E<lt>kclark@cpan.orgE<gt>.
110 perl(1), SQL::Translator, SQL::Translator::Schema.