forked from stetard/DNN.Repository
-
Notifications
You must be signed in to change notification settings - Fork 1
/
03.01.04.SqlDataProvider
85 lines (71 loc) · 2.87 KB
/
03.01.04.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
/* =====================================================================*/
/***** Initialization Script 03.01.04 *****/
/* =====================================================================*/
/* convert the Category and Attribute data from the grmRepositoryObjects where it is */
/* stored in columns as delimited strings to the new schema */
/* if the CategoryId column exists, we need to upgrade */
IF NOT (SELECT COLUMNPROPERTY( OBJECT_ID('{databaseOwner}{objectQualifier}grmRepositoryObjects'),'CategoryId','AllowsNull')) IS NULL
BEGIN
DECLARE
@ItemID int,
@CategoryId nvarchar(50),
@Attributes nvarchar(150),
@lcListWork varchar(150),
@tcDelimiter nvarchar(1),
@lnCommaPos int,
@lcItem varchar(150)
DECLARE myCursor CURSOR FOR
SELECT ItemID, CategoryId, Attributes from {databaseOwner}{objectQualifier}grmRepositoryObjects
OPEN myCursor
FETCH NEXT FROM myCursor INTO @ItemID, @CategoryId, @Attributes
WHILE @@FETCH_STATUS = 0
BEGIN
DELETE FROM {databaseOwner}{objectQualifier}grmRepositoryObjectCategories WHERE ObjectID = @ItemID
DELETE FROM {databaseOwner}{objectQualifier}grmRepositoryObjectValues WHERE ObjectID = @ItemID
SET @lcListWork = @CategoryId
SET @tcDelimiter = ';'
WHILE LEN(@lcListWork) > 0
BEGIN
SET @lnCommaPos = CHARINDEX(@tcDelimiter, @lcListWork)
IF @lnCommaPos > 0
BEGIN
SET @lcItem = SUBSTRING(@lcListWork, 1, @lnCommaPos - 1)
SET @lcListWork = SUBSTRING(@lcListWork, @lnCommaPos + 1, LEN(@lcListWork) - @lnCommaPos)
END
ELSE
BEGIN
SET @lcItem = @lcListWork
SET @lcListWork = ''
END
IF @lcItem <> ''
INSERT INTO {databaseOwner}{objectQualifier}grmRepositoryObjectCategories (ObjectID, CategoryId) VALUES (@ItemID, @lcItem)
END
SET @lcListWork = @Attributes
SET @tcDelimiter = ';'
WHILE LEN(@lcListWork) > 0
BEGIN
SET @lnCommaPos = CHARINDEX(@tcDelimiter, @lcListWork)
IF @lnCommaPos > 0
BEGIN
SET @lcItem = SUBSTRING(@lcListWork, 1, @lnCommaPos - 1)
SET @lcListWork = SUBSTRING(@lcListWork, @lnCommaPos + 1, LEN(@lcListWork) - @lnCommaPos)
END
ELSE
BEGIN
SET @lcItem = @lcListWork
SET @lcListWork = ''
END
IF @lcItem <> ''
INSERT INTO {databaseOwner}{objectQualifier}grmRepositoryObjectValues (ObjectID, ValueId) VALUES (@ItemID, @lcItem)
END
FETCH NEXT FROM myCursor INTO @ItemID, @CategoryId, @Attributes
END
CLOSE myCursor
DEALLOCATE myCursor
END
IF NOT (SELECT COLUMNPROPERTY( OBJECT_ID('{databaseOwner}{objectQualifier}grmRepositoryObjects'),'CategoryId','AllowsNull')) IS NULL
ALTER TABLE {databaseOwner}{objectQualifier}grmRepositoryObjects DROP COLUMN CategoryId
GO
IF NOT (SELECT COLUMNPROPERTY( OBJECT_ID('{databaseOwner}{objectQualifier}grmRepositoryObjects'),'Attributes','AllowsNull')) IS NULL
ALTER TABLE {databaseOwner}{objectQualifier}grmRepositoryObjects DROP COLUMN Attributes
GO