1DateTime::Format::DBI(3U)ser Contributed Perl DocumentatiDoanteTime::Format::DBI(3)
2
3
4
6 DateTime::Format::DBI - Find a parser class for a database connection.
7
9 use DBI;
10 use DateTime;
11 use DateTime::Format::DBI;
12
13 my $db = DBI->connect('dbi:...');
14 my $db_parser = DateTime::Format::DBI->new($dbh);
15 my $dt = DateTime->now();
16
17 $db->do("UPDATE table SET dt=? WHERE foo='bar'",undef,
18 $db_parser->format_datetime($dt);
19
21 This module finds a "DateTime::Format::*" class that is suitable for
22 the use with a given DBI connection (and "DBD::*" driver).
23
24 It currently supports the following format modules: IBM DB2 (DB2),
25 Microsoft SQL (MSSQL), MySQL, Oracle, PostgreSQL (Pg), SQLite, and
26 Sybase.
27
28 NOTE: This module provides a quick method to find the correct parser
29 and formatter class. However, this is usually not sufficient for full
30 database abstraction. You will also have to cater for differences in
31 the syntax and semantics of SQL datetime functions (and other SQL
32 commands).
33
35 This module provides a single factory method:
36
37 · new( $dbh )
38
39 Creates a new "DateTime::Format::*" instance, the exact class of
40 which depends on the database driver used for the database
41 connection referenced by $dbh.
42
44 "DateTime::Format::DBI" is just a front-end class factory that will
45 return one of the format classes based on the nature of your $dbh.
46
47 For information on the interface of the returned parser object, please
48 see the documentation for the class pertaining to your particular $dbh.
49
50 In general, parser classes for databases will implement the following
51 methods. For more information on the exact behaviour of these methods,
52 see the documentation of the parser class.
53
54 · parse_datetime( $string )
55
56 Given a string containing a date and/or time representation from
57 the database used, this method will return a new "DateTime" object.
58
59 If given an improperly formatted string, this method may die.
60
61 · format_datetime( $dt )
62
63 Given a "DateTime" object, this method returns a string appropriate
64 as input for all or the most common date and date/time types of the
65 database used.
66
67 · parse_duration( $string )
68
69 Given a string containing a duration representation from the
70 database used, this method will return a new "DateTime::Duration"
71 object.
72
73 If given an improperly formatted string, this method may die.
74
75 Not all databases and format/formatter classes support durations;
76 please use UNIVERSAL::has to check for the availability of this
77 method.
78
79 · format_duration( $du )
80
81 Given a "DateTime::Duration" object, this method returns a string
82 appropriate as input for the duration or interval type of the
83 database used.
84
85 Not all databases and parser/formatter classes support durations;
86 please use UNIVERSAL::has to check for the availability of this
87 method.
88
89 Parser/formatter classes may additionally define methods like
90 parse_type or format_type (where type is derived from the SQL type);
91 please see the documentation of the individual format class for more
92 information.
93
95 Please report bugs and other requests to the rt tracker:
96 <https://rt.cpan.org/Public/Dist/Display.html?Name=DateTime-Format-DBI>.
97
99 Claus Färber <CFAERBER@cpan.org>
100
102 Copyright 2003-2013 Claus Färber. All rights reserved.
103
104 This program is free software; you can redistribute it and/or modify it
105 under the same terms as Perl itself.
106
107 The full text of the license can be found in the LICENSE file included
108 with this module.
109
111 DateTime, DBI
112
113 datetime@perl.org mailing list
114
115 http://datetime.perl.org/
116
117
118
119perl v5.30.0 2019-07-26 DateTime::Format::DBI(3)