Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

new to clr Integration, Expand / Collapse
Author
Message
Posted Thursday, June 7, 2012 1:14 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: 2 days ago @ 12:37 PM
Points: 52, Visits: 227
I am creating a small project to read match regex from sql,

.cs file
using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Collections;
using System.Text.RegularExpressions;





public partial class RegExBase
{
[SqlFunction(IsDeterministic = true, IsPrecise = true)]
public static bool RegexSHIP(string matchString, string pattern)
{
Regex r1 = new Regex(pattern.TrimEnd(null));

return Regex.Match(matchString.TrimEnd(null), pattern.TrimEnd(null)).Success;
}


};

Test.sql
select * from [databasename].[dbo].tablename as P, [databasename].[dbo].tablename as S

where P.UserID = 'Rep'

and S.UserID = P.UserID

and dbo.RegexSHIP('T_SHIP_123456.txt', S.Pattern) = 1

I have enable clr, created function but still getting the attach error and help to solve that.
Thanks




  Post Attachments 
error.docx (3 views, 177.64 KB)
Post #1312741
Posted Thursday, June 7, 2012 1:19 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 7:44 AM
Points: 12,910, Visits: 32,015
the error message is related to debugging.

do you really need to debug the CLR?
why not just deploy the project, then test it in q window for known pattern/values?


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1312743
Posted Thursday, June 7, 2012 2:14 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: 2 days ago @ 12:37 PM
Points: 52, Visits: 227
do you really need to debug the CLR? No

All I want is to test it.

why not just deploy the project, then test it in q window for known pattern/values?
everything run fine except I don't get any output.
Post #1312777
Posted Thursday, June 7, 2012 3:09 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: 2 days ago @ 12:37 PM
Points: 52, Visits: 227
I think I solved my issue, it was from my data it needed some clean up
Post #1312793
Posted Friday, June 8, 2012 7:17 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 10:11 AM
Points: 36,995, Visits: 31,516
Slightly off subject, it's been reported that some forms of Regex CLR are quite slow. If it does turn out to be one of the slow ones, it won't look slow on just a couple of rows but could take quite some time if you're batch processing several thousand rows.

To be sure, I'm not in any way shape or form saying to avoid CLRs. I'm saying the same as I would for any type of code where there was a known issue including T-SQL and to simply be aware of it.

The question that I would have is what are you doing in RegEx that a more simple LIKE or other pattern matching in T-SQL can't do for you? The reason why I'm asking that is because if you are using Regex to replace the simple pattern matching that you can do in T-SQL, there's a very high probability that functionality will be a fair bit slower than the equivalent T-SQL code.



--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1313114
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse