1DBIx::Class::Storage::DUBsIe:r:MCSoSnQtLr(i3b)uted PerlDDBoIcxu:m:eCnltaastsi:o:nStorage::DBI::MSSQL(3)
2
3
4

NAME

6       DBIx::Class::Storage::DBI::MSSQL - Base Class for Microsoft SQL Server
7       support in DBIx::Class
8

SYNOPSIS

10       This is the base class for Microsoft SQL Server support, used by
11       DBIx::Class::Storage::DBI::ODBC::Microsoft_SQL_Server and
12       DBIx::Class::Storage::DBI::Sybase::Microsoft_SQL_Server.
13

IMPLEMENTATION NOTES

15   IDENTITY information
16       Microsoft SQL Server supports three methods of retrieving the IDENTITY
17       value for inserted row: IDENT_CURRENT, @@IDENTITY, and
18       SCOPE_IDENTITY().  SCOPE_IDENTITY is used here because it is the
19       safest.  However, it must be called is the same execute statement, not
20       just the same connection.
21
22       So, this implementation appends a SELECT SCOPE_IDENTITY() statement
23       onto each INSERT to accommodate that requirement.
24
25       "SELECT @@IDENTITY" can also be used by issuing:
26
27         $self->_identity_method('@@identity');
28
29       it will only be used if SCOPE_IDENTITY() fails.
30
31       This is more dangerous, as inserting into a table with an on insert
32       trigger that inserts into another table with an identity will give
33       erroneous results on recent versions of SQL Server.
34
35   identity insert
36       Be aware that we have tried to make things as simple as possible for
37       our users.  For MSSQL that means that when a user tries to create a
38       row, while supplying an explicit value for an autoincrementing column,
39       we will try to issue the appropriate database call to make this
40       possible, namely "SET IDENTITY_INSERT $table_name ON". Unfortunately
41       this operation in MSSQL requires the "db_ddladmin" privilege, which is
42       normally not included in the standard write-permissions.
43
44   Ordered Subselects
45       If you attempted the following query (among many others) in Microsoft
46       SQL Server
47
48        $rs->search ({}, {
49         prefetch => 'relation',
50         rows => 2,
51         offset => 3,
52        });
53
54       You may be surprised to receive an exception. The reason for this is a
55       quirk in the MSSQL engine itself, and sadly doesn't have a sensible
56       workaround due to the way DBIC is built. DBIC can do truly wonderful
57       things with the aid of subselects, and does so automatically when
58       necessary. The list of situations when a subselect is necessary is long
59       and still changes often, so it can not be exhaustively enumerated here.
60       The general rule of thumb is a joined has_many relationship with
61       limit/group applied to the left part of the join.
62
63       In its "pursuit of standards" Microsft SQL Server goes to great lengths
64       to forbid the use of ordered subselects. This breaks a very useful
65       group of searches like "Give me things number 4 to 6 (ordered by name),
66       and prefetch all their relations, no matter how many". While there is a
67       hack which fools the syntax checker, the optimizer may still elect to
68       break the subselect.  Testing has determined that while such breakage
69       does occur (the test suite contains an explicit test which demonstrates
70       the problem), it is relative rare. The benefits of ordered subselects
71       are on the other hand too great to be outright disabled for MSSQL.
72
73       Thus compromise between usability and perfection is the MSSQL-specific
74       resultset attribute "unsafe_subselect_ok".  It is deliberately not
75       possible to set this on the Storage level, as the user should inspect
76       (and preferably regression-test) the return of every such ResultSet
77       individually. The example above would work if written like:
78
79        $rs->search ({}, {
80         unsafe_subselect_ok => 1,
81         prefetch => 'relation',
82         rows => 2,
83         offset => 3,
84        });
85
86       If it is possible to rewrite the search() in a way that will avoid the
87       need for this flag - you are urged to do so. If DBIC internals insist
88       that an ordered subselect is necessary for an operation, and you
89       believe there is a different/better way to get the same result - please
90       file a bugreport.
91

FURTHER QUESTIONS?

93       Check the list of additional DBIC resources.
94
96       This module is free software copyright by the DBIx::Class (DBIC)
97       authors. You can redistribute it and/or modify it under the same terms
98       as the DBIx::Class library.
99
100
101
102perl v5.28.0                      2018-01-29DBIx::Class::Storage::DBI::MSSQL(3)
Impressum