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;
17 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server - Support for Microsoft
18 SQL Server via DBD::Sybase
22 This subclass supports MSSQL server connections via L<DBD::Sybase>.
26 This driver tries to determine whether your version of L<DBD::Sybase> and
27 supporting libraries (usually FreeTDS) support using placeholders, if not the
28 storage will be reblessed to
29 L<DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars>.
31 The MSSQL specific functionality is provided by
32 L<DBIx::Class::Storage::DBI::MSSQL>.
38 __PACKAGE__->datetime_parser_type(
39 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format'
44 my $dbh = $self->_get_dbh;
46 return if ref $self ne __PACKAGE__;
47 if (not $self->_use_typeless_placeholders) {
48 carp_once <<'EOF' unless $ENV{DBIC_MSSQL_FREETDS_LOWVER_NOWARN};
49 Placeholders do not seem to be supported in your configuration of
52 This means you are taking a large performance hit, as caching of prepared
53 statements is disabled.
55 Make sure to configure your server with "tds version" of 8.0 or 7.0 in
56 /etc/freetds/freetds.conf .
58 To turn off this warning, set the DBIC_MSSQL_FREETDS_LOWVER_NOWARN environment
62 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars;
64 'DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::NoBindVars';
72 $self->next::method(@_);
74 # work around massively broken freetds versions after 0.82
75 # - explicitly no scope_identity
78 # warn about the fact as well, do not provide a mechanism to shut it up
79 if ($self->_using_freetds and (my $ver = $self->_using_freetds_version||999) > 0.82) {
81 "Your DBD::Sybase was compiled against buggy FreeTDS version $ver. "
82 . 'Statement caching does not work and will be disabled.'
85 $self->_identity_method('@@identity');
86 $self->_no_scope_identity_query(1);
87 $self->disable_sth_caching(1);
91 # invoked only if DBD::Sybase is compiled against FreeTDS
92 sub _set_autocommit_stmt {
95 return 'SET IMPLICIT_TRANSACTIONS ' . ($on ? 'OFF' : 'ON');
98 sub _get_server_version {
101 my $product_version = $self->_get_dbh->selectrow_hashref('master.dbo.xp_msver ProductVersion');
103 if ((my $version = $product_version->{Character_Value}) =~ /^(\d+)\./) {
107 $self->throw_exception(
108 "MSSQL Version Retrieval Failed, Your ProductVersion's Character_Value is missing or malformed!"
113 =head2 connect_call_datetime_setup
117 on_connect_call => 'datetime_setup'
119 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set:
121 $dbh->syb_date_fmt('ISO_strict'); # output fmt: 2004-08-21T14:36:48.080Z
123 On connection for use with L<DBIx::Class::InflateColumn::DateTime>
125 This works for both C<DATETIME> and C<SMALLDATETIME> columns, although
126 C<SMALLDATETIME> columns only have minute precision.
130 sub connect_call_datetime_setup {
132 my $dbh = $self->_get_dbh;
134 if ($dbh->can('syb_date_fmt')) {
135 # amazingly, this works with FreeTDS
136 $dbh->syb_date_fmt('ISO_strict');
140 'Your DBD::Sybase is too old to support '
141 . 'DBIx::Class::InflateColumn::DateTime, please upgrade!';
146 package # hide from PAUSE
147 DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server::DateTime::Format;
149 my $datetime_parse_format = '%Y-%m-%dT%H:%M:%S.%3NZ';
150 my $datetime_format_format = '%Y-%m-%d %H:%M:%S.%3N'; # %F %T
152 my ($datetime_parser, $datetime_formatter);
156 require DateTime::Format::Strptime;
157 $datetime_parser ||= DateTime::Format::Strptime->new(
158 pattern => $datetime_parse_format,
161 return $datetime_parser->parse_datetime(shift);
164 sub format_datetime {
166 require DateTime::Format::Strptime;
167 $datetime_formatter ||= DateTime::Format::Strptime->new(
168 pattern => $datetime_format_format,
171 return $datetime_formatter->format_datetime(shift);
174 =head1 FURTHER QUESTIONS?
176 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
178 =head1 COPYRIGHT AND LICENSE
180 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
181 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
182 redistribute it and/or modify it under the same terms as the
183 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.