HEX TO RAW function for DB2 on z/OS - sql

I need to cast an INT value as HEX (not to hex).
For example, given the value 1234, I want to transform it to x'1234'.
My first inclination was to use the hex function, but that does not produce the desired results:
hex(1234) = x'04D2'
I need a function or algorithm such that
my_function(1234) = x'1234'
EDIT: Thanks to Lennart's answer I learned that it would be the equivalent of HEXTORAW or
VARCHAR_BIT_FORMAT which exist on DB2 for LUW, but not for z/OS

Not sure I understand your question, is this in the ballpark?
with t (s) as (values ('1234'),(x'F0F0F0F0F0F0F0F0F0F0F0F0F0'))
select s
, case when translate(s, '', '0123456789') = ''
then hextoraw(s)
else s
end
from t;
S 2
------------- --------------------------
1234 x'1234'
ððððððððððððð ððððððððððððð

It is possible to do this transformation using the EBCDIC_CHR function. This solution assumes your system character encoding is EBCDIC.
See this thread for discussion, and UDF: http://www.idug.org/p/fo/st/thread=43924
This user defined function is from that thread. It will receive a varchar input and for each pair of values convert them to raw using EBCDIC_CHR, concatenating it all together.
CREATE FUNCTION UDFUNC.HEX2RAW(INSTR VARCHAR(1024))
RETURNS VARCHAR(2048)
DETERMINISTIC
NO EXTERNAL ACTION
CONTAINS SQL
BEGIN
DECLARE invalid_hexval CONDITION FOR SQLSTATE '22007';
DECLARE VALIDSTR VARCHAR(1024) default '';
DECLARE OUTSTR VARCHAR(2048) DEFAULT '';
DECLARE HEXCHR CHAR(16) DEFAULT '0123456789ABCDEF';
DECLARE MODVAL INT DEFAULT 0;
DECLARE LENSTR INT;
DECLARE I INT DEFAULT 0;
DECLARE J INT DEFAULT 0;
IF INSTR IS NULL THEN
RETURN NULL;
END IF;
set VALIDSTR = TRANSLATE(INSTR,'',HEXCHR);
IF (VALIDSTR <> '') THEN
SIGNAL invalid_hexval SET MESSAGE_TEXT = 'Not Hex: [' || CAST(INSTR AS VARCHAR(59))||']';
END IF;
SET MODVAL = MOD(LENGTH(INSTR),2);
IF MODVAL <> 0 THEN
SET INSTR = CONCAT('0',INSTR);
END IF;
SET LENSTR = LENGTH(INSTR);
WHILE I < LENSTR DO
SET J = 16 * (POSSTR(HEXCHR,SUBSTR(INSTR,I+1,1))-1);
SET I = I + 1;
SET J = J + (POSSTR(HEXCHR,SUBSTR(INSTR,I+1,1))-1);
SET I = I + 1;
SET OUTSTR = CONCAT(OUTSTR,EBCDIC_CHR(J));
END WHILE;
RETURN OUTSTR;
END#
Function usage:
SELECT UDFUNC.HEX2RAW('1234')
, HEX(UDFUNC.HEX2RAW('1234'))
, UDFUNC.HEX2RAW('1234567')
, HEX(UDFUNC.HEX2RAW('1234567'))
FROM SYSIBM.SYSDUMMY1;
results in:
1 2 3 4
-- ---- ---- --------
1234 áÅ 01234567

Related

Why is SQL output parameter always null

I have the following SP
CREATE PROCEDURE [dbo].[GetBaseSixtyTwoString]
#a_number_to_convert int,
#v_temp_val nvarchar(256) output
AS
DECLARE #v_modulo INTEGER;
DECLARE #v_temp_int decimal(38) = #a_number_to_convert;
DECLARE #v_temp_char VARCHAR(1);
DECLARE #c_base62_digits VARCHAR(62) = '0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ';
IF ( #a_number_to_convert = 0 )
BEGIN
SET #v_temp_val = '5';
END
WHILE ( #v_temp_int <> 0 )
BEGIN
SET #v_modulo = #v_temp_int % 62;
SET #v_temp_char = substring( #c_base62_digits, #v_modulo + 1, 1 );
SET #v_temp_val = #v_temp_char + #v_temp_val;
SET #v_temp_int = floor(#v_temp_int / 62);
END
I am calling it like this:
declare #shorturl nvarchar(256)
exec dbo.GetBaseSixtyTwoString 1, #shorturl output
But the variable #shorturl always returns null
However if I put print statements in the SP I can see that #v_temp_val is indeed getting the correct value.
What am I missing?
You need to initialise #v_temp_val inside the stored procedure to non-NULL value, to ''.
If #v_temp_val is NULL, then this line would still result in NULL:
SET #v_temp_val = #v_temp_char + #v_temp_val;
because "value" + NULL = NULL
check if any value you put into variable #v_temp_val is null. note that any non-null value + NULL will result to NULL:
SET #v_temp_val = ISNULL(#v_temp_char, '') + ISNULL(#v_temp_val, '');

Uniqueidentifier as parameter in SQL Server Function

I have created a Function in SQL Server 2012 that I will use in a Check Constraint on a table.
The function works as expected if I do:
SELECT [dbo].[CheckValidCardnumberForShellTankingen] ('700678036658047691' ,'2925CA00-6DD5-4F9D-AB0E-AA15DBBD388B')
But when I try to set the expression in Check Constraint so:
([dbo].[CheckValidCardnumberForShellTankingen]([Volledig kaartnummer],[RollBackCode])=(1))
I get a Messaage: "Error validating constraint 'CK_MyConstraint'"
I use the Uniqueidentifier in a Where clause and the strange thing is if I replace the parameter with string containing the Uniqueidentifier I dont get this error.
Here is the Function:
-- =============================================
-- Author: Anders Pedersen
-- Create date: 2015-02-13
-- Description: Check of the Cardnumber of a transaction is valid.
-- =============================================
CREATE FUNCTION [dbo].[CheckValidCardnumberForShellTankingen]
(
-- Add the parameters for the function here
#Cardnumber NvarChar(50),
#RollBackCode NvarChar(200)
)
RETURNS BIT
AS
BEGIN
-- Declare the return variable here
DECLARE
#Result BIT
,#ResultLenght BIT
,#ResultPrefix BIT
,#CardLenght INT
,#SupplierID INT
,#UseCardnumber BIT
,#Prefix NvarChar(50)
-- Add the T-SQL statements to compute the return value here
SET #Result = 0
SET #ResultLenght = 0
SET #ResultPrefix = 0
SET #CardLenght = -1
SET #SupplierID = -1
SET #UseCardnumber = 0
SET #Prefix = ''
-- Get the UseCardnumber and the SupplierID
SELECT #UseCardnumber = C.UseCardNumber, #SupplierID = F.SupplierID
FROM Client C INNER JOIN
ClientFileUploads F ON C.ClientID = F.ClientID
WHERE F.RollBackCode = #RollBackCode
--WHERE F.RollBackCode = '2925CA00-6DD5-4F9D-AB0E-AA15DBBD388B'
-- Only carry out the check if the Client use Cards else set the check to True (1)
IF #UseCardnumber = 1
BEGIN
SELECT #CardLenght = [CardNumberLenght], #Prefix = ISNULL([Prefix],'') FROM [dbo].[Supplier] AS S WHERE S.SupplierID = #SupplierID
IF (#CardLenght IS NULL) OR (#CardLenght = 0)
BEGIN
SET #ResultLenght = 1
END
ELSE
BEGIN
IF (LEN(#Cardnumber) - #CardLenght)= 0
BEGIN
SET #ResultLenght = 1
END
ELSE
BEGIN
SET #ResultLenght = 0
END
END
IF SUBSTRING(#Cardnumber, 1, LEN(#Prefix)) = #Prefix
BEGIN
SET #ResultPrefix = 1
END
ELSE
BEGIN
SET #ResultPrefix = 0
END
IF ((#ResultLenght = 1) AND (#ResultPrefix = 1))
BEGIN
SET #Result = 1
END
ELSE
BEGIN
SET #Result = 0
END
END
ELSE
BEGIN
SET #Result = 1
END
-- Return the result of the function
RETURN #Result
END
GO
If #RollBackCode is a uniqueidentifier, I recommend making the parameter a uniqueidentifier and not a varchar.
As Rhys Jones points out, you shouldn't use a UDF in a check constraint.
See
https://dba.stackexchange.com/questions/22297/udf-in-check-constraint-downside
https://social.msdn.microsoft.com/Forums/sqlserver/en-US/078b720f-faac-425c-b51a-33bcecb263d2/check-constraint-with-udf-problem-with-lots-of-data?forum=transactsql
http://sqlblog.com/blogs/tibor_karaszi/archive/2009/12/17/be-careful-with-constraints-calling-udfs.aspx
If you need to check in a trigger and roll back -- SQL Server - After Insert/ For Insert - Rollback

How to extract an ID number from a URL string in SQL?

I am trying to extract an ID from a URL and running into some issues. The URL's will look something like this:
http://www.website.com/news/view.aspx?id=95
http://www.website.com/news/view.aspx?id=20&ReturnURL=%2fnews%2fview.aspx%3fid%3d20
I am trying to return back the number following "?id=" and nothing after the number. I will then convert it to an INT in reference to another table. Any suggestions as how to do this properly?
Use charindex to find the position of ?id and stuff to remove the characters that is before ?id. Then you use left to return the characters to the next &
declare #T table
(
URL varchar(100)
);
insert into #T values
('http://www.website.com/news/view.aspx?id=95'),
('http://www.website.com/news/view.aspx?id=20&ReturnURL=%2fnews%2fview.aspx%3fid%3d20');
select left(T2.URL, charindex('&', T2.URL) - 1) as ID
from #T as T
cross apply (select stuff(T.URL, 1, charindex('?id', T.URL) + 3, '')+'&') as T2(URL);
Here is an option that you can use when you want to find the value of any parameter value within a URL, it also supports parsing text values that contain a URL
DECLARE #Param varchar(50) = 'event'
DECLARE #Data varchar(8000) = 'User Logged into https://my.website.org/default.aspx?id=3066&event=49de&event=true from ip'
DECLARE #ParamIndex int = (select PatIndex('%'+#param+'=%', #Data)+LEN(#param)+1)
-- #ParamValueSubstring chops off everthing before the first instance of the parameter value
DECLARE #ParamValueSubstring varchar(8000) = SubString(#Data, #ParamIndex, 8000)
SELECT #ParamValueSubstring as ParamSubstring
DECLARE #SpaceIndex int = (SELECT CHARINDEX(' ', #ParamValueSubstring))-1
DECLARE #AmpIndex int = (SELECT CHARINDEX('&', #ParamValueSubstring))-1
DECLARE #valueLength int = -1
-- find first instance of ' ' or & after parameter value
IF #SpaceIndex = -1
SET #valueLength = #AmpIndex
ELSE IF #AmpIndex = -1
SET #valueLength = #SpaceIndex
ELSE IF #SpaceIndex < #AmpIndex
SET #valueLength = #SpaceIndex
ELSE
SET #valueLength = #AmpIndex
IF(#valueLength = -1) -- check to see if there was no space or '&' following the parameter value
BEGIN
SET #valueLength = 8000
END
select Left(#ParamValueSubstring, #valueLength) as ParamValue
-- approach similar to idea function found here http://blogs.lessthandot.com/index.php/DataMgmt/DataDesign/extracting-numbers-with-sql-server/
I'm not totally clear on what you're asking. Are you asking how to get the value of id from the url when you are in the asp.net application? Then in the code behind you can
In c#
string id = Request.QueryString["id"]; // returns null if id not found
Reference
From this SO question Try this for integers:
int id;
if (!int.TryParse(Request.QueryString["id"], out id))
{
// error case
}
You could do it in an SQL function, like this:
declare #URL varchar(100)
--set #URL = 'http://www.website.com/news/view.aspx?id=95'
set #URL = 'http://www.website.com/news/view.aspx?id=20&ReturnURL=%2fnews%2fview.aspx%3fid%3d20'
Set #URL = CASE charindex('&',#URL)
WHEN 0 then #URL else substring(#url,1,charindex('&',#URL)-1) end
select #URL,SUBSTRING(#URL,CHARINDEX('?id=',#URL)+4,99)
Both examples are in there, comment either one to see result

SQL Server 2005:charindex starting from the end

I have a string 'some.file.name',I want to grab 'some.file'.
To do that,I need to find the last occurrence of '.' in a string.
My solution is :
declare #someStr varchar(20)
declare #reversedStr varchar(20)
declare #index int
set #someStr = '001.002.003'
set #reversedStr = reverse(#someStr)
set #index = len(#someStr) - charindex('.',#reversedStr)
select left(#someStr,#index)
Well,isn't it too complicated?I was just intented to using 'some.file' in a where-clause.
Anyone has a good idea?
What do you need to do with it?? Do you need to grab the characters after the last occurence of a given delimiter?
If so: reverse the string and search using the normal CHARINDEX:
declare #test varchar(100)
set #test = 'some.file.name'
declare #reversed varchar(100)
set #reversed = REVERSE(#test)
select
REVERSE(SUBSTRING(#reversed, CHARINDEX('.', #reversed)+1, 100))
You'll get back "some.file" - the characters up to the last "." in the original file name.
There's no "LASTCHARINDEX" or anything like that in SQL Server directly. What you might consider doing in SQL Server 2005 and up is great a .NET extension library and deploy it as an assembly into SQL Server - T-SQL is not very strong with string manipulation, whereas .NET really is.
A very simple way is:
SELECT
RIGHT(#str, CHARINDEX('.', REVERSE(#str)) - 1)
This will also work:
DECLARE
#test VARCHAR(100)
SET #test = 'some.file.name'
SELECT
LEFT(#test, LEN(#test) - CHARINDEX('.', REVERSE(#test)))
Take one ')'
declare #test varchar(100)
set #test = 'some.file.name'
select left(#test,charindex('.',#test)+charindex('.',#test)-1)
CREATE FUNCTION [dbo].[Instr] (
-------------------------------------------------------------------------------------------------
-- Name: [dbo].[Instr]
-- Purpose: Find The Nth Value Within A String
-------------------------------------------------------------------------------------------------
-- Revisions:
-- 25-FEB-2011 - HESSR - Initial Revision
-------------------------------------------------------------------------------------------------
-- Parameters:
-- 1) #in_FindString - NVARCHAR(MAX) - INPUT - Input Find String
-- 2) #in_String - NVARCHAR(MAX) - INPUT - Input String
-- 3) #in_StartPos - SMALLINT - INPUT - Position In The String To Start Looking From
-- (If Start Position Is Negative, Search Begins At The End Of The String)
-- (Negative 1 Starts At End Position 1, Negative 3 Starts At End Position Minus 2)
-- 4) #in_Nth - SMALLINT - INPUT - Nth Occurrence To Find The Location For
-------------------------------------------------------------------------------------------------
-- Returns: SMALLINT - Position Of String Segment (Not Found = 0)
-------------------------------------------------------------------------------------------------
#in_FindString NVARCHAR(MAX),
#in_String NVARCHAR(MAX),
#in_StartPos SMALLINT = NULL,
#in_Nth SMALLINT = NULL
)
RETURNS SMALLINT
AS
BEGIN
DECLARE #loc_FindString NVARCHAR(MAX);
DECLARE #loc_String NVARCHAR(MAX);
DECLARE #loc_Position SMALLINT;
DECLARE #loc_StartPos SMALLINT;
DECLARE #loc_Nth SMALLINT;
DECLARE #loc_Idx SMALLINT;
DECLARE #loc_FindLength SMALLINT;
DECLARE #loc_Length SMALLINT;
SET #loc_FindString = #in_FindString;
SET #loc_String = #in_String;
SET #loc_Nth = ISNULL(ABS(#in_Nth), 1);
SET #loc_FindLength = LEN(#loc_FindString+N'.') - 1;
SET #loc_Length = LEN(#loc_String+N'.') - 1;
SET #loc_StartPos = ISNULL(#in_StartPos, 1);
SET #loc_Idx = 0;
IF (#loc_StartPos = ABS(#loc_StartPos))
BEGIN
WHILE (#loc_Idx < #loc_Nth)
BEGIN
SET #loc_Position = CHARINDEX(#loc_FindString,#loc_String,#loc_StartPos);
IF (#loc_Position > 0)
SET #loc_StartPos = #loc_Position + #loc_FindLength
ELSE
SET #loc_Idx = #loc_Nth;
SET #loc_Idx = #loc_Idx + 1;
END;
END
ELSE
BEGIN
SET #loc_StartPos = ABS(#loc_StartPos);
SET #loc_FindString = REVERSE(#in_FindString);
SET #loc_String = REVERSE(#in_String);
WHILE (#loc_Idx < #loc_Nth)
BEGIN
SET #loc_Position = CHARINDEX(#loc_FindString,#loc_String,#loc_StartPos);
IF (#loc_Position > 0)
SET #loc_StartPos = #loc_Position + #loc_FindLength
ELSE
SET #loc_Idx = #loc_Nth;
SET #loc_Idx = #loc_Idx + 1;
END;
IF (#loc_Position > 0)
SET #loc_Position = #loc_Length - #loc_Position + (1 - #loc_FindLength) + 1;
END;
RETURN (#loc_Position);
END;
GO
Here is a shorter version
DECLARE #someStr varchar(20)
set #someStr = '001.002.003'
SELECT REVERSE(Substring(REVERSE(#someStr),CHARINDEX('.', REVERSE(#someStr))+1,20))

Remove SQL comments

our stored procedures have developer comments and headers and as part of our deployment process we would like to remove these from the customer copy. Is there a method of achieving this within SQL Server 2005 or with another tool?
Don't know if it would suit, but you can use the WITH ENCRYPTION option to hide the entire contents. Do your end users need to see/modify any of the procedures?
I use an SQL tool called WinSQL (very handy, highly reccommended) that has an option to "Parse Comments Locally".
I don't use it much personally, but I have had it on accidentally when running my scripts that build my stored procs and it does clean them out of the proc source in the database. :-)
Even the free version has that option.
This option wasn't available when the question was asked, but in SQL 2012, we can now use SQL Server's own parser to help us out.
Removing Comments From SQL
A little late to the party but in case someone else stumbles across...
CREATE FUNCTION [usf_StripSQLComments] ( #CommentedSQLCode VARCHAR(max) )
RETURNS Varchar(max)
/****************************************************************************************
--######################################################################################
-- Mjwheele#yahoo.com -- Some count sheep. Some code. Some write code to count sheep.
--######################################################################################
--#############################################################################
-- Sample Call Script
--#############################################################################
Declare #SqlCode Varchar(Max)
Declare #objname varchar(max) = 'sp_myproc'
select #Sqlcode = OBJECT_DEFINITION(t.OBJECT_ID)
from sys.objects t
where t.name = #objname
select dbo.ssf_StripSQLComments( #Sqlcode )
****************************************************************************************/
AS
BEGIN
DECLARE #Sqlcode VARCHAR(MAX) =#CommentedSQLCode
Declare #i integer = 0
Declare #Char1 Char(1)
Declare #Char2 Char(1)
Declare #TrailingComment Char(1) = 'N'
Declare #UncommentedSQLCode varchar(Max)=''
Declare #Whackcounter Integer = 0
Declare #max Integer = DATALENGTH(#sqlcode)
While #i < #max
Begin
Select #Char1 = Substring(#Sqlcode,#i,1)
if #Char1 not in ('-', '/','''','*')
begin
if #Char1 = CHAR(13) or #Char1 = CHAR(10)
Select #TrailingComment = 'N'
Else if not (#Char1 = CHAR(32) or #Char1 = CHAR(9)) and #TrailingComment = 'N' -- Not Space or Tab
Select #TrailingComment = 'Y'
if #Whackcounter = 0
Select #UncommentedSQLCode += #Char1
select #i+=1
end
else
begin
Select #Char2 = #Char1
, #Char1 = Substring(#Sqlcode,#i+1,1)
If #Char1 = '-' and #Char2 = '-' and #Whackcounter = 0
Begin
While #i < #Max and Substring(#Sqlcode,#i,1) not in (char(13), char(10))
Select #i+=1
if Substring(#Sqlcode,#i,1) = char(13) and #TrailingComment = 'N'
Select #i+=1
if Substring(#Sqlcode,#i,1) = char(10) and #TrailingComment = 'N'
Select #i+=1
End
else If #Char1 = '*' and #Char2 = '/'
Begin
Select #Whackcounter += 1
, #i += 2
End
else If #Char1 = '/' and #Char2 = '*'
Begin
Select #Whackcounter -= 1
, #i += 2
End
else if #char2 = '''' and #Whackcounter = 0
begin
Select #UncommentedSQLCode += #char2
while Substring(#Sqlcode,#i,1) <> ''''
Begin
Select #UncommentedSQLCode += Substring(#Sqlcode,#i,1)
, #i +=1
end
Select #i +=1
, #Char1 = Substring(#Sqlcode,#i,1)
end
else
Begin
if #Whackcounter = 0
Select #UncommentedSQLCode += #Char2
Select #i+=1
end
end
End
Return #UncommentedSQLCode
END
You may want to check this out:
Remove Comments from SQL Server Stored Procedures.
Note: this doesn't handle comments that start with --, which SQL Server allows. Otherwise I would inquire into having a developer write a short filter app that reads the text in via a stream, and then remove the comments that way. Or write it yourself.
I ended up writing my own SQL comment remover in C#
I assume you save your procedure definitions to a text or .sql file that you then version control. You could always use something like notepadd++ to find/replace the strings you want then commit them as a production/customer tag. This is not elegant, but an option. I don't know of any third party tools and my google searches returned the same result as the other posters posted.
You can remove comments using regular expressions in C# like described here. It works for line comments, block comments, even when block comments are nested, and it can correctly identify and ignore comments delimiters when they are inside literals or bracketed named identifiers.
This a VB.NET code for removing SQL Coments
It's supposed the script is well formated syntaxicly under SQL Management Studio
Module Module1
Const TagBeginMultiComent = "/*"
Const TagEndMultiComent = "*/"
Const TagMonoComent = "--"
Public Fail As Integer
Function IsQuoteOpened(ByVal Value As String) As Boolean
Dim V As String = Replace(Value, "'", "")
If V Is Nothing Then Return 0
Return ((Value.Length - V.Length) / "'".Length) Mod 2 > 0
End Function
Function RemoveComents(ByVal Value As String) As String
Dim RetVal As String = ""
Dim Block As String
Dim Tampon As String
Dim NbComentIncluded As Integer = 0
Dim QuoteOpened As Boolean
Dim CommentOpen As Boolean
While Value.Length > 0
Tampon = ""
Block = ""
Dim P1 As Integer = InStr(Value, TagBeginMultiComent)
Dim P2 As Integer = InStr(Value, TagEndMultiComent)
Dim P3 As Integer = InStr(Value, TagMonoComent)
Dim Min As Integer
If P1 = 0 Then P1 = Value.Length + 1
If P2 = 0 Then P2 = Value.Length + 1
If P3 = 0 Then P3 = Value.Length + 1
Tampon = ""
If P1 + P2 + P3 > 0 Then
Min = Math.Min(P1, Math.Min(P2, P3))
Tampon = Left(Value, Min - 1)
Block = Mid(Value, Min, 2)
Value = Mid(Value, Min)
End If
If NbComentIncluded = 0 Then QuoteOpened = IsQuoteOpened(RetVal & Tampon)
If Not QuoteOpened Then
NbComentIncluded += -(Block = TagBeginMultiComent) + (Block = TagEndMultiComent)
If Block = TagMonoComent Then
Dim Ploc As Integer = InStr(Value, vbCrLf)
If Ploc = 0 Then
Value = ""
Else
Value = Mid(Value, Ploc - 2)
End If
End If
End If
If Not CommentOpen And NbComentIncluded = 0 Then
RetVal += Tampon
If ({TagBeginMultiComent, TagEndMultiComent, TagMonoComent}.Contains(Block) And QuoteOpened) Or
(Not {TagBeginMultiComent, TagEndMultiComent, TagMonoComent}.Contains(Block) And Not QuoteOpened) Then RetVal += Block
End If
CommentOpen = (NbComentIncluded > 0)
Value = Mid(Value, 3)
End While
Fail = -1 * (IsQuoteOpened(RetVal)) - 2 * (NbComentIncluded > 0)
If Fail <> 0 Then RetVal = ""
Return RetVal
End Function
Sub Main()
Dim InputFileName = "C:\Users\godef\OneDrive - sacd.fr\DEV\DelComentsSql\test.txt" '"C:\Users\sapgy01\OneDrive - sacd.fr\DEV\DelComentsSql\test.txt"
Dim Script As String = File.ReadAllText(InputFileName)
Dim InputDataArray As String() = Split(Script, vbCrLf)
Script = RemoveComents(Script)
If Fail Then
Console.WriteLine($"Fail : {Fail}")
If Fail And 1 = 1 Then Console.WriteLine("Toutes les quotes ne sont pas refermées")
If Fail And 2 = 2 Then Console.WriteLine("Tous les commentaires multiliqnes ne sont pas refermées")
Else
Console.WriteLine(Script)
End If
Console.ReadKey()
End Sub
End Module
Addon : a check is made for unclosed multilines coment and/or unclosed apostroph.
Example :
/* Commentaire principal
Suite du commentaire principal
/* Inclusion de commentaire
Suite du commentaire inclu
*/ suite commentaire principal
continuation commentaire principal
/* mono comentaire tagué multi lignes */
*/ select * from ref
-- mono commentaire
select ref.ref_lbl_code as 'code
de
la
-- ref --
' -- from ref as 'references' -- Fin de séquence
from ref as reference -- Mono commentaire fin de ligne
go -- lance l'exécution
select dbo.ref.REF_LBL_CODE as 'commentaire
/* Mulitlignes sur une ligne dans litteral */'
from ref as 'table_ref'
select ref.ref_lbl_code as 'commentaire
/* Mulitlignes
sur plusieurs lignes
dans litteral */'
from ref as '-- ref_table --'
-- Fin de l'exécution du ' -- script -- '