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
| ALTER FUNCTION fn_parse_update(@invoer VARCHAR(2048)) RETURNS @result TABLE(
tabelnaam VARCHAR(255), actie VARCHAR(255), set_kolom VARCHAR(255), set_waarde VARCHAR(255))
AS
BEGIN
--DECLARE @invoer VARCHAR(2048)
DECLARE @positie INT
DECLARE @tabelnaam VARCHAR(255)
DECLARE @aantal_sets INT
DECLARE @set_kolom VARCHAR(255)
DECLARE @set_waarde VARCHAR(255)
DECLARE @aantal_haakjes_openen INT
DECLARE @aantal_haakjes_sluiten INT
DECLARE @haakjes_gelijk INT
DECLARE @temp VARCHAR(255)
--SET @invoer = ' Update _Opdracht Set OpdrachtAanmaakDT = dbo.fn_TimeNil( getdate()), OpdrachtHistorie = "Aangemaakt op: "+ CONVERT(varchar(10), GetDate(), 104) Where '
SET @invoer = LTRIM(RTRIM(@invoer))
SET @temp = @invoer
SET @haakjes_gelijk = 0
-- Haal UPDATE weg, sla tabelnaam op en haalt tabelnaam + SET weg
SET @invoer = SUBSTRING(@invoer, 8, LEN(@invoer) - 7)
SET @positie = CHARINDEX(' ', @invoer)
SET @tabelnaam = SUBSTRING(@invoer, 1, @positie - 1)
SET @invoer = LTRIM(RTRIM(SUBSTRING(@invoer, @positie + 6, LEN(@invoer) - @positie)))
SET @positie = dbo.fn_zoek_keyword('WHERE', @invoer, ' ')
SET @invoer = SUBSTRING(@invoer, 1, @positie)
-- Controleer hoeveel waarden er 'ge-set' worden en sla de waarden/kolommen op
SET @aantal_sets = dbo.fn_aantal_char(@invoer, ',') + 1
WHILE @aantal_sets != 0
BEGIN
IF ( CHARINDEX(',', @invoer)) = 1 SET @invoer = LTRIM(SUBSTRING(@invoer, 2, LEN(@invoer) - 1))
SET @positie = CHARINDEX(' ', @invoer)
SET @set_kolom = SUBSTRING(@invoer, 1, @positie - 1)
SET @invoer = SUBSTRING(@invoer, @positie + 3, LEN(@invoer) - @positie - 2)
SET @positie = CHARINDEX(',', @invoer)
IF @positie = 0
BEGIN
SET @set_waarde = RTRIM(@invoer)
END
ELSE
BEGIN
SET @positie = CHARINDEX(',', @invoer)
SET @aantal_haakjes_openen = dbo.fn_aantal_char(SUBSTRING(@invoer, 1, @positie - 1), '(')
SET @aantal_haakjes_sluiten = dbo.fn_aantal_char(SUBSTRING(@invoer, 1, @positie - 1), ')')
IF (@aantal_haakjes_openen != @aantal_haakjes_sluiten)
BEGIN
SET @aantal_sets = @aantal_sets - 1
WHILE @haakjes_gelijk = 0
BEGIN
SET @positie = CHARINDEX(',', @invoer, @positie + 1)
IF @positie = 0 SET @positie = LEN(@invoer)
SET @aantal_haakjes_openen = dbo.fn_aantal_char(SUBSTRING(@invoer, 1, @positie), '(')
SET @aantal_haakjes_sluiten = dbo.fn_aantal_char(SUBSTRING(@invoer, 1, @positie), ')')
IF (@aantal_haakjes_openen = @aantal_haakjes_sluiten) SET @haakjes_gelijk = 1
ELSE SET @aantal_sets = @aantal_sets - 1
END
END
SET @set_waarde = SUBSTRING(@invoer, 1, @positie - 1)
SET @invoer = LTRIM(RTRIM(SUBSTRING(@invoer, @positie + 1, LEN(@invoer) - @positie)))
END
SET @aantal_sets = @aantal_sets - 1
INSERT INTO @result VALUES (@tabelnaam, 'UPDATE', @set_kolom, @set_waarde)
END
RETURN
END |