1Rose::DB(3) User Contributed Perl Documentation Rose::DB(3)
2
3
4
6 Rose::DB - A DBI wrapper and abstraction layer.
7
9 package My::DB;
10
11 use Rose::DB;
12 our @ISA = qw(Rose::DB);
13
14 My::DB->register_db(
15 domain => 'development',
16 type => 'main',
17 driver => 'Pg',
18 database => 'dev_db',
19 host => 'localhost',
20 username => 'devuser',
21 password => 'mysecret',
22 server_time_zone => 'UTC',
23 );
24
25 My::DB->register_db(
26 domain => 'production',
27 type => 'main',
28 driver => 'Pg',
29 database => 'big_db',
30 host => 'dbserver.acme.com',
31 username => 'dbadmin',
32 password => 'prodsecret',
33 server_time_zone => 'UTC',
34 );
35
36 My::DB->default_domain('development');
37 My::DB->default_type('main');
38 ...
39
40 $db = My::DB->new;
41
42 my $dbh = $db->dbh or die $db->error;
43
44 $db->begin_work or die $db->error;
45 $dbh->do(...) or die $db->error;
46 $db->commit or die $db->error;
47
48 $db->do_transaction(sub
49 {
50 $dbh->do(...);
51 $sth = $dbh->prepare(...);
52 $sth->execute(...);
53 while($sth->fetch) { ... }
54 $dbh->do(...);
55 })
56 or die $db->error;
57
58 $dt = $db->parse_timestamp('2001-03-05 12:34:56.123');
59 $val = $db->format_timestamp($dt);
60
61 $dt = $db->parse_datetime('2001-03-05 12:34:56');
62 $val = $db->format_datetime($dt);
63
64 $dt = $db->parse_date('2001-03-05');
65 $val = $db->format_date($dt);
66
67 $bit = $db->parse_bitfield('0x0AF', 32);
68 $val = $db->format_bitfield($bit);
69
70 ...
71
73 Rose::DB is a wrapper and abstraction layer for DBI-related
74 functionality. A Rose::DB object "has a" DBI object; it is not a
75 subclass of DBI.
76
77 Please see the tutorial (perldoc Rose::DB::Tutorial) for an example
78 usage scenario that reflects "best practices" for this module.
79
80 Tip: Are you looking for an object-relational mapper (ORM)? If so,
81 please see the Rose::DB::Object module. Rose::DB::Object is an ORM
82 that uses this module to manage its database connections. Rose::DB
83 alone is simply a data source abstraction layer; it is not an ORM.
84
86 Rose::DB currently supports the following DBI database drivers:
87
88 DBD::Pg (PostgreSQL)
89 DBD::mysql (MySQL)
90 DBD::SQLite (SQLite)
91 DBD::Informix (Informix)
92 DBD::Oracle (Oracle)
93
94 Rose::DB will attempt to service an unsupported database using a
95 generic implementation that may or may not work. Support for more
96 drivers may be added in the future. Patches are welcome.
97
98 All database-specific behavior is contained and documented in the
99 subclasses of Rose::DB. Rose::DB's constructor method (new()) returns
100 a database-specific subclass of Rose::DB, chosen based on the driver
101 value of the selected data source. The default mapping of databases to
102 Rose::DB subclasses is:
103
104 DBD::Pg -> Rose::DB::Pg
105 DBD::mysql -> Rose::DB::MySQL
106 DBD::SQLite -> Rose::DB::SQLite
107 DBD::Informix -> Rose::DB::Informix
108 DBD::Oracle -> Rose::DB::Oracle
109
110 This mapping can be changed using the driver_class class method.
111
112 The Rose::DB object method documentation found here defines the purpose
113 of each method, as well as the default behavior of the method if it is
114 not overridden by a subclass. You must read the subclass documentation
115 to learn about behaviors that are specific to each type of database.
116
117 Subclasses may also add methods that do not exist in the parent class,
118 of course. This is yet another reason to read the documentation for
119 the subclass that corresponds to your data source's database software.
120
122 The basic features of Rose::DB are as follows.
123
124 Data Source Abstraction
125 Instead of dealing with "databases" that exist on "hosts" or are
126 located via some vendor-specific addressing scheme, Rose::DB deals with
127 "logical" data sources. Each logical data source is currently backed
128 by a single "physical" database (basically a single DBI connection).
129
130 Multiplexing, fail-over, and other more complex relationships between
131 logical data sources and physical databases are not part of Rose::DB.
132 Some basic types of fail-over may be added to Rose::DB in the future,
133 but right now the mapping is strictly one-to-one. (I'm also currently
134 inclined to encourage multiplexing functionality to exist in a layer
135 above Rose::DB, rather than within it or in a subclass of it.)
136
137 The driver type of the data source determines the functionality of all
138 methods that do vendor-specific things (e.g., column value parsing and
139 formatting).
140
141 Rose::DB identifies data sources using a two-level namespace made of a
142 "domain" and a "type". Both are arbitrary strings. If left
143 unspecified, the default domain and default type (accessible via
144 Rose::DB's default_domain and default_type class methods) are assumed.
145
146 There are many ways to use the two-level namespace, but the most common
147 is to use the domain to represent the current environment (e.g.,
148 "development", "staging", "production") and then use the type to
149 identify the logical data source within that environment (e.g.,
150 "report", "main", "archive")
151
152 A typical deployment scenario will set the default domain using the
153 default_domain class method as part of the configure/install process.
154 Within application code, Rose::DB objects can be constructed by
155 specifying type alone:
156
157 $main_db = Rose::DB->new(type => 'main');
158 $archive_db = Rose::DB->new(type => 'archive');
159
160 If there is only one database type, then all Rose::DB objects can be
161 instantiated with a bare constructor call like this:
162
163 $db = Rose::DB->new;
164
165 Again, remember that this is just one of many possible uses of domain
166 and type. Arbitrarily complex scenarios can be created by nesting
167 namespaces within one or both parameters (much like how Perl uses "::"
168 to create a multi-level namespace from single strings).
169
170 The important point is the abstraction of data sources so they can be
171 identified and referred to using a vocabulary that is entirely
172 independent of the actual DSN (data source names) used by DBI behind
173 the scenes.
174
175 Database Handle Life-Cycle Management
176 When a Rose::DB object is destroyed while it contains an active DBI
177 database handle, the handle is explicitly disconnected before
178 destruction. Rose::DB supports a simple retain/release reference-
179 counting system which allows a database handle to out-live its parent
180 Rose::DB object.
181
182 In the simplest case, Rose::DB could be used for its data source
183 abstractions features alone. For example, transiently creating a
184 Rose::DB and then retaining its DBI database handle before it is
185 destroyed:
186
187 $main_dbh = Rose::DB->new(type => 'main')->retain_dbh
188 or die Rose::DB->error;
189
190 $aux_dbh = Rose::DB->new(type => 'aux')->retain_dbh
191 or die Rose::DB->error;
192
193 If the database handle was simply extracted via the dbh method instead
194 of retained with retain_dbh, it would be disconnected by the time the
195 statement completed.
196
197 # WRONG: $dbh will be disconnected immediately after the assignment!
198 $dbh = Rose::DB->new(type => 'main')->dbh or die Rose::DB->error;
199
200 Vendor-Specific Column Value Parsing and Formatting
201 Certain semantically identical column types are handled differently in
202 different databases. Date and time columns are good examples.
203 Although many databases store month, day, year, hours, minutes, and
204 seconds using a "datetime" column type, there will likely be
205 significant differences in how each of those databases expects to
206 receive such values, and how they're returned.
207
208 Rose::DB is responsible for converting the wide range of vendor-
209 specific column values for a particular column type into a single form
210 that is convenient for use within Perl code. Rose::DB also handles the
211 opposite task, taking input from the Perl side and converting it into
212 the appropriate format for a specific database. Not all column types
213 that exist in the supported databases are handled by Rose::DB, but
214 support will expand in the future.
215
216 Many column types are specific to a single database and do not exist
217 elsewhere. When it is reasonable to do so, vendor-specific column
218 types may be "emulated" by Rose::DB for the benefit of other databases.
219 For example, an ARRAY value may be stored as a specially formatted
220 string in a VARCHAR field in a database that does not have a native
221 ARRAY column type.
222
223 Rose::DB does NOT attempt to present a unified column type system,
224 however. If a column type does not exist in a particular kind of
225 database, there should be no expectation that Rose::DB will be able to
226 parse and format that value type on behalf of that database.
227
228 High-Level Transaction Support
229 Transactions may be started, committed, and rolled back in a variety of
230 ways using the DBI database handle directly. Rose::DB provides
231 wrappers to do the same things, but with different error handling and
232 return values. There's also a method (do_transaction) that will
233 execute arbitrary code within a single transaction, automatically
234 handling rollback on failure and commit on success.
235
237 Subclassing is strongly encouraged and generally works as expected.
238 (See the tutorial for a complete example.) There is, however, the
239 question of how class data is shared with subclasses. Here's how it
240 works for the various pieces of class data.
241
242 alias_db, modify_db, register_db, unregister_db, unregister_domain
243 By default, all subclasses share the same data source "registry"
244 with Rose::DB. To provide a private registry for your subclass
245 (the recommended approach), see the example in the documentation
246 for the registry method below.
247
248 default_domain, default_type
249 If called with no arguments, and if the attribute was never set for
250 this class, then a left-most, breadth-first search of the parent
251 classes is initiated. The value returned is taken from first
252 parent class encountered that has ever had this attribute set.
253
254 (These attributes use the inheritable_scalar method type as defined
255 in Rose::Class::MakeMethods::Generic.)
256
257 driver_class, default_connect_options
258 These hashes of attributes are inherited by subclasses using a one-
259 time, shallow copy from a superclass. Any subclass that accesses
260 or manipulates the hash in any way will immediately get its own
261 private copy of the hash as it exists in the superclass at the time
262 of the access or manipulation.
263
264 The superclass from which the hash is copied is the closest ("least
265 super") class that has ever accessed or manipulated this hash. The
266 copy is a "shallow" copy, duplicating only the keys and values.
267 Reference values are not recursively copied.
268
269 Setting to hash to undef (using the 'reset' interface) will cause
270 it to be re-copied from a superclass the next time it is accessed.
271
272 (These attributes use the inheritable_hash method type as defined
273 in Rose::Class::MakeMethods::Generic.)
274
276 A Rose::DB object may contain a DBI database handle, and DBI database
277 handles usually don't survive the serialize process intact. Rose::DB
278 objects also hide database passwords inside closures, which also don't
279 serialize well. In order for a Rose::DB object to survive
280 serialization, custom hooks are required.
281
282 Rose::DB has hooks for the Storable serialization module, but there is
283 an important caveat. Since Rose::DB objects are blessed into a
284 dynamically generated class (derived from the driver class), you must
285 load your Rose::DB-derived class with all its registered data sources
286 before you can successfully thaw a frozen Rose::DB-derived object.
287 Here's an example.
288
289 Imagine that this is your Rose::DB-derived class:
290
291 package My::DB;
292
293 use Rose::DB;
294 our @ISA = qw(Rose::DB);
295
296 My::DB->register_db(
297 domain => 'dev',
298 type => 'main',
299 driver => 'Pg',
300 ...
301 );
302
303 My::DB->register_db(
304 domain => 'prod',
305 type => 'main',
306 driver => 'Pg',
307 ...
308 );
309
310 My::DB->default_domain('dev');
311 My::DB->default_type('main');
312
313 In one program, a "My::DB" object is frozen using Storable:
314
315 # my_freeze_script.pl
316
317 use My::DB;
318 use Storable qw(nstore);
319
320 # Create My::DB object
321 $db = My::DB->new(domain => 'dev', type => 'main');
322
323 # Do work...
324 $db->dbh->db('CREATE TABLE some_table (...)');
325 ...
326
327 # Serialize $db and store it in frozen_data_file
328 nstore($db, 'frozen_data_file');
329
330 Now another program wants to thaw out that "My::DB" object and use it.
331 To do so, it must be sure to load the My::DB module (which registers
332 all its data sources when loaded) before attempting to deserialize the
333 "My::DB" object serialized by "my_freeze_script.pl".
334
335 # my_thaw_script.pl
336
337 # IMPORTANT: load db modules with all data sources registered before
338 # attempting to deserialize objects of this class.
339 use My::DB;
340
341 use Storable qw(retrieve);
342
343 # Retrieve frozen My::DB object from frozen_data_file
344 $db = retrieve('frozen_data_file');
345
346 # Do work...
347 $db->dbh->db('DROP TABLE some_table');
348 ...
349
350 Note that this rule about loading a Rose::DB-derived class with all its
351 data sources registered prior to deserializing such an object only
352 applies if the serialization was done in a different process. If you
353 freeze and thaw within the same process, you don't have to worry about
354 it.
355
357 There are two ways to alter the initial Rose::DB data source registry.
358
359 · The ROSEDB_DEVINIT file or module, which can add, modify, or remove
360 data sources and alter the default domain and type.
361
362 · The ROSEDBRC file, which can modify existing data sources.
363
364 ROSEDB_DEVINIT
365 The "ROSEDB_DEVINIT" file or module is used during development, usually
366 to set up data sources for a particular developer's database or
367 project. If the "ROSEDB_DEVINIT" environment variable is set, it
368 should be the name of a Perl module or file. If it is a Perl module
369 and that module has a "fixup()" subroutine, it will be called as a
370 class method after the module is loaded.
371
372 If the "ROSEDB_DEVINIT" environment variable is not set, or if the
373 specified file does not exist or has errors, then it defaults to the
374 package name "Rose::DB::Devel::Init::username", where "username" is the
375 account name of the current user.
376
377 Note: if the getpwuid() function is unavailable (as is often the case
378 on Windows versions of perl) then this default does not apply and the
379 loading of the module named "Rose::DB::Devel::Init::username" is not
380 attempted.
381
382 The "ROSEDB_DEVINIT" file or module may contain arbitrary Perl code
383 which will be loaded and evaluated in the context of Rose::DB.
384 Example:
385
386 Rose::DB->default_domain('development');
387
388 Rose::DB->modify_db(domain => 'development',
389 type => 'main_db',
390 database => 'main',
391 username => 'jdoe',
392 password => 'mysecret');
393
394 1;
395
396 Remember to end the file with a true value.
397
398 The "ROSEDB_DEVINIT" file or module must be read explicitly by calling
399 the auto_load_fixups class method.
400
401 ROSEDBRC
402 The "ROSEDBRC" file contains configuration "fix-up" information. This
403 file is most often used to dynamically set passwords that are too
404 sensitive to be included directly in the source code of a
405 Rose::DB-derived class.
406
407 The path to the fix-up file is determined by the "ROSEDBRC" environment
408 variable. If this variable is not set, or if the file it points to
409 does not exist, then it defaults to "/etc/rosedbrc".
410
411 This file should be in YAML format. To read this file, you must have
412 either YAML::Syck or some reasonably modern version of YAML installed
413 (0.66 or later recommended). YAML::Syck will be preferred if both are
414 installed.
415
416 The "ROSEDBRC" file's contents have the following structure:
417
418 ---
419 somedomain:
420 sometype:
421 somemethod: somevalue
422 ---
423 otherdomain:
424 othertype:
425 othermethod: othervalue
426
427 Each entry modifies an existing registered data source. Any valid
428 registry entry object method can be used (in place of "somemethod" and
429 "othermethod" in the YAML example above).
430
431 This file must be read explicitly by calling the auto_load_fixups class
432 method after setting up all your data sources. Example:
433
434 package My::DB;
435
436 use Rose::DB;
437 our @ISA = qw(Rose::DB);
438
439 __PACKAGE__->use_private_registry;
440
441 # Register all data sources
442 __PACKAGE__->register_db(
443 domain => 'development',
444 type => 'main',
445 driver => 'Pg',
446 database => 'dev_db',
447 host => 'localhost',
448 username => 'devuser',
449 password => 'mysecret',
450 );
451
452 ...
453
454 # Load fix-up files, if any
455 __PACKAGE__->auto_load_fixups;
456
458 alias_db PARAMS
459 Make one data source an alias for another by pointing them both to
460 the same registry entry. PARAMS are name/value pairs that must
461 include domain and type values for both the source and alias
462 parameters. Example:
463
464 Rose::DB->alias_db(source => { domain => 'dev', type => 'main' },
465 alias => { domain => 'dev', type => 'aux' });
466
467 This makes the "dev/aux" data source point to the same registry
468 entry as the "dev/main" data source. Modifications to either
469 registry entry (via modify_db) will be reflected in both.
470
471 auto_load_fixups
472 Attempt to load both the YAML-based ROSEDBRC and Perl-based
473 ROSEDB_DEVINIT fix-up files, if any exist, in that order. The
474 ROSEDBRC file will modify the data source registry of the calling
475 class. See the ENVIRONMENT section above for more information.
476
477 db_cache [CACHE]
478 Get or set the Rose::DB::Cache-derived object used to cache
479 Rose::DB objects on behalf of this class. If no such object
480 exists, a new cache object of db_cache_class class will be created,
481 stored, and returned.
482
483 db_cache_class [CLASS]
484 Get or set the name of the Rose::DB::Cache-derived class used to
485 cache Rose::DB objects on behalf of this class. The default value
486 is Rose::DB::Cache.
487
488 db_exists PARAMS
489 Returns true of the data source specified by PARAMS is registered,
490 false otherwise. PARAMS are name/value pairs for "domain" and
491 "type". If they are omitted, they default to default_domain and
492 default_type, respectively. If default values do not exist, a
493 fatal error will occur. If a single value is passed instead of
494 name/value pairs, it is taken as the value of the "type" parameter.
495
496 default_connect_options [HASHREF | PAIRS]
497 Get or set the default DBI connect options hash. If a reference to
498 a hash is passed, it replaces the default connect options hash. If
499 a series of name/value pairs are passed, they are added to the
500 default connect options hash.
501
502 The default set of default connect options is:
503
504 AutoCommit => 1,
505 RaiseError => 1,
506 PrintError => 1,
507 ChopBlanks => 1,
508 Warn => 0,
509
510 See the connect_options object method for more information on how
511 the default connect options are used.
512
513 default_domain [DOMAIN]
514 Get or set the default data source domain. See the "Data Source
515 Abstraction" section for more information on data source domains.
516
517 default_type [TYPE]
518 Get or set the default data source type. See the "Data Source
519 Abstraction" section for more information on data source types.
520
521 driver_class DRIVER [, CLASS]
522 Get or set the subclass used for DRIVER. The DRIVER argument is
523 automatically converted to lowercase. (Driver names are
524 effectively case-insensitive.)
525
526 $class = Rose::DB->driver_class('Pg'); # get
527 Rose::DB->driver_class('pg' => 'MyDB::Pg'); # set
528
529 The default mapping of driver names to class names is as follows:
530
531 mysql -> Rose::DB::MySQL
532 pg -> Rose::DB::Pg
533 informix -> Rose::DB::Informix
534 sqlite -> Rose::DB::SQLite
535 oracle -> Rose::DB::Oracle
536 generic -> Rose::DB::Generic
537
538 The class mapped to the special driver name "generic" will be used
539 for any driver name that does not have an entry in the map.
540
541 See the documentation for the new method for more information on
542 how the driver influences the class of objects returned by the
543 constructor.
544
545 default_keyword_function_calls [BOOL]
546 Get or set a boolean default value for the keyword_function_calls
547 object attribute. Defaults to the value of the
548 "ROSE_DB_KEYWORD_FUNCTION_CALLS" environment variable, it set to a
549 defined value, or false otherwise.
550
551 modify_db PARAMS
552 Modify a data source, setting the attributes specified in PARAMS,
553 where PARAMS are name/value pairs. Any Rose::DB object method that
554 sets a data source configuration value is a valid parameter name.
555
556 # Set new username for data source identified by domain and type
557 Rose::DB->modify_db(domain => 'test',
558 type => 'main',
559 username => 'tester');
560
561 PARAMS should include values for both the "type" and "domain"
562 parameters since these two attributes are used to identify the data
563 source. If they are omitted, they default to default_domain and
564 default_type, respectively. If default values do not exist, a
565 fatal error will occur. If there is no data source defined for the
566 specified "type" and "domain", a fatal error will occur.
567
568 prepare_cache_for_apache_fork
569 This is a convenience method that is equivalent to the following
570 call:
571
572 Rose::DB->db_cache->prepare_for_apache_fork()
573
574 Any arguments passed to this method are passed on to the call to
575 the db_cache's prepare_for_apache_fork method.
576
577 Please read the Rose::DB::Cache documentation, particularly the
578 documentation for the use_cache_during_apache_startup method for
579 more information.
580
581 register_db PARAMS
582 Registers a new data source with the attributes specified in
583 PARAMS, where PARAMS are name/value pairs. Any Rose::DB object
584 method that sets a data source configuration value is a valid
585 parameter name.
586
587 PARAMS must include a value for the "driver" parameter. If the
588 "type" or "domain" parameters are omitted or undefined, they
589 default to the return values of the default_type and default_domain
590 class methods, respectively.
591
592 The "type" and "domain" are used to identify the data source. If
593 either one is missing, a fatal error will occur. See the "Data
594 Source Abstraction" section for more information on data source
595 types and domains.
596
597 The "driver" is used to determine which class objects will be
598 blessed into by the Rose::DB constructor, new. The driver name is
599 automatically converted to lowercase. If it is missing, a fatal
600 error will occur.
601
602 In most deployment scenarios, register_db is called early in the
603 compilation process to ensure that the registered data sources are
604 available when the "real" code runs.
605
606 Database registration can be included directly in your Rose::DB
607 subclass. This is the recommended approach. Example:
608
609 package My::DB;
610
611 use Rose::DB;
612 our @ISA = qw(Rose::DB);
613
614 # Use a private registry for this class
615 __PACKAGE__->use_private_registry;
616
617 # Register data sources
618 My::DB->register_db(
619 domain => 'development',
620 type => 'main',
621 driver => 'Pg',
622 database => 'dev_db',
623 host => 'localhost',
624 username => 'devuser',
625 password => 'mysecret',
626 );
627
628 My::DB->register_db(
629 domain => 'production',
630 type => 'main',
631 driver => 'Pg',
632 database => 'big_db',
633 host => 'dbserver.acme.com',
634 username => 'dbadmin',
635 password => 'prodsecret',
636 );
637 ...
638
639 Another possible approach is to consolidate data source
640 registration in a single module which is then "use"ed early on in
641 the code path. For example, imagine a mod_perl web server
642 environment:
643
644 # File: MyCorp/DataSources.pm
645 package MyCorp::DataSources;
646
647 My::DB->register_db(
648 domain => 'development',
649 type => 'main',
650 driver => 'Pg',
651 database => 'dev_db',
652 host => 'localhost',
653 username => 'devuser',
654 password => 'mysecret',
655 );
656
657 My::DB->register_db(
658 domain => 'production',
659 type => 'main',
660 driver => 'Pg',
661 database => 'big_db',
662 host => 'dbserver.acme.com',
663 username => 'dbadmin',
664 password => 'prodsecret',
665 );
666 ...
667
668 # File: /usr/local/apache/conf/startup.pl
669
670 use My::DB; # your Rose::DB subclass
671 use MyCorp::DataSources; # register all data sources
672 ...
673
674 Data source registration can happen at any time, of course, but it
675 is most useful when all application code can simply assume that all
676 the data sources are already registered. Doing the registration as
677 early as possible (e.g., directly in your Rose::DB subclass, or in
678 a "startup.pl" file that is loaded from an apache/mod_perl web
679 server's "httpd.conf" file) is the best way to create such an
680 environment.
681
682 Note that the data source registry serves as an initial source of
683 information for Rose::DB objects. Once an object is instantiated,
684 it is independent of the registry. Changes to an object are not
685 reflected in the registry, and changes to the registry are not
686 reflected in existing objects.
687
688 registry [REGISTRY]
689 Get or set the Rose::DB::Registry-derived object that manages and
690 stores the data source registry. It defaults to an "empty"
691 Rose::DB::Registry object. Remember that setting a new registry
692 will replace the existing registry and all the data sources
693 registered in it.
694
695 Note that Rose::DB subclasses will inherit the base class's
696 Rose::DB::Registry object and will therefore inherit all existing
697 registry entries and share the same registry namespace as the base
698 class. This may or may not be what you want.
699
700 In most cases, it's wise to give your subclass its own private
701 registry if it inherits directly from Rose::DB. To do that, just
702 set a new registry object in your subclass. Example:
703
704 package My::DB;
705
706 use Rose::DB;
707 our @ISA = qw(Rose::DB);
708
709 # Create a private registry for this class:
710 #
711 # either explicitly:
712 # use Rose::DB::Registry;
713 # __PACKAGE__->registry(Rose::DB::Registry->new);
714 #
715 # or use the convenience method:
716 __PACKAGE__->use_private_registry;
717 ...
718
719 Further subclasses of "My::DB" may then inherit its registry
720 object, if desired, or may create their own private registries in
721 the manner shown above.
722
723 unregister_db PARAMS
724 Unregisters the data source having the "type" and "domain"
725 specified in PARAMS, where PARAMS are name/value pairs. Returns
726 true if the data source was unregistered successfully, false if it
727 did not exist in the first place. Example:
728
729 Rose::DB->unregister_db(type => 'main', domain => 'test');
730
731 PARAMS must include values for both the "type" and "domain"
732 parameters since these two attributes are used to identify the data
733 source. If either one is missing, a fatal error will occur.
734
735 Unregistering a data source removes all knowledge of it. This may
736 be harmful to any existing Rose::DB objects that are associated
737 with that data source.
738
739 unregister_domain DOMAIN
740 Unregisters an entire domain. Returns true if the domain was
741 unregistered successfully, false if it did not exist in the first
742 place. Example:
743
744 Rose::DB->unregister_domain('test');
745
746 Unregistering a domain removes all knowledge of all of the data
747 sources that existed under it. This may be harmful to any existing
748 Rose::DB objects that are associated with any of those data
749 sources.
750
751 use_cache_during_apache_startup [BOOL]
752 This is a convenience method that is equivalent to the following
753 call:
754
755 Rose::DB->db_cache->use_cache_during_apache_startup(...)
756
757 The boolean argument passed to this method is passed on to the call
758 to the db_cache's use_cache_during_apache_startup method.
759
760 Please read the Rose::DB::Cache's use_cache_during_apache_startup
761 documentation for more information.
762
763 use_private_registry
764 This method is used to give a class its own private registry. In
765 other words, this:
766
767 __PACKAGE__->use_private_registry;
768
769 is roughly equivalent to this:
770
771 use Rose::DB::Registry;
772 __PACKAGE__->registry(Rose::DB::Registry->new);
773
775 new PARAMS
776 Constructs a new object based on PARAMS, where PARAMS are
777 name/value pairs. Any object method is a valid parameter name.
778 Example:
779
780 $db = Rose::DB->new(type => 'main', domain => 'qa');
781
782 If a single argument is passed to new, it is used as the "type"
783 value:
784
785 $db = Rose::DB->new(type => 'aux');
786 $db = Rose::DB->new('aux'); # same thing
787
788 Each Rose::DB object is associated with a particular data source,
789 defined by the type and domain values. If these are not part of
790 PARAMS, then the default values are used. If you do not want to
791 use the default values for the type and domain attributes, you
792 should specify them in the constructor PARAMS.
793
794 The default type and domain can be set using the default_type and
795 default_domain class methods. See the "Data Source Abstraction"
796 section for more information on data sources.
797
798 Object attributes are set based on the registry entry specified by
799 the "type" and "domain" parameters. This registry entry must exist
800 or a fatal error will occur (with one exception; see below). Any
801 additional PARAMS will override the values taken from the registry
802 entry.
803
804 If "type" and "domain" parameters are not passed, but a "driver"
805 parameter is passed, then a new "empty" object will be returned.
806 Examples:
807
808 # This is ok, even if no registered data sources exist
809 $db = Rose::DB->new(driver => 'sqlite');
810
811 The object returned by new will be derived from a database-specific
812 driver class, chosen based on the driver value of the selected data
813 source. If there is no registered data source for the specified
814 type and domain, a fatal error will occur.
815
816 The default driver-to-class mapping is as follows:
817
818 pg -> Rose::DB::Pg
819 mysql -> Rose::DB::MySQL
820 informix -> Rose::DB::Informix
821 oracle -> Rose::DB::Oracle
822 sqlite -> Rose::DB::SQLite
823
824 You can change this mapping with the driver_class class method.
825
826 new_or_cached PARAMS
827 Constructs or returns a Rose::DB object based on PARAMS, where
828 PARAMS are any name/value pairs that can be passed to the new
829 method. If the db_cache's get_db method returns an existing
830 Rose::DB object that matches PARAMS, then it is returned.
831 Otherwise, a new Rose::DB object is created, stored in the
832 db_cache, then returned.
833
834 See the Rose::DB::Cache documentation to learn about the cache API
835 and the default implementation.
836
838 begin_work
839 Attempt to start a transaction by calling the begin_work method on
840 the DBI database handle.
841
842 If necessary, the database handle will be constructed and connected
843 to the current data source. If this fails, undef is returned. If
844 there is no registered data source for the current "type" and
845 "domain", a fatal error will occur.
846
847 If the "AutoCommit" database handle attribute is false, the handle
848 is assumed to already be in a transaction and
849 Rose::DB::Constants::IN_TRANSACTION (-1) is returned. If the call
850 to DBI's begin_work method succeeds, 1 is returned. If it fails,
851 undef is returned.
852
853 commit
854 Attempt to commit the current transaction by calling the commit
855 method on the DBI database handle. If the DBI database handle does
856 not exist or is not connected, 0 is returned.
857
858 If the "AutoCommit" database handle attribute is true, the handle
859 is assumed to not be in a transaction and
860 Rose::DB::Constants::IN_TRANSACTION (-1) is returned. If the call
861 to DBI's commit method succeeds, 1 is returned. If it fails, undef
862 is returned.
863
864 connect
865 Constructs and connects the DBI database handle for the current
866 data source, calling dbi_connect to create a new DBI database
867 handle if none exists. If there is no registered data source for
868 the current type and domain, a fatal error will occur.
869
870 If any post_connect_sql statement failed to execute, the database
871 handle is disconnected and then discarded.
872
873 If the database handle returned by dbi_connect was originally
874 connected by another Rose::DB-derived object (e.g., if a subclass's
875 custom implementation of dbi_connect calls DBI's connect_cached
876 method) then the post_connect_sql statements will not be run, nor
877 will any custom DBI attributes be applied (e.g., Rose::DB::MySQL's
878 mysql_enable_utf8 attribute).
879
880 Returns true if the database handle was connected successfully and
881 all post_connect_sql statements (if any) were run successfully,
882 false otherwise.
883
884 connect_option NAME [, VALUE]
885 Get or set a single connection option. Example:
886
887 $val = $db->connect_option('RaiseError'); # get
888 $db->connect_option(AutoCommit => 1); # set
889
890 Connection options are name/value pairs that are passed in a hash
891 reference as the fourth argument to the call to DBI->connect().
892 See the DBI documentation for descriptions of the various options.
893
894 connect_options [HASHREF | PAIRS]
895 Get or set the DBI connect options hash. If a reference to a hash
896 is passed, it replaces the connect options hash. If a series of
897 name/value pairs are passed, they are added to the connect options
898 hash.
899
900 Returns a reference to the connect options has in scalar context,
901 or a list of name/value pairs in list context.
902
903 dbh [DBH]
904 Get or set the DBI database handle connected to the current data
905 source. If the database handle does not exist or was created in
906 another process or thread, this method will discard the old
907 database handle (if any) and dbi_connect will be called to create a
908 new one.
909
910 Returns undef if the database handle could not be constructed and
911 connected. If there is no registered data source for the current
912 "type" and "domain", a fatal error will occur.
913
914 Note: when setting this attribute, you must pass in a DBI database
915 handle that has the same driver as the object. For example, if the
916 driver is "mysql" then the DBI database handle must be connected to
917 a MySQL database. Passing in a mismatched database handle will
918 cause a fatal error.
919
920 dbi_connect [ARGS]
921 This method calls DBI->connect(...), passing all ARGS and returning
922 all values. This method has no affect on the internal state of the
923 object. Use the connect method to create and store a new database
924 handle in the object.
925
926 Override this method in your Rose::DB subclass if you want to use a
927 different method (e.g. DBI->connect_cached()) to create database
928 handles.
929
930 disconnect
931 Decrements the reference count for the database handle and
932 disconnects it if the reference count is zero and if the database
933 handle was originally connected by this object. (This may not be
934 the case if, say, a subclass's custom implementation of dbi_connect
935 calls DBI's connect_cached method.) Regardless of the reference
936 count, it sets the dbh attribute to undef.
937
938 Returns true if all pre_disconnect_sql statements (if any) were run
939 successfully and the database handle was disconnected successfully
940 (or if it was simply set to undef), false otherwise.
941
942 The database handle will not be disconnected if any
943 pre_disconnect_sql statement fails to execute, and the
944 pre_disconnect_sql is not run unless the handle is going to be
945 disconnected.
946
947 do_transaction CODE [, ARGS]
948 Execute arbitrary code within a single transaction, rolling back if
949 any of the code fails, committing if it succeeds. CODE should be a
950 code reference. It will be called with any arguments passed to
951 do_transaction after the code reference. Example:
952
953 # Transfer $100 from account id 5 to account id 9
954 $db->do_transaction(sub
955 {
956 my($amt, $id1, $id2) = @_;
957
958 my $dbh = $db->dbh or die $db->error;
959
960 # Transfer $amt from account id $id1 to account id $id2
961 $dbh->do("UPDATE acct SET bal = bal - $amt WHERE id = $id1");
962 $dbh->do("UPDATE acct SET bal = bal + $amt WHERE id = $id2");
963 },
964 100, 5, 9) or warn "Transfer failed: ", $db->error;
965
966 If the CODE block threw an exception or the transaction could not
967 be started and committed successfully, then undef is returned and
968 the exception thrown is available in the error attribute.
969 Otherwise, a true value is returned.
970
971 error [MSG]
972 Get or set the error message associated with the last failure. If
973 a method fails, check this attribute to get the reason for the
974 failure in the form of a text message.
975
976 has_dbh
977 Returns true if the object has a DBI database handle (dbh), false
978 if it does not.
979
980 has_primary_key [ TABLE | PARAMS ]
981 Returns true if the specified table has a primary key (as
982 determined by the primary_key_column_names method), false
983 otherwise.
984
985 The arguments are the same as those for the
986 primary_key_column_names method: either a table name or name/value
987 pairs specifying "table", "catalog", and "schema". The "catalog"
988 and "schema" parameters are optional and default to the return
989 values of the catalog and schema methods, respectively. See the
990 documentation for the primary_key_column_names for more
991 information.
992
993 in_transaction
994 Return true if the dbh is currently in the middle of a transaction,
995 false (but defined) if it is not. If no dbh exists, then undef is
996 returned.
997
998 init_db_info
999 Initialize data source configuration information based on the
1000 current values of the type and domain attributes by pulling data
1001 from the corresponding registry entry. If there is no registered
1002 data source for the current type and domain, a fatal error will
1003 occur. init_db_info is called as part of the new and connect
1004 methods.
1005
1006 insertid_param
1007 Returns the name of the DBI statement handle attribute that
1008 contains the auto-generated unique key created during the last
1009 insert operation. Returns undef if the current data source does
1010 not support this attribute.
1011
1012 keyword_function_calls [BOOL]
1013 Get or set a boolean value that indicates whether or not any string
1014 that looks like a function call (matches "/^\w+\(.*\)$/") will be
1015 treated as a "keyword" by the various format_* methods. Defaults
1016 to the value returned by the default_keyword_function_calls class
1017 method.
1018
1019 last_insertid_from_sth STH
1020 Given a DBI statement handle, returns the value of the auto-
1021 generated unique key created during the last insert operation.
1022 This value may be undefined if this feature is not supported by the
1023 current data source.
1024
1025 list_tables
1026 Returns a list (in list context) or reference to an array (in
1027 scalar context) of tables in the database. The current catalog and
1028 schema are honored.
1029
1030 quote_column_name NAME
1031 Returns the column name NAME appropriately quoted for use in an SQL
1032 statement. (Note that "appropriate" quoting may mean no quoting at
1033 all.)
1034
1035 release_dbh
1036 Decrements the reference count for the DBI database handle, if it
1037 exists. Returns 0 if the database handle does not exist.
1038
1039 If the reference count drops to zero, the database handle is
1040 disconnected. Keep in mind that the Rose::DB object itself will
1041 increment the reference count when the database handle is
1042 connected, and decrement it when disconnect is called.
1043
1044 Returns true if the reference count is not 0 or if all
1045 pre_disconnect_sql statements (if any) were run successfully and
1046 the database handle was disconnected successfully, false otherwise.
1047
1048 The database handle will not be disconnected if any
1049 pre_disconnect_sql statement fails to execute, and the
1050 pre_disconnect_sql is not run unless the handle is going to be
1051 disconnected.
1052
1053 See the "Database Handle Life-Cycle Management" section for more
1054 information on the retain/release system.
1055
1056 retain_dbh
1057 Returns the connected DBI database handle after incrementing the
1058 reference count. If the database handle does not exist or is not
1059 already connected, this method will do everything necessary to do
1060 so.
1061
1062 Returns undef if the database handle could not be constructed and
1063 connected. If there is no registered data source for the current
1064 type and domain, a fatal error will occur.
1065
1066 See the "Database Handle Life-Cycle Management" section for more
1067 information on the retain/release system.
1068
1069 rollback
1070 Roll back the current transaction by calling the rollback method on
1071 the DBI database handle. If the DBI database handle does not exist
1072 or is not connected, 0 is returned.
1073
1074 If the call to DBI's rollback method succeeds or if auto-commit is
1075 enabled, 1 is returned. If it fails, undef is returned.
1076
1077 Data Source Configuration
1078 Not all databases will use all of these values. Values that are not
1079 supported are simply ignored.
1080
1081 autocommit [VALUE]
1082 Get or set the value of the "AutoCommit" connect option and DBI
1083 handle attribute. If a VALUE is passed, it will be set in both the
1084 connect options hash and the current database handle, if any.
1085 Returns the value of the "AutoCommit" attribute of the database
1086 handle if it exists, or the connect option otherwise.
1087
1088 This method should not be mixed with the connect_options method in
1089 calls to register_db or modify_db since connect_options will
1090 overwrite all the connect options with its argument, and neither
1091 register_db nor modify_db guarantee the order that its parameters
1092 will be evaluated.
1093
1094 catalog [CATALOG]
1095 Get or set the database catalog name. This setting is only
1096 relevant to databases that support the concept of catalogs.
1097
1098 connect_options [HASHREF | PAIRS]
1099 Get or set the options passed in a hash reference as the fourth
1100 argument to the call to DBI->connect(). See the DBI documentation
1101 for descriptions of the various options.
1102
1103 If a reference to a hash is passed, it replaces the connect options
1104 hash. If a series of name/value pairs are passed, they are added
1105 to the connect options hash.
1106
1107 Returns a reference to the hash of options in scalar context, or a
1108 list of name/value pairs in list context.
1109
1110 When init_db_info is called for the first time on an object (either
1111 in isolation or as part of the connect process), the connect
1112 options are merged with the default_connect_options. The defaults
1113 are overridden in the case of a conflict. Example:
1114
1115 Rose::DB->register_db(
1116 domain => 'development',
1117 type => 'main',
1118 driver => 'Pg',
1119 database => 'dev_db',
1120 host => 'localhost',
1121 username => 'devuser',
1122 password => 'mysecret',
1123 connect_options =>
1124 {
1125 RaiseError => 0,
1126 AutoCommit => 0,
1127 }
1128 );
1129
1130 # Rose::DB->default_connect_options are:
1131 #
1132 # AutoCommit => 1,
1133 # ChopBlanks => 1,
1134 # PrintError => 1,
1135 # RaiseError => 1,
1136 # Warn => 0,
1137
1138 # The object's connect options are merged with default options
1139 # since new() will trigger the first call to init_db_info()
1140 # for this object
1141 $db = Rose::DB->new(domain => 'development', type => 'main');
1142
1143 # $db->connect_options are:
1144 #
1145 # AutoCommit => 0,
1146 # ChopBlanks => 1,
1147 # PrintError => 1,
1148 # RaiseError => 0,
1149 # Warn => 0,
1150
1151 $db->connect_options(TraceLevel => 2); # Add an option
1152
1153 # $db->connect_options are now:
1154 #
1155 # AutoCommit => 0,
1156 # ChopBlanks => 1,
1157 # PrintError => 1,
1158 # RaiseError => 0,
1159 # TraceLevel => 2,
1160 # Warn => 0,
1161
1162 # The object's connect options are NOT re-merged with the default
1163 # connect options since this will trigger the second call to
1164 # init_db_info(), not the first
1165 $db->connect or die $db->error;
1166
1167 # $db->connect_options are still:
1168 #
1169 # AutoCommit => 0,
1170 # ChopBlanks => 1,
1171 # PrintError => 1,
1172 # RaiseError => 0,
1173 # TraceLevel => 2,
1174 # Warn => 0,
1175
1176 database [NAME]
1177 Get or set the database name used in the construction of the DSN
1178 used in the DBI connect call.
1179
1180 domain [DOMAIN]
1181 Get or set the data source domain. See the "Data Source
1182 Abstraction" section for more information on data source domains.
1183
1184 driver [DRIVER]
1185 Get or set the driver name. The driver name can only be set during
1186 object construction (i.e., as an argument to new) since it
1187 determines the object class. After the object is constructed,
1188 setting the driver to anything other than the same value it already
1189 has will cause a fatal error.
1190
1191 Even in the call to new, setting the driver name explicitly is not
1192 recommended. Instead, specify the driver when calling register_db
1193 for each data source and allow the driver to be set automatically
1194 based on the domain and type.
1195
1196 The driver names for the currently supported database types are:
1197
1198 pg
1199 mysql
1200 informix
1201 oracle
1202 sqlite
1203
1204 Driver names should only use lowercase letters.
1205
1206 dsn [DSN]
1207 Get or set the DBI DSN (Data Source Name) passed to the call to
1208 DBI's connect method.
1209
1210 An attempt is made to parse the new DSN. Any parts successfully
1211 extracted are assigned to the corresponding Rose::DB attributes
1212 (e.g., host, port, database). If no value could be extracted for
1213 an attribute, it is set to undef.
1214
1215 If the DSN is never set explicitly, it is built automatically based
1216 on the relevant object attributes.
1217
1218 If the DSN is set explicitly, but any of host, port, database,
1219 schema, or catalog are also provided, either in an object
1220 constructor or when the data source is registered, the explicit DSN
1221 may be ignored as a new DSN is constructed based on these
1222 attributes.
1223
1224 handle_error [VALUE]
1225 Get or set the value of the "HandleError" connect option and DBI
1226 handle attribute. If a VALUE is passed, it will be set in both the
1227 connect options hash and the current database handle, if any.
1228 Returns the value of the "HandleError" attribute of the database
1229 handle if it exists, or the connect option otherwise.
1230
1231 This method should not be mixed with the connect_options method in
1232 calls to register_db or modify_db since connect_options will
1233 overwrite all the connect options with its argument, and neither
1234 register_db nor modify_db guarantee the order that its parameters
1235 will be evaluated.
1236
1237 host [NAME]
1238 Get or set the database server host name used in the construction
1239 of the DSN which is passed in the DBI connect call.
1240
1241 password [PASS]
1242 Get or set the password that will be passed to the DBI connect
1243 call.
1244
1245 port [NUM]
1246 Get or set the database server port number used in the construction
1247 of the DSN which is passed in the DBI connect call.
1248
1249 pre_disconnect_sql [STATEMENTS]
1250 Get or set the SQL statements that will be run immediately before
1251 disconnecting from the database. STATEMENTS should be a list or
1252 reference to an array of SQL statements. Returns a reference to
1253 the array of SQL statements in scalar context, or a list of SQL
1254 statements in list context.
1255
1256 The SQL statements are run in the order that they are supplied in
1257 STATEMENTS. If any pre_disconnect_sql statement fails when
1258 executed, the subsequent statements are ignored.
1259
1260 post_connect_sql [STATEMENTS]
1261 Get or set the SQL statements that will be run immediately after
1262 connecting to the database. STATEMENTS should be a list or
1263 reference to an array of SQL statements. Returns a reference to
1264 the array of SQL statements in scalar context, or a list of SQL
1265 statements in list context.
1266
1267 The SQL statements are run in the order that they are supplied in
1268 STATEMENTS. If any post_connect_sql statement fails when executed,
1269 the subsequent statements are ignored.
1270
1271 primary_key_column_names [ TABLE | PARAMS ]
1272 Returns a list (in list context) or reference to an array (in
1273 scalar context) of the names of the columns that make up the
1274 primary key for the specified table. If the table has no primary
1275 key, an empty list (in list context) or reference to an empty array
1276 (in scalar context) will be returned.
1277
1278 The table may be specified in two ways. If one argument is passed,
1279 it is taken as the name of the table. Otherwise, name/value pairs
1280 are expected. Valid parameter names are:
1281
1282 "catalog"
1283 The name of the catalog that contains the table. This
1284 parameter is optional and defaults to the return value of the
1285 catalog method.
1286
1287 "schema"
1288 The name of the schema that contains the table. This parameter
1289 is optional and defaults to the return value of the schema
1290 method.
1291
1292 "table"
1293 The name of the table. This parameter is required.
1294
1295 Case-sensitivity of names is determined by the underlying database.
1296 If your database is case-sensitive, then you must pass names to
1297 this method with the expected case.
1298
1299 print_error [VALUE]
1300 Get or set the value of the "PrintError" connect option and DBI
1301 handle attribute. If a VALUE is passed, it will be set in both the
1302 connect options hash and the current database handle, if any.
1303 Returns the value of the "PrintError" attribute of the database
1304 handle if it exists, or the connect option otherwise.
1305
1306 This method should not be mixed with the connect_options method in
1307 calls to register_db or modify_db since connect_options will
1308 overwrite all the connect options with its argument, and neither
1309 register_db nor modify_db guarantee the order that its parameters
1310 will be evaluated.
1311
1312 raise_error [VALUE]
1313 Get or set the value of the "RaiseError" connect option and DBI
1314 handle attribute. If a VALUE is passed, it will be set in both the
1315 connect options hash and the current database handle, if any.
1316 Returns the value of the "RaiseError" attribute of the database
1317 handle if it exists, or the connect option otherwise.
1318
1319 This method should not be mixed with the connect_options method in
1320 calls to register_db or modify_db since connect_options will
1321 overwrite all the connect options with its argument, and neither
1322 register_db nor modify_db guarantee the order that its parameters
1323 will be evaluated.
1324
1325 schema [SCHEMA]
1326 Get or set the database schema name. This setting is only useful
1327 to databases that support the concept of schemas (e.g.,
1328 PostgreSQL).
1329
1330 server_time_zone [TZ]
1331 Get or set the time zone used by the database server software. TZ
1332 should be a time zone name that is understood by
1333 DateTime::TimeZone. The default value is "floating".
1334
1335 See the DateTime::TimeZone documentation for acceptable values of
1336 TZ.
1337
1338 type [TYPE]
1339 Get or set the data source type. See the "Data Source
1340 Abstraction" section for more information on data source types.
1341
1342 username [NAME]
1343 Get or set the username that will be passed to the DBI connect
1344 call.
1345
1346 Value Parsing and Formatting
1347 format_bitfield BITS [, SIZE]
1348 Converts the Bit::Vector object BITS into the appropriate format
1349 for the "bitfield" data type of the current data source. If a SIZE
1350 argument is provided, the bit field will be padded with the
1351 appropriate number of zeros until it is SIZE bits long. If the
1352 data source does not have a native "bit" or "bitfield" data type, a
1353 character data type may be used to store the string of 1s and 0s
1354 returned by the default implementation.
1355
1356 format_boolean VALUE
1357 Converts VALUE into the appropriate format for the "boolean" data
1358 type of the current data source. VALUE is simply evaluated in
1359 Perl's scalar context to determine if it's true or false.
1360
1361 format_date DATETIME
1362 Converts the DateTime object DATETIME into the appropriate format
1363 for the "date" (month, day, year) data type of the current data
1364 source.
1365
1366 format_datetime DATETIME
1367 Converts the DateTime object DATETIME into the appropriate format
1368 for the "datetime" (month, day, year, hour, minute, second) data
1369 type of the current data source.
1370
1371 format_interval DURATION
1372 Converts the DateTime::Duration object DURATION into the
1373 appropriate format for the interval (years, months, days, hours,
1374 minutes, seconds) data type of the current data source. If DURATION
1375 is undefined, a DateTime::Duration object, a valid interval keyword
1376 (according to validate_interval_keyword), or if it looks like a
1377 function call (matches "/^\w+\(.*\)$/") and keyword_function_calls
1378 is true, then it is returned unmodified.
1379
1380 format_time TIMECLOCK
1381 Converts the Time::Clock object TIMECLOCK into the appropriate
1382 format for the time (hour, minute, second, fractional seconds) data
1383 type of the current data source. Fractional seconds are optional,
1384 and the useful precision may vary depending on the data source.
1385
1386 format_timestamp DATETIME
1387 Converts the DateTime object DATETIME into the appropriate format
1388 for the timestamp (month, day, year, hour, minute, second,
1389 fractional seconds) data type of the current data source.
1390 Fractional seconds are optional, and the useful precision may vary
1391 depending on the data source.
1392
1393 format_timestamp_with_time_zone DATETIME
1394 Converts the DateTime object DATETIME into the appropriate format
1395 for the timestamp with time zone (month, day, year, hour, minute,
1396 second, fractional seconds, time zone) data type of the current
1397 data source. Fractional seconds are optional, and the useful
1398 precision may vary depending on the data source.
1399
1400 parse_bitfield BITS [, SIZE]
1401 Parse BITS and return a corresponding Bit::Vector object. If SIZE
1402 is not passed, then it defaults to the number of bits in the parsed
1403 bit string.
1404
1405 If BITS is a string of "1"s and "0"s or matches "/^B'[10]+'$/",
1406 then the "1"s and "0"s are parsed as a binary string.
1407
1408 If BITS is a string of numbers, at least one of which is in the
1409 range 2-9, it is assumed to be a decimal (base 10) number and is
1410 converted to a bitfield as such.
1411
1412 If BITS matches any of these regular expressions:
1413
1414 /^0x/
1415 /^X'.*'$/
1416 /^[0-9a-f]+$/
1417
1418 it is assumed to be a hexadecimal number and is converted to a
1419 bitfield as such.
1420
1421 Otherwise, undef is returned.
1422
1423 parse_boolean STRING
1424 Parse STRING and return a boolean value of 1 or 0. STRING should
1425 be formatted according to the data source's native "boolean" data
1426 type. The default implementation accepts 't', 'true', 'y', 'yes',
1427 and '1' values for true, and 'f', 'false', 'n', 'no', and '0'
1428 values for false.
1429
1430 If STRING is a valid boolean keyword (according to
1431 validate_boolean_keyword) or if it looks like a function call
1432 (matches "/^\w+\(.*\)$/") and keyword_function_calls is true, then
1433 it is returned unmodified. Returns undef if STRING could not be
1434 parsed as a valid "boolean" value.
1435
1436 parse_date STRING
1437 Parse STRING and return a DateTime object. STRING should be
1438 formatted according to the data source's native "date" (month, day,
1439 year) data type.
1440
1441 If STRING is a valid date keyword (according to
1442 validate_date_keyword) or if it looks like a function call (matches
1443 "/^\w+\(.*\)$/") and keyword_function_calls is true, then it is
1444 returned unmodified. Returns undef if STRING could not be parsed
1445 as a valid "date" value.
1446
1447 parse_datetime STRING
1448 Parse STRING and return a DateTime object. STRING should be
1449 formatted according to the data source's native "datetime" (month,
1450 day, year, hour, minute, second) data type.
1451
1452 If STRING is a valid datetime keyword (according to
1453 validate_datetime_keyword) or if it looks like a function call
1454 (matches "/^\w+\(.*\)$/") and keyword_function_calls is true, then
1455 it is returned unmodified. Returns undef if STRING could not be
1456 parsed as a valid "datetime" value.
1457
1458 parse_interval STRING [, MODE]
1459 Parse STRING and return a DateTime::Duration object. STRING should
1460 be formatted according to the data source's native "interval"
1461 (years, months, days, hours, minutes, seconds) data type.
1462
1463 If STRING is a DateTime::Duration object, a valid interval keyword
1464 (according to validate_interval_keyword), or if it looks like a
1465 function call (matches "/^\w+\(.*\)$/") and keyword_function_calls
1466 is true, then it is returned unmodified. Otherwise, undef is
1467 returned if STRING could not be parsed as a valid "interval" value.
1468
1469 This optional MODE argument determines how math is done on duration
1470 objects. If defined, the "end_of_month" setting for each
1471 DateTime::Duration object created by this column will have its mode
1472 set to MODE. Otherwise, the "end_of_month" parameter will not be
1473 passed to the DateTime::Duration constructor.
1474
1475 Valid modes are "wrap", "limit", and "preserve". See the
1476 documentation for DateTime::Duration for a full explanation.
1477
1478 parse_time STRING
1479 Parse STRING and return a Time::Clock object. STRING should be
1480 formatted according to the data source's native "time" (hour,
1481 minute, second, fractional seconds) data type.
1482
1483 If STRING is a valid time keyword (according to
1484 validate_time_keyword) or if it looks like a function call (matches
1485 "/^\w+\(.*\)$/") and keyword_function_calls is true, then it is
1486 returned unmodified. Returns undef if STRING could not be parsed
1487 as a valid "time" value.
1488
1489 parse_timestamp STRING
1490 Parse STRING and return a DateTime object. STRING should be
1491 formatted according to the data source's native "timestamp" (month,
1492 day, year, hour, minute, second, fractional seconds) data type.
1493 Fractional seconds are optional, and the acceptable precision may
1494 vary depending on the data source.
1495
1496 If STRING is a valid timestamp keyword (according to
1497 validate_timestamp_keyword) or if it looks like a function call
1498 (matches "/^\w+\(.*\)$/") and keyword_function_calls is true, then
1499 it is returned unmodified. Returns undef if STRING could not be
1500 parsed as a valid "timestamp" value.
1501
1502 parse_timestamp_with_time_zone STRING
1503 Parse STRING and return a DateTime object. STRING should be
1504 formatted according to the data source's native "timestamp with
1505 time zone" (month, day, year, hour, minute, second, fractional
1506 seconds, time zone) data type. Fractional seconds are optional,
1507 and the acceptable precision may vary depending on the data source.
1508
1509 If STRING is a valid timestamp keyword (according to
1510 validate_timestamp_keyword) or if it looks like a function call
1511 (matches "/^\w+\(.*\)$/") and keyword_function_calls is true, then
1512 it is returned unmodified. Returns undef if STRING could not be
1513 parsed as a valid "timestamp with time zone" value.
1514
1515 validate_boolean_keyword STRING
1516 Returns true if STRING is a valid keyword for the "boolean" data
1517 type of the current data source, false otherwise. The default
1518 implementation accepts the values "TRUE" and "FALSE".
1519
1520 validate_date_keyword STRING
1521 Returns true if STRING is a valid keyword for the "date" (month,
1522 day, year) data type of the current data source, false otherwise.
1523 The default implementation always returns false.
1524
1525 validate_datetime_keyword STRING
1526 Returns true if STRING is a valid keyword for the "datetime"
1527 (month, day, year, hour, minute, second) data type of the current
1528 data source, false otherwise. The default implementation always
1529 returns false.
1530
1531 validate_interval_keyword STRING
1532 Returns true if STRING is a valid keyword for the "interval"
1533 (years, months, days, hours, minutes, seconds) data type of the
1534 current data source, false otherwise. The default implementation
1535 always returns false.
1536
1537 validate_time_keyword STRING
1538 Returns true if STRING is a valid keyword for the "time" (hour,
1539 minute, second, fractional seconds) data type of the current data
1540 source, false otherwise. The default implementation always returns
1541 false.
1542
1543 validate_timestamp_keyword STRING
1544 Returns true if STRING is a valid keyword for the "timestamp"
1545 (month, day, year, hour, minute, second, fractional seconds) data
1546 type of the current data source, false otherwise. The default
1547 implementation always returns false.
1548
1550 The Rose development policy applies to this, and all "Rose::*" modules.
1551 Please install Rose from CPAN and then run ""perldoc Rose"" for more
1552 information.
1553
1555 Any Rose::DB questions or problems can be posted to the
1556 Rose::DB::Object mailing list. (If the volume ever gets high enough,
1557 I'll create a separate list for Rose::DB, but it isn't an issue right
1558 now.) To subscribe to the list or view the archives, go here:
1559
1560 <http://groups.google.com/group/rose-db-object>
1561
1562 Although the mailing list is the preferred support mechanism, you can
1563 also email the author (see below) or file bugs using the CPAN bug
1564 tracking system:
1565
1566 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Rose-DB>
1567
1568 There's also a wiki and other resources linked from the Rose project
1569 home page:
1570
1571 <http://rosecode.org>
1572
1574 Kostas Chatzikokolakis, Peter Karman, Brian Duggan, Lucian Dragus, Ask
1575 Bjørn Hansen, Sergey Leschenko, Ron Savage
1576
1578 John C. Siracusa (siracusa@gmail.com)
1579
1581 Copyright (c) 2010 by John C. Siracusa. All rights reserved. This
1582 program is free software; you can redistribute it and/or modify it
1583 under the same terms as Perl itself.
1584
1585
1586
1587perl v5.28.1 2016-06-28 Rose::DB(3)