[Jifty-commit] r1978 - in jifty/trunk: lib/Jifty/Script

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Sep 15 22:08:09 EDT 2006


Author: jesse
Date: Fri Sep 15 22:08:07 2006
New Revision: 1978

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/META.yml
   jifty/trunk/Makefile.PL
   jifty/trunk/lib/Jifty/Script/Schema.pm

Log:
 r27545 at pinglin:  jesse | 2006-09-16 03:07:39 +0100
 * Added support for SQL::ReservedWords to the schema tool, to stop me from building applications for Postgres on SQLite and hurting myself later


Modified: jifty/trunk/META.yml
==============================================================================
--- jifty/trunk/META.yml	(original)
+++ jifty/trunk/META.yml	Fri Sep 15 22:08:07 2006
@@ -79,6 +79,7 @@
   Params::Validate: 0
   PerlIO::gzip: 0
   Pod::Simple: 0
+  SQL::ReservedWords: 0
   Scalar::Defer: 0.06
   Shell::Command: 0
   String::Koremutake: 0

Modified: jifty/trunk/Makefile.PL
==============================================================================
--- jifty/trunk/Makefile.PL	(original)
+++ jifty/trunk/Makefile.PL	Fri Sep 15 22:08:07 2006
@@ -54,6 +54,7 @@
 requires('Scalar::Defer' => '0.06');
 requires('Shell::Command');
 requires('String::Koremutake');
+requires('SQL::ReservedWords');
 requires('UNIVERSAL::require');
 requires('URI');
 requires('XML::Writer');

Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm	Fri Sep 15 22:08:07 2006
@@ -8,6 +8,30 @@
 use version;
 use Jifty::DBI::SchemaGenerator;
 use Jifty::Config;
+use SQL::ReservedWords;
+
+Module::Pluggable->import(
+    require     => 1,
+    search_path => [ "SQL::ReservedWords"],
+    sub_name => '_sql_dialects',
+);  
+        
+            
+
+our %_SQL_RESERVED = ();
+our @_SQL_RESERVED_OVERRIDE = qw(value);
+foreach my $dialect ( 'SQL::ReservedWords', &_sql_dialects ) {
+    foreach my $word ( $dialect->words ) {
+        push @{ $_SQL_RESERVED{ lc($word) } }, $dialect->reserved_by($word);
+    }
+}
+
+# XXX TODO: QUESTIONABLE ENGINEERING DECISION
+# The SQL standard forbids columns named 'value', but just about everone on the planet 
+# actually supports it. Rather than going about scaremongering, we choose
+# not to warn people about columns named 'value'
+
+delete $_SQL_RESERVED{lc($_)} for (@_SQL_RESERVED_OVERRIDE);
 
 =head2 options
 
@@ -21,6 +45,7 @@
         "setup"             => "setup_tables",
         "print|p"           => "print",
         "create-database|c" => "create_database",
+        "ignore-reserved-words" => "ignore_reserved",
         "drop-database"     => "drop_database",
         "help|?"            => "help",
         "man"               => "man"
@@ -207,7 +232,14 @@
         $log->info("Using $model");
         my $ret = $self->{'_schema_generator'}->add_model( $model->new );
         $ret or die "couldn't add model $model: " . $ret->error_message;
+        unless ($self->{'ignore_reserved'}) {
+                $self->_check_reserved($model);
+        }
+
+
     }
+     
+
 
     if ( $self->{'print'} ) {
         print $self->{'_schema_generator'}->create_table_sql_text;
@@ -483,6 +515,21 @@
     Jifty->handle->connect();
 }
 
+
+sub _check_reserved {
+    my $self  = shift;
+    my $model = shift;
+    my $log   = Log::Log4perl->get_logger("SchemaTool");
+    foreach my $col ( $model->columns ) {
+        if ( exists $_SQL_RESERVED{ lc( $col->name ) } ) {
+            $log->error( $model . ": "
+                    . $col->name
+                    . " is a reserved word in these SQL dialects: "
+                    . join( ', ', @{ $_SQL_RESERVED{ lc( $col->name ) } } ) );
+        }
+    }
+}
+
 1;
 
 __DATA__


More information about the Jifty-commit mailing list