1 package DBIx::DBSchema::Column;
13 DBIx::DBSchema::Column - Column objects
17 use DBIx::DBSchema::Column;
19 $column = new DBIx::DBSchema::Column ( $name, $sql_type, '' );
20 $column = new DBIx::DBSchema::Column ( $name, $sql_type, 'NULL' );
21 $column = new DBIx::DBSchema::Column ( $name, $sql_type, '', $length );
22 $column = new DBIx::DBSchema::Column ( $name, $sql_type, 'NULL', $length );
24 $name = $column->name;
25 $column->name( 'name' );
27 $sql_type = $column->type;
28 $column->sql_type( 'sql_type' );
30 $null = $column->null;
31 $column->null( 'NULL' );
32 $column->null( 'NOT NULL' );
35 $length = $column->length;
36 $column->length( '10' );
37 $column->length( '8,2' );
39 $sql_line = $column->line;
40 $sql_line = $column->line($datasrc);
44 DBIx::DBSchema::Column objects represent columns in tables (see
45 L<DBIx::DBSchema::Table>).
51 =item new [ NAME [ , SQL_TYPE [ , NULL [ , LENGTH ] ] ] ]
53 Creates a new DBIx::DBSchema::Column object. NAME is the name of the column.
54 SQL_TYPE is the SQL data type. NULL is the nullability of the column (the
55 empty string is equivalent to `NOT NULL'). LENGTH is the SQL length of the
61 my($proto,$name,$type,$null,$length)=@_;
63 #croak "Illegal name: $name" if grep $name eq $_, @reserved_words;
65 $null =~ s/^NOT NULL$//i;
66 $null = 'NULL' if $null;
68 my $class = ref($proto) || $proto;
76 bless ($self, $class);
82 Returns or sets the column name.
88 if ( defined($value) ) {
89 #croak "Illegal name: $name" if grep $name eq $_, @reserved_words;
90 $self->{'name'} = $value;
98 Returns or sets the column type.
104 if ( defined($value) ) {
105 $self->{'type'} = $value;
113 Returns or sets the column null flag (the empty string is equivalent to
120 if ( defined($value) ) {
121 $value =~ s/^NOT NULL$//i;
122 $value = 'NULL' if $value;
123 $self->{'null'} = $value;
129 =item length [ LENGTH ]
131 Returns or sets the column length.
137 if ( defined($value) ) {
138 $self->{'length'} = $value;
144 =item line [ $datasrc ]
146 Returns an SQL column definition.
148 If passed a DBI data source such as `DBI:mysql:database' or
149 `DBI:Pg:dbname=database', will use syntax specific to that database engine.
150 Currently supported databases are MySQL and PostgreSQL. Non-standard syntax
151 for other engines (if applicable) may also be supported in the future.
156 my($self,$datasrc)=@_;
157 my($null)=$self->null;
158 if ( $datasrc =~ /^dbi:mysql:/i ) { #yucky mysql hack
161 if ( $datasrc =~ /^dbi:pg/i ) { #yucky Pg hack
162 $null ||= "NOT NULL";
167 $self->type. ( $self->length ? '('.$self->length.')' : '' ),
176 Ivan Kohler <ivan-dbix-dbschema@420.am>
180 Copyright (c) 2000 Ivan Kohler
181 Copyright (c) 2000 Mail Abuse Prevention System LLC
183 This program is free software; you can redistribute it and/or modify it under
184 the same terms as Perl itself.
188 line() has database-specific foo that probably ought to be abstracted into
189 the DBIx::DBSchema:DBD:: modules.
193 L<DBIx::DBSchema::Table>, L<DBIx::DBSchema>, L<DBIx::DBSchema::DBD>, L<DBI>