Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NamedParametersParser.cs #1179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
Expand Down Expand Up @@ -37,6 +37,9 @@ public static (string sql, IReadOnlyList<string> parameters) Parse(string sql)
var inSingleQuotes = false;
var inDoubleQuotes = false;
var inParam = false;
var inSingleLineComment = false;
var inMultiLineComment = false;

for (var i = 0; i < sql.Length; i++)
{
var sym = sql[i];
Expand All @@ -58,21 +61,47 @@ public static (string sql, IReadOnlyList<string> parameters) Parse(string sql)
}
else
{
if (sym == '\'' && !inDoubleQuotes)
var needsAdvance = false;
if ((sym == '\'') && (!(inDoubleQuotes || inSingleLineComment || inMultiLineComment)))
{
inSingleQuotes = !inSingleQuotes;
}
else if (sym == '\"' && !inSingleQuotes)
else if ((sym == '\"') && (!(inSingleQuotes || inSingleLineComment || inMultiLineComment)))
{
inDoubleQuotes = !inDoubleQuotes;
}
else if (!(inSingleQuotes || inDoubleQuotes) && sym == '@')
else if ((sym == '-') && (i < sql.Length - 1) && (sql[i + 1] == '-') && (!(inSingleQuotes || inDoubleQuotes || inSingleLineComment || inMultiLineComment)))
{
inSingleLineComment = true;
needsAdvance = true;
}
else if ((sym == '\n') && inSingleLineComment)
{
inSingleLineComment = false;
}
else if ((sym == '/') && (i < sql.Length - 1) && (sql[i + 1] == '*') && (!(inSingleQuotes || inDoubleQuotes || inSingleLineComment || inMultiLineComment)))
{
inMultiLineComment = true;
needsAdvance = true;
}
else if ((sym == '*') && (i < sql.Length - 1) && (sql[i + 1] == '/') && (inMultiLineComment))
{
inMultiLineComment = false;
needsAdvance = true;
}
else if ((!(inSingleQuotes || inDoubleQuotes || inSingleLineComment || inMultiLineComment)) && (sym == '@'))
{
inParam = true;
paramBuilder.Append(sym);
continue;
}

if (needsAdvance)
{
sqlBuilder.Append(sym);
sym = sql[++i];
}

sqlBuilder.Append(sym);
}
}
Expand Down