bugfixes
[DBIx-DBSchema.git] / DBSchema / Column.pm
index b7ab18f..7e2aad2 100644 (file)
@@ -20,6 +20,7 @@ DBIx::DBSchema::Column - Column objects
   $column = new DBIx::DBSchema::Column ( $name, $sql_type, 'NULL' );
   $column = new DBIx::DBSchema::Column ( $name, $sql_type, '', $length );
   $column = new DBIx::DBSchema::Column ( $name, $sql_type, 'NULL', $length );
+  $column = new DBIx::DBSchema::Column ( $name, $sql_type, 'NULL', $length, $local );
 
   $name = $column->name;
   $column->name( 'name' );
@@ -48,17 +49,17 @@ L<DBIx::DBSchema::Table>).
 
 =over 4
 
-=item new [ NAME [ , SQL_TYPE [ , NULL [ , LENGTH ] ] ] ]
+=item new [ NAME [ , SQL_TYPE [ , NULL [ , LENGTH  [ , LOCAL ] ] ] ] ]
 
 Creates a new DBIx::DBSchema::Column object.  NAME is the name of the column.
 SQL_TYPE is the SQL data type.  NULL is the nullability of the column (the
 empty string is equivalent to `NOT NULL').  LENGTH is the SQL length of the
-column.
+column.  LOCAL is reserved for database-specific information.
 
 =cut
 
 sub new {
-  my($proto,$name,$type,$null,$length)=@_;
+  my($proto,$name,$type,$null,$length,$local)=@_;
 
   #croak "Illegal name: $name" if grep $name eq $_, @reserved_words;
 
@@ -71,6 +72,7 @@ sub new {
     'type'   => $type,
     'null'   => $null,
     'length' => $length,
+    'local'  => $local,
   };
 
   bless ($self, $class);
@@ -141,6 +143,21 @@ sub length {
   }
 }
 
+=item local [ LOCAL ]
+
+Returns or sets the database-specific field.
+
+=cut
+
+sub local {
+  my($self,$value)=@_;
+  if ( defined($value) ) {
+    $self->{'local'} = $value;
+  } else {
+    $self->{'local'};
+  }
+}
+
 =item line [ $datasrc ]
 
 Returns an SQL column definition.
@@ -166,6 +183,10 @@ sub line {
     $self->name,
     $self->type. ( $self->length ? '('.$self->length.')' : '' ),
     $null,
+    ( ( $datasrc =~ /^dbi:mysql:/i )
+      ? $self->local
+      : ''
+    ),
   );
 }