X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FSQL%2FTranslator%2FProducer.pm;h=450eb642bcf05f808d25a3e6be6ef9a18954e691;hb=782b5a43519d2713171767f74a544fe9892542ea;hp=28d6d0e99a668bd66447f4c46180c34f4fc8042c;hpb=077ebf34f9c9218e6381e211613b6f41dd3a0ec3;p=dbsrgits%2FSQL-Translator.git diff --git a/lib/SQL/Translator/Producer.pm b/lib/SQL/Translator/Producer.pm index 28d6d0e..450eb64 100644 --- a/lib/SQL/Translator/Producer.pm +++ b/lib/SQL/Translator/Producer.pm @@ -1,10 +1,9 @@ package SQL::Translator::Producer; -#----------------------------------------------------- -# $Id: Producer.pm,v 1.1.1.1.2.1 2002-03-15 20:13:46 dlc Exp $ -#----------------------------------------------------- -# Copyright (C) 2002 Ken Y. Clark , -# darren chamberlain +# ------------------------------------------------------------------- +# $Id$ +# ------------------------------------------------------------------- +# Copyright (C) 2002-4 SQLFairy Authors # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as @@ -23,38 +22,93 @@ package SQL::Translator::Producer; use strict; use vars qw($VERSION); -$VERSION = sprintf "%d.%02d", q$Revision: 1.1.1.1.2.1 $ =~ /(\d+)\.(\d+)/; +$VERSION = '1.99'; sub produce { "" } +# Do not rely on this if you are not bundled with SQL::Translator. +# -- rjbs, 2008-09-30 +## $exceptions contains an arrayref of paired values +## Each pair contains a pattern match or string, and a value to be used as +## the default if matched. +## They are special per Producer, and provide support for the old 'now()' +## default value exceptions +sub _apply_default_value { + my (undef, $field_ref, $default, $exceptions) = @_; + + if ($exceptions and ! ref $default) { + for (my $i = 0; $i < @$exceptions; $i += 2) { + my ($pat, $val) = @$exceptions[ $i, $i + 1 ]; + if (ref $pat and $default =~ $pat) { + $default = $val; + last; + } elsif (lc $default eq lc $pat) { + $default = $val; + last + } + } + } + + if (ref $default) { + $$field_ref .= " DEFAULT $$default"; + } else { + $$field_ref .= " DEFAULT '$default'"; + } + +} + 1; -#----------------------------------------------------- +# ------------------------------------------------------------------- # A burnt child loves the fire. # Oscar Wilde -#----------------------------------------------------- - -=head1 NAME +# ------------------------------------------------------------------- -SQL::Translator::Producer - base object for Producers +=pod -=head1 SYNOPSIS +=head1 NAME +SQL::Translator::Producer - describes how to write a producer =head1 DESCRIPTION Producer modules designed to be used with SQL::Translator need to implement a single function, called B. B will be -called with a data structure created by a SQL::Translator::Parser -subclass. It is expected to return a string containing a valid SQL -create statement. +called with the SQL::Translator object from which it is expected to +retrieve the SQL::Translator::Schema object which has been populated +by the parser. It is expected to return a string. + +=head1 METHODS + +=over 4 + +=item produce + +=item create_table($table) + +=item create_field($field) + +=item create_view($view) + +=item create_index($index) + +=item create_constraint($constraint) + +=item create_trigger($trigger) + +=item alter_field($from_field, $to_field) + +=item add_field($table, $new_field) + +=item drop_field($table, $old_field) -=head1 AUTHOR +=head1 AUTHORS -Ken Y. Clark, kclark@logsoft.com +Darren Chamberlain Edarren@cpan.orgE, +Ken Y. Clark Ekclark@cpan.orgE. =head1 SEE ALSO -perl(1). +perl(1), SQL::Translator, SQL::Translator::Schema. =cut