-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01.00.00.SqlDataProvider
175 lines (128 loc) · 4.95 KB
/
01.00.00.SqlDataProvider
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/************************************************************/
/***** SqlDataProvider *****/
/***** *****/
/***** *****/
/***** Note: To manually execute this script you must *****/
/***** perform a search and replace operation *****/
/***** for {databaseOwner} and {objectQualifier} *****/
/***** *****/
/************************************************************/
/** Create Table **/
if not exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_BtbShoutbox]') and OBJECTPROPERTY(id, N'IsTable') = 1)
BEGIN
CREATE TABLE {databaseOwner}[{objectQualifier}BTB_BtbShoutbox]
(
[ModuleID] [int] NOT NULL,
[ItemID] [int] NOT NULL IDENTITY(1, 1),
[Message] [ntext] NOT NULL,
[Username] nvarchar(255) NOT NULL,
[CreatedDate] [datetime] NOT NULL
)
ALTER TABLE {databaseOwner}[{objectQualifier}BTB_BtbShoutbox] ADD CONSTRAINT [PK_{objectQualifier}BTB_BtbShoutbox] PRIMARY KEY CLUSTERED ([ItemID])
CREATE NONCLUSTERED INDEX [IX_{objectQualifier}BTB_BtbShoutbox] ON {databaseOwner}[{objectQualifier}BTB_BtbShoutbox] ([ModuleID])
ALTER TABLE {databaseOwner}[{objectQualifier}BTB_BtbShoutbox] WITH NOCHECK ADD CONSTRAINT [FK_{objectQualifier}BTB_BtbShoutbox_{objectQualifier}Modules] FOREIGN KEY ([ModuleID]) REFERENCES {databaseOwner}[{objectQualifier}Modules] ([ModuleID]) ON DELETE CASCADE NOT FOR REPLICATION
END
GO
/** Drop Existing Stored Procedures **/
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_GetBtbShoutboxs]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}BTB_GetBtbShoutboxs
GO
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_GetBtbShoutboxsUpdates]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}BTB_GetBtbShoutboxsUpdates
GO
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_GetBtbShoutbox]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}BTB_GetBtbShoutbox
GO
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_AddBtbShoutbox]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}BTB_AddBtbShoutbox
GO
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_UpdateBtbShoutbox]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}BTB_UpdateBtbShoutbox
GO
if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}BTB_DeleteBtbShoutbox]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure {databaseOwner}{objectQualifier}BTB_DeleteBtbShoutbox
GO
/** Create Stored Procedures **/
create procedure {databaseOwner}{objectQualifier}BTB_GetBtbShoutboxs
@ModuleId int,
@limit int
as
set rowcount @limit
select ModuleId,
ItemId,
Message,
Username,
CreatedDate
from {objectQualifier}BTB_BtbShoutbox
where ModuleId = @ModuleId
order by ItemId DESC
set rowcount 0
GO
create procedure {databaseOwner}{objectQualifier}BTB_GetBtbShoutboxsUpdates
@ModuleId int,
@lastItemId int
as
select ModuleId,
ItemId,
Message,
Username,
CreatedDate
from {objectQualifier}BTB_BtbShoutbox
where ModuleId = @ModuleId and ItemId > @lastItemId
GO
create procedure {databaseOwner}{objectQualifier}BTB_GetBtbShoutbox
@ModuleId int,
@ItemId int
as
select ModuleId,
ItemId,
Message,
Username,
CreatedDate
from {objectQualifier}BTB_BtbShoutbox
where ModuleId = @ModuleId
and ItemId = @ItemId
GO
create procedure {databaseOwner}{objectQualifier}BTB_AddBtbShoutbox
@ModuleId int,
@Message ntext,
@Username nvarchar(255)
as
insert into {objectQualifier}BTB_BtbShoutbox (
ModuleId,
Message,
Username,
CreatedDate
)
values (
@ModuleId,
@Message,
@Username,
getdate()
)
GO
create procedure {databaseOwner}{objectQualifier}BTB_UpdateBtbShoutbox
@ModuleId int,
@ItemId int,
@Message ntext,
@Username nvarchar(255)
as
update {objectQualifier}BTB_BtbShoutbox
set Message = @Message,
Username = @Username,
CreatedDate = getdate()
where ModuleId = @ModuleId
and ItemId = @ItemId
GO
create procedure {databaseOwner}{objectQualifier}BTB_DeleteBtbShoutbox
@ModuleId int,
@ItemId int
as
delete
from {objectQualifier}BTB_BtbShoutbox
where ModuleId = @ModuleId
and ItemId = @ItemId
GO
/************************************************************/
/***** SqlDataProvider *****/
/************************************************************/