Skip to content

Commit

Permalink
Merge pull request #306 from mk3008/293-request-parsing-mysql-system-…
Browse files Browse the repository at this point in the history
…variables

Supports parsing of MySQL system variables
  • Loading branch information
mk3008 authored Jan 24, 2024
2 parents 27ac292 + 6af5ddd commit e55c124
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Carbunql/Analysis/LexReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public string ReadLex(bool skipSpace = true)
return sb.ToString();
}

// ex. @@ (MySQL system variable)
if (fc == '@')
{
var isFirst = true;
foreach (var item in ReadChars(x => isFirst && x == '@'))
{
sb.Append(item);
isFirst = false;
}
}

// ex. . or , or (
if (SingleSymbols.Contains(fc)) return sb.ToString();

Expand All @@ -144,7 +155,7 @@ public string ReadLex(bool skipSpace = true)
// ex. 123.45
if (fc.IsInteger())
{
foreach (var item in ReadChars((x) => "0123456789.".ToArray().Contains(x)))
foreach (var item in ReadChars(x => "0123456789.".ToArray().Contains(x)))
{
sb.Append(item);
}
Expand Down
1 change: 1 addition & 0 deletions src/Carbunql/Analysis/Parser/ParameterValueParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public static class ParameterValueParser
{
public static bool IsParameterValue(string text)
{
if (text.StartsWith("@@")) return false;
return text.StartsWith(new string[] { ":", "@", "?" });
}

Expand Down
15 changes: 15 additions & 0 deletions test/Carbunql.Analysis.Test/ValueParseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,19 @@ public void PostgresArray()
var lst = v.GetTokens().ToList();
Assert.Equal(6, lst.Count);
}

[Fact]
public void MySqlSystemVariable()
{
var text = "@@session.time_zone";
var v = ValueParser.Parse(text);
Monitor.Log(v);

var lst = v.GetTokens().ToList();
Assert.Equal(3, lst.Count);

var expect = "@@session.time_zone";

Assert.Equal(expect, v.ToText());
}
}

0 comments on commit e55c124

Please sign in to comment.