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 data‐
62           base-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 equiva‐
77           lent 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).  Typ‐
90           ically 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 pass‐
102           word.
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 `DBI:mysql:data‐
110           base' or `DBI:Pg:dbname=database', will use syntax specific to that
111           database engine.  Currently supported databases are MySQL and Post‐
112           greSQL.  Non-standard syntax for other engines (if applicable) may
113           also be supported in the future.
114
115       sql_add_column [ DBH ]
116           Returns a list of SQL statements to add this column to an existing
117           table.  (To create a new table, see "sql_create_table" in
118           DBIx::DBSchema::Table instead.)
119
120           The data source can be specified by passing an open DBI database
121           handle, or by passing the DBI data source name, username and pass‐
122           word.
123
124           Although the username and password are optional, it is best to call
125           this method with a database handle or data source including a valid
126           username and password - a DBI connection will be opened and the
127           quoting and type mapping will be more reliable.
128
129           If passed a DBI data source (or handle) such as
130           `DBI:Pg:dbname=database', will use PostgreSQL-specific syntax.
131           Non-standard syntax for other engines (if applicable) may also be
132           supported in the future.
133
134       sql_alter_column PROTOTYPE_COLUMN  [ DATABASE_HANDLE ⎪ DATA_SOURCE [
135       USERNAME PASSWORD [ ATTR ] ] ]
136           Returns a list of SQL statements to alter this column so that it is
137           identical to the provided prototype column, also a
138           DBIx::DBSchema::Column object.
139
140            #Optionally, the data source can be specified by passing an open DBI database
141            #handle, or by passing the DBI data source name, username and password.
142            #
143            #If passed a DBI data source (or handle) such as `DBI:Pg:dbname=database', will
144            #use PostgreSQL-specific syntax.  Non-standard syntax for other engines (if
145            #applicable) may also be supported in the future.
146            #
147            #If not passed a data source (or handle), or if there is no driver for the
148            #specified database, will attempt to use generic SQL syntax.
149
150           Or should, someday.  Right now it knows how to change NOT NULL into
151           NULL and vice-versa.
152

AUTHOR

154       Ivan Kohler <ivan-dbix-dbschema@420.am>
155
157       Copyright (c) 2000-2006 Ivan Kohler Copyright (c) 2007 Freeside Inter‐
158       net Services, Inc.  All rights reserved.  This program is free soft‐
159       ware; you can redistribute it and/or modify it under the same terms as
160       Perl itself.
161

BUGS

163       The new() method should warn that "Old-style $class creation without
164       named parameters is deprecated!"
165
166       Better documentation is needed for sql_add_column
167
168       line() and sql_add_column() hav database-specific foo that should be
169       abstracted into the DBIx::DBSchema:DBD:: modules.
170

SEE ALSO

172       DBIx::DBSchema::Table, DBIx::DBSchema, DBIx::DBSchema::DBD, DBI
173
174
175
176perl v5.8.8                       2002-11-29               DBSchema::Column(3)
Impressum