1DBSchema::Column(3) User Contributed Perl Documentation DBSchema::Column(3)
2
3
4
6 DBIx::DBSchema::Column - Column objects
7
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
49 DBIx::DBSchema::Column objects represent columns in tables (see
50 DBIx::DBSchema::Table).
51
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 SQL to add this column to an existing table. (To create a
120 new table, see "sql_create_table" in DBIx::DBSchema::Table
121 instead.)
122
123 NOTE: This interface has changed in 0.41
124
125 Returns two listrefs. The first is a list of column alteration SQL
126 fragments for an ALTER TABLE statement. The second is a list of
127 full SQL statements that should be run after the ALTER TABLE
128 statement.
129
130 The data source can be specified by passing an open DBI database
131 handle, or by passing the DBI data source name, username and
132 password.
133
134 Although the username and password are optional, it is best to call
135 this method with a database handle or data source including a valid
136 username and password - a DBI connection will be opened and the
137 quoting and type mapping will be more reliable.
138
139 If passed a DBI data source (or handle) such as
140 `DBI:Pg:dbname=database', will use PostgreSQL-specific syntax.
141 Non-standard syntax for other engines (if applicable) may also be
142 supported in the future.
143
144 sql_alter_column PROTOTYPE_COLUMN [ DATABASE_HANDLE | DATA_SOURCE [
145 USERNAME PASSWORD [ ATTR ] ] ]
146 Returns SQL to alter this column so that it is identical to the
147 provided prototype column, also a DBIx::DBSchema::Column object.
148
149 NOTE: This interface has changed in 0.41
150
151 Returns two listrefs. The first is a list of column alteration SQL
152 fragments for an ALTER TABLE statement. The second is a list of
153 full SQL statements that should be run after the ALTER TABLE
154 statement.
155
156 Optionally, the data source can be specified by passing an open DBI
157 database handle, or by passing the DBI data source name, username
158 and password.
159
160 If passed a DBI data source (or handle) such as
161 `DBI:Pg:dbname=database', will use PostgreSQL-specific syntax.
162 Non-standard syntax for other engines (if applicable) may also be
163 supported in the future.
164
165 If not passed a data source (or handle), or if there is no driver
166 for the specified database, will attempt to use generic SQL syntax.
167
168 sql_drop_column [ DBH ]
169 Returns SQL to drop this column from an existing table.
170
171 NOTE: This interface has changed in 0.41
172
173 Returns a list of column alteration SQL fragments for an ALTER
174 TABLE statement.
175
176 The optional database handle or DBI data source/username/password
177 is not yet used.
178
180 Ivan Kohler <ivan-dbix-dbschema@420.am>
181
183 Copyright (c) 2000-2006 Ivan Kohler Copyright (c) 2007-2013 Freeside
184 Internet Services, Inc. All rights reserved. This program is free
185 software; you can redistribute it and/or modify it under the same terms
186 as Perl itself.
187
189 The new() method should warn that "Old-style $class creation without
190 named parameters is deprecated!"
191
192 Better documentation is needed for sql_add_column
193
194 sql_alter_column() has database-specific foo that should be abstracted
195 info DBIx::DBSchema::DBD::Pg
196
197 nullify_default option should be documented
198
200 DBIx::DBSchema::Table, DBIx::DBSchema, DBIx::DBSchema::DBD, DBI
201
202
203
204perl v5.34.0 2021-07-22 DBSchema::Column(3)