1DBSchema::Column(3)   User Contributed Perl Documentation  DBSchema::Column(3)
2
3
4

NAME

6       DBIx::DBSchema::Column - Column objects
7

SYNOPSIS

9         use DBIx::DBSchema::Column;
10
11         #named params with a hashref (preferred)
12         $column = new DBIx::DBSchema::Column ( {
13           'name'    => 'column_name',
14           'type'    => 'varchar'
15           'null'    => 'NOT NULL',
16           'length'  => 64,
17           'default' => '',
18           'local'   => '',
19         } );
20
21         #list
22         $column = new DBIx::DBSchema::Column ( $name, $sql_type, $nullability, $length, $default, $local );
23
24         $name = $column->name;
25         $column->name( 'name' );
26
27         $sql_type = $column->type;
28         $column->type( 'sql_type' );
29
30         $null = $column->null;
31         $column->null( 'NULL' );
32         $column->null( 'NOT NULL' );
33         $column->null( '' );
34
35         $length = $column->length;
36         $column->length( '10' );
37         $column->length( '8,2' );
38
39         $default = $column->default;
40         $column->default( 'Roo' );
41
42         $sql_line = $column->line;
43         $sql_line = $column->line($datasrc);
44
45         $sql_add_column = $column->sql_add_column;
46         $sql_add_column = $column->sql_add_column($datasrc);
47

DESCRIPTION

49       DBIx::DBSchema::Column objects represent columns in tables (see
50       DBIx::DBSchema::Table).
51

METHODS

53       new HASHREF
54       new [ name [ , type [ , null [ , length  [ , default [ , local ] ] ] ]
55       ] ]
56           Creates a new DBIx::DBSchema::Column object.  Takes a hashref of
57           named parameters, or a list.  name is the name of the column.  type
58           is the SQL data type.  null is the nullability of the column
59           (intrepreted using Perl's rules for truth, with one exception: `NOT
60           NULL' is false).  length is the SQL length of the column.  default
61           is the default value of the column.  local is reserved for
62           database-specific information.
63
64           Note: If you pass a scalar reference as the default rather than a
65           scalar value, it will be dereferenced and quoting will be forced
66           off.  This can be used to pass SQL functions such as "now()" or
67           explicit empty strings as '' as defaults.
68
69       name [ NAME ]
70           Returns or sets the column name.
71
72       type [ TYPE ]
73           Returns or sets the column type.
74
75       null [ NULL ]
76           Returns or sets the column null flag (the empty string is
77           equivalent to `NOT NULL')
78
79       length [ LENGTH ]
80           Returns or sets the column length.
81
82       default [ LOCAL ]
83           Returns or sets the default value.
84
85       local [ LOCAL ]
86           Returns or sets the database-specific field.
87
88       table_obj [ TABLE_OBJ ]
89           Returns or sets the table object (see DBIx::DBSchema::Table).
90           Typically set internally when a column object is added to a table
91           object.
92
93       table_name
94           Returns the table name, or the empty string if this column has not
95           yet been assigned to a table.
96
97       line [ DATABASE_HANDLE | DATA_SOURCE [ USERNAME PASSWORD [ ATTR ] ] ]
98           Returns an SQL column definition.
99
100           The data source can be specified by passing an open DBI database
101           handle, or by passing the DBI data source name, username and
102           password.
103
104           Although the username and password are optional, it is best to call
105           this method with a database handle or data source including a valid
106           username and password - a DBI connection will be opened and the
107           quoting and type mapping will be more reliable.
108
109           If passed a DBI data source (or handle) such as
110           `DBI:mysql:database' or `DBI:Pg:dbname=database', will use syntax
111           specific to that database engine.  Currently supported databases
112           are MySQL and PostgreSQL.  Non-standard syntax for other engines
113           (if applicable) may also be supported in the future.
114
115       quoted_default DATABASE_HANDLE
116           Returns this column's default value quoted for the database.
117
118       sql_add_column [ DBH ]
119           Returns a list of SQL statements to add this column to an existing
120           table.  (To create a new table, see "sql_create_table" in
121           DBIx::DBSchema::Table instead.)
122
123           The data source can be specified by passing an open DBI database
124           handle, or by passing the DBI data source name, username and
125           password.
126
127           Although the username and password are optional, it is best to call
128           this method with a database handle or data source including a valid
129           username and password - a DBI connection will be opened and the
130           quoting and type mapping will be more reliable.
131
132           If passed a DBI data source (or handle) such as
133           `DBI:Pg:dbname=database', will use PostgreSQL-specific syntax.
134           Non-standard syntax for other engines (if applicable) may also be
135           supported in the future.
136
137       sql_alter_column PROTOTYPE_COLUMN  [ DATABASE_HANDLE | DATA_SOURCE [
138       USERNAME PASSWORD [ ATTR ] ] ]
139           Returns a list of SQL statements to alter this column so that it is
140           identical to the provided prototype column, also a
141           DBIx::DBSchema::Column object.
142
143           Optionally, the data source can be specified by passing an open DBI
144           database handle, or by passing the DBI data source name, username
145           and password.
146
147           If passed a DBI data source (or handle) such as
148           `DBI:Pg:dbname=database', will use PostgreSQL-specific syntax.
149           Non-standard syntax for other engines (if applicable) may also be
150           supported in the future.
151
152           If not passed a data source (or handle), or if there is no driver
153           for the specified database, will attempt to use generic SQL syntax.
154
155       sql_drop_column [ DBH ]
156           Returns a list of SQL statements to drop this column from an
157           existing table.
158
159           The optional database handle or DBI data source/username/password
160           is not yet used.
161

AUTHOR

163       Ivan Kohler <ivan-dbix-dbschema@420.am>
164
166       Copyright (c) 2000-2006 Ivan Kohler Copyright (c) 2007-2010 Freeside
167       Internet Services, Inc.  All rights reserved.  This program is free
168       software; you can redistribute it and/or modify it under the same terms
169       as Perl itself.
170

BUGS

172       The new() method should warn that "Old-style $class creation without
173       named parameters is deprecated!"
174
175       Better documentation is needed for sql_add_column
176
177       sql_alter_column() has database-specific foo that should be abstracted
178       info DBIx::DBSchema::DBD::Pg
179
180       nullify_default option should be documented
181

SEE ALSO

183       DBIx::DBSchema::Table, DBIx::DBSchema, DBIx::DBSchema::DBD, DBI
184
185
186
187perl v5.12.1                      2010-03-27               DBSchema::Column(3)
Impressum