Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 21, 2016 1:06 PM
Points: 78, Visits: 324
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: Today @ 1:42 PM
Points: 14,444, Visits: 37,853
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Post #1312743
Posted Thursday, June 7, 2012 2:14 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 21, 2016 1:06 PM
Points: 78, Visits: 324
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
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, July 21, 2016 1:06 PM
Points: 78, Visits: 324
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-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 2:02 PM
Points: 40,993, Visits: 38,292
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."

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

Add to briefcase

Permissions Expand / Collapse