1 package DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server;
7 DBIx::Class::Storage::DBI::Sybase
8 DBIx::Class::Storage::DBI::MSSQL
12 use DBIx::Class::Carp;
16 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server - Support for Microsoft
17 SQL Server via DBD::Sybase
21 This subclass supports MSSQL server connections via L<DBD::Sybase>.
25 This driver tries to determine whether your version of L<DBD::Sybase> and
26 supporting libraries (usually FreeTDS) support using placeholders, if not the
27 storage will be reblessed to
28 L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars>.
30 The MSSQL specific functionality is provided by
31 L<DBIx::Class::Storage::DBI::MSSQL>.
37 __PACKAGE__->datetime_parser_type(
38 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format'
43 my $dbh = $self->_get_dbh;
45 return if ref $self ne __PACKAGE__;
46 if (not $self->_use_typeless_placeholders) {
47 carp_once <<'EOF' unless $ENV{DBIC_MSSQL_FREETDS_LOWVER_NOWARN};
48 Placeholders do not seem to be supported in your configuration of
51 This means you are taking a large performance hit, as caching of prepared
52 statements is disabled.
54 Make sure to configure your server with "tds version" of 8.0 or 7.0 in
55 /etc/freetds/freetds.conf .
57 To turn off this warning, set the DBIC_MSSQL_FREETDS_LOWVER_NOWARN environment
61 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars;
63 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars';
71 $self->next::method(@_);
73 # work around massively broken freetds versions after 0.82
74 # - explicitly no scope_identity
77 # warn about the fact as well, do not provide a mechanism to shut it up
78 if ($self->_using_freetds and (my $ver = $self->_using_freetds_version||999) > 0.82) {
80 "Your DBD::Sybase was compiled against buggy FreeTDS version $ver. "
81 . 'Statement caching does not work and will be disabled.'
84 $self->_identity_method('@@identity');
85 $self->_no_scope_identity_query(1);
86 $self->disable_sth_caching(1);
90 # invoked only if DBD::Sybase is compiled against FreeTDS
91 sub _set_autocommit_stmt {
94 return 'SET IMPLICIT_TRANSACTIONS ' . ($on ? 'OFF' : 'ON');
97 sub _get_server_version {
100 my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion');
102 if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) {
106 $self->throw_exception(
107 "MSSQL Version Retrieval Failed, Your ProductVersion's Character_Value is missing or malformed!"
112 =head2 connect_call_datetime_setup
116 on_connect_call => 'datetime_setup'
118 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set:
120 $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z
122 On connection for use with L<DBIx::Class::InflateColumn::DateTime>
124 This works for both C<DATETIME> and C<SMALLDATETIME> columns, although
125 C<SMALLDATETIME> columns only have minute precision.
129 sub connect_call_datetime_setup {
131 my $dbh = $self->_get_dbh;
133 if ($dbh->can('syb_date_fmt')) {
134 # amazingly, this works with FreeTDS
135 $dbh->syb_date_fmt('ISO_strict');
139 'Your DBD::Sybase is too old to support '
140 . 'DBIx::Class::InflateColumn::DateTime, please upgrade!';
145 package # hide from PAUSE
146 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format;
148 my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ';
149 my $datetime_format_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T
151 my ($datetime_parser, $datetime_formatter);
155 require DateTime::Format::Strptime;
156 $datetime_parser ||= DateTime::Format::Strptime->new(
157 pattern => $datetime_parse_format,
160 return $datetime_parser->parse_datetime(shift);
163 sub format_datetime {
165 require DateTime::Format::Strptime;
166 $datetime_formatter ||= DateTime::Format::Strptime->new(
167 pattern => $datetime_format_format,
170 return $datetime_formatter->format_datetime(shift);
177 See L<DBIx::Class/CONTRIBUTORS>.
181 You may distribute this code under the same terms as Perl itself.