-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateAssemblyTemplate.sql
More file actions
553 lines (472 loc) · 20.8 KB
/
Copy pathCreateAssemblyTemplate.sql
File metadata and controls
553 lines (472 loc) · 20.8 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/* Source code for the library at: https://github.com/Ascentis/mssql-regex */
PRINT 'Checking if regex package already exists...';
DECLARE @clrName nvarchar(4000) = 'Ascentis.RegExSql';
DECLARE @asmBin varbinary(max) = <BinaryDll>;
DECLARE @hash varbinary(64);
SELECT @hash = HASHBYTES('SHA2_512', @asmBin);
IF NOT EXISTS (select *
from sys.assembly_files f
where HASHBYTES('SHA2_512', f.content) = @hash
AND f.name = @clrName)
BEGIN
PRINT 'Dropping regex functions';
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExIsMatch]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExIsMatch;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExIsMatchWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExIsMatchWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatch]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatch;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchIndexed]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchIndexed;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchIndexedWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchIndexedWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExSplit]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExSplit;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExSplitWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExSplitWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExReplace]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExReplace;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExReplaceWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExReplaceWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExReplaceCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExReplaceCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExReplaceCountWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExReplaceCountWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExEscape]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExEscape;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExUnescape]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExUnescape;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatches]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatches;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchesWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchesWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchGroup]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchGroup;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchGroupWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchGroupWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchGroupIndexed]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchGroupIndexed;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchGroupIndexedWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchGroupIndexedWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchesGroup]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchesGroup;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchesGroupWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchesGroupWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchesGroups]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchesGroups;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExMatchesGroupsWithOptions]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExMatchesGroupsWithOptions;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExCachedCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExCachedCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExCacheHitCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExCacheHitCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExClearCache]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExClearCache;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExExecCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExExecCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExExceptionCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExExceptionCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExResetExecCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExResetExecCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExResetCacheHitCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExResetCacheHitCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExResetExceptionCount]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExResetExceptionCount;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExSetCacheEntryExpirationMilliseconds]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExSetCacheEntryExpirationMilliseconds;
IF EXISTS (SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[RegExCacheList]')
AND type IN ( N'FN', N'IF', N'TF', N'FS', N'FT' ))
DROP FUNCTION RegExCacheList;
PRINT 'Dropping existing assemblies matching name "Ascentis.RegExQL"'
IF EXISTS (select *
from sys.assembly_files f
full outer join sys.assemblies a
on f.assembly_id=a.assembly_id
where a.name ='Ascentis.RegExSQL')
DROP ASSEMBLY [Ascentis.RegExSQL];
PRINT 'Resetting CLR Security to "Enabled"'
IF EXISTS(SELECT *
from sys.configurations
where name = 'clr strict security' and value = 0)
EXEC SP_CONFIGURE 'clr strict security', 1;
RECONFIGURE;
PRINT 'Adding our assembly to list of trusted assemblies'
IF EXISTS(SELECT * from sys.trusted_assemblies
WHERE description = 'Ascentis.RegExSql')
BEGIN
DECLARE @UnTrustAssembliesCmd nvarchar(max) = '';
SELECT @UnTrustAssembliesCmd = @UnTrustAssembliesCmd + 'EXEC sys.sp_drop_trusted_assembly @hash = ' + CONVERT(varchar(max), hash, 1) + ';'
FROM sys.trusted_assemblies
WHERE description = 'Ascentis.RegExSql';
EXEC sp_executesql @UnTrustAssembliesCmd;
END;
EXEC sys.sp_add_trusted_assembly @hash = @hash, @description = @clrName;
PRINT 'Pushing our assembly into the database';
CREATE ASSEMBLY [Ascentis.RegExSQL]
FROM @asmBin
WITH PERMISSION_SET = UNSAFE;
PRINT 'Creating function stubs';
DECLARE @CreateFnCommand nvarchar(max) = '';
SET @CreateFnCommand = '
CREATE FUNCTION RegExIsMatch(
@input nvarchar(max),
@pattern nvarchar(max)
)
RETURNS bit EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledIsMatch;';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExIsMatchWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@options int
)
RETURNS bit EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledIsMatchWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatch(
@input nvarchar(max),
@pattern nvarchar(max)
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatch'
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@options int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchWithOptions'
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchIndexed(
@input nvarchar(max),
@pattern nvarchar(max),
@index int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchIndexed';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchIndexedWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@index int,
@options int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchIndexedWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchGroup(
@input nvarchar(max),
@pattern nvarchar(max),
@group int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchGroup';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchGroupWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@group int,
@options int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchGroupWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchGroupIndexed(
@input nvarchar(max),
@pattern nvarchar(max),
@group int,
@index int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchGroupIndexed';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchGroupIndexedWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@group int,
@index int,
@options int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchGroupIndexedWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExReplace(
@input nvarchar(max),
@pattern nvarchar(max),
@replacement nvarchar(max)
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledReplace';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExReplaceWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@replacement nvarchar(max),
@options int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledReplaceWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExReplaceCount(
@input nvarchar(max),
@pattern nvarchar(max),
@replacement nvarchar(max),
@count int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledReplaceCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExReplaceCountWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@replacement nvarchar(max),
@count int,
@options int
)
RETURNS nvarchar(max) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledReplaceCountWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExSplit(
@input nvarchar(max),
@pattern nvarchar(max)
)
RETURNS TABLE (ITEM NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledSplit';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExSplitWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@options int
)
RETURNS TABLE (ITEM NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledSplitWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExEscape(
@input nvarchar(max)
)
RETURNS NVARCHAR(MAX) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledEscape';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExUnescape(
@input nvarchar(max)
)
RETURNS NVARCHAR(MAX) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledUnescape';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatches(
@input nvarchar(max),
@pattern nvarchar(max)
)
RETURNS TABLE (ITEM NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatches';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchesWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@options int
)
RETURNS TABLE (ITEM NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchesWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchesGroup(
@input nvarchar(max),
@pattern nvarchar(max),
@group int
)
RETURNS TABLE (ITEM NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchesGroup';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchesGroupWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@group int,
@options int
)
RETURNS TABLE (ITEM NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchesGroupWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchesGroupsWithOptions(
@input nvarchar(max),
@pattern nvarchar(max),
@options int
)
RETURNS TABLE (
MatchNum int,
GrpNum int,
GrpName nvarchar(255),
Item NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchesGroupsWithOptions';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExMatchesGroups(
@input nvarchar(max),
@pattern nvarchar(max)
)
RETURNS TABLE (
MatchNum int,
GrpNum int,
GrpName nvarchar(255),
Item NVARCHAR(MAX)) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCompiledMatchesGroups';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExCachedCount()
RETURNS INT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCachedCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExClearCache()
RETURNS INT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExClearCache';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExExecCount()
RETURNS BIGINT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExExecCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExCacheHitCount()
RETURNS BIGINT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCacheHitCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExExceptionCount()
RETURNS BIGINT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExExceptionCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExResetExecCount()
RETURNS BIGINT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExResetExecCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExResetCacheHitCount()
RETURNS BIGINT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExResetCacheHitCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExResetExceptionCount()
RETURNS BIGINT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExResetExceptionCount';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExSetCacheEntryExpirationMilliseconds(
@cacheEntryExpirationMilliseconds int
)
RETURNS INT EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExSetCacheEntryExpirationMilliseconds';
EXEC sp_executesql @CreateFnCommand;
SET @CreateFnCommand = '
CREATE FUNCTION RegExCacheList()
RETURNS TABLE (
PATTERN NVARCHAR(MAX),
OPTIONS INT,
CACHEREGEXCOUNT INT,
TTL INT) EXTERNAL NAME [Ascentis.RegExSQL].RegExCompiled.RegExCacheList';
EXEC sp_executesql @CreateFnCommand;
END
ELSE
BEGIN
PRINT 'Assembly already exists. Exiting';
END
GO
PRINT 'Testing our regex library...'
IF NOT EXISTS(SELECT *
FROM dbo.RegExMatches('SM1,M 29,B 13', '(^|,)(E372|M 29|E275|B 13)((?=,)|(?=$))'))
BEGIN
THROW 50001, 'Something is wrong with regex library. Expected matches calling RegExMatches(). Test failed', 1;
END
PRINT 'Test passed';