Skip to content

Commit

Permalink
bugs fix:
Browse files Browse the repository at this point in the history
1. script translate: not use details mode to fetch definition
2. query editor: handle content within single quotation chars
  • Loading branch information
victor committed Dec 10, 2022
1 parent e9d0eeb commit e4aab39
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<PackageProjectUrl>https://github.com/victor-wiki/DatabaseManager</PackageProjectUrl>
<Description>Database manage tool for: SqlServer, MySql, Oracle and Postgres.</Description>
<Authors>victor-wiki</Authors>
<Version>2.0.22</Version>
<PackageReleaseNotes>detect sql query type: handle quoted keyword</PackageReleaseNotes>
<Version>2.0.23</Version>
<PackageReleaseNotes>bug fix: script translate not use details mode to fetch definition</PackageReleaseNotes>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>2.0.22</AssemblyVersion>
<FileVersion>2.0.22</FileVersion>
<AssemblyVersion>2.0.23</AssemblyVersion>
<FileVersion>2.0.23</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class TranslateManager

public async Task<TranslateResult> Translate(DatabaseType sourceDbType, DatabaseType targetDbType, DatabaseObject dbObject, ConnectionInfo connectionInfo, bool removeCarriagRreturnChar = false)
{
DbInterpreterOption sourceScriptOption = new DbInterpreterOption() { ScriptOutputMode = GenerateScriptOutputMode.None };
DbInterpreterOption sourceScriptOption = new DbInterpreterOption() { ScriptOutputMode = GenerateScriptOutputMode.None, ObjectFetchMode = DatabaseObjectFetchMode.Details };
DbInterpreterOption targetScriptOption = new DbInterpreterOption() { ScriptOutputMode = GenerateScriptOutputMode.WriteToString };

DbConveterInfo script = new DbConveterInfo() { DbInterpreter = DbInterpreterHelper.GetDbInterpreter(sourceDbType, connectionInfo, sourceScriptOption) };
DbConveterInfo target = new DbConveterInfo() { DbInterpreter = DbInterpreterHelper.GetDbInterpreter(targetDbType, new ConnectionInfo(), sourceScriptOption) };
DbConveterInfo source = new DbConveterInfo() { DbInterpreter = DbInterpreterHelper.GetDbInterpreter(sourceDbType, connectionInfo, sourceScriptOption) };
DbConveterInfo target = new DbConveterInfo() { DbInterpreter = DbInterpreterHelper.GetDbInterpreter(targetDbType, new ConnectionInfo(), targetScriptOption) };

using (DbConverter dbConverter = new DbConverter(script, target))
using (DbConverter dbConverter = new DbConverter(source, target))
{
var option = dbConverter.Option;

Expand Down
47 changes: 38 additions & 9 deletions DatabaseManager/DatabaseManager.CoreApp/Controls/UC_QueryEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void tsmiCopy_Click(object sender, EventArgs e)

private void CopyText()
{
Clipboard.SetDataObject(this.txtEditor.SelectedText);
Clipboard.SetDataObject(this.txtEditor.SelectedText);
}

private void tsmiPaste_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -120,7 +120,7 @@ private void txtEditor_KeyDown(object sender, KeyEventArgs e)
{
this.ShowFindBox();
}
else if(e.Control && e.KeyCode == Keys.C)
else if (e.Control && e.KeyCode == Keys.C)
{
this.CopyText();
}
Expand Down Expand Up @@ -278,6 +278,11 @@ private void HandleKeyUpForIntellisense(KeyEventArgs e)
{
if (this.enableIntellisense)
{
if (token.Type == SqlWordTokenType.String)
{
return;
}

SqlWord word = this.FindWord(token.Text);

if (word.Type == SqlWordTokenType.Table)
Expand Down Expand Up @@ -319,11 +324,28 @@ private void HandleKeyUpForIntellisense(KeyEventArgs e)
{
if (this.enableIntellisense)
{
this.ShowWordListByToken(token);
if (!this.IsWordInQuotationChar(token))
{
this.ShowWordListByToken(token);
}
}
}
}

private bool IsWordInQuotationChar(SqlWordToken token)
{
int startIndex = token.StopIndex;

if (startIndex == 0)
{
return false;
}

int singleQotationCharCount = this.txtEditor.Text.Substring(0, startIndex).Count(item => item == '\'');

return singleQotationCharCount % 2 != 0;
}

private void HighlightingWord(SqlWordToken token)
{
int start = this.txtEditor.SelectionStart;
Expand Down Expand Up @@ -554,7 +576,7 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal

int i = -1;

bool exited = false;
bool existed = false;
for (i = index; i >= 0; i--)
{
char c = this.txtEditor.Text[i];
Expand All @@ -580,7 +602,7 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal
}
else
{
exited = true;
existed = true;
break;
}
}
Expand All @@ -596,7 +618,7 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal

token.Text = word;

token.StartIndex = i + (exited ? 1 : 0);
token.StartIndex = i + (existed ? 1 : 0);

if (token.StartIndex == token.StopIndex && isInsert && word.Length > 0)
{
Expand All @@ -612,9 +634,11 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal
if (isQuotationPaired && word.StartsWith("'"))
{
List<char> afterChars = new List<char>();

for (int j = currentIndex; j < this.txtEditor.Text.Length; j++)
{
char c = this.txtEditor.Text[j];

if (Regex.IsMatch(c.ToString(), delimeterPattern))
{
break;
Expand Down Expand Up @@ -644,7 +668,11 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal

if (token.Type == SqlWordTokenType.String)
{
this.SetWordColor(token);
if (!isDot)
{
this.SetWordColor(token);
}

return token;
}
}
Expand Down Expand Up @@ -680,6 +708,7 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal
else if (isComment)
{
token.Type = SqlWordTokenType.Comment;

this.SetWordColor(token, true);
}
else if (long.TryParse(word, out _))
Expand All @@ -688,7 +717,7 @@ private SqlWordToken GetLastWordToken(bool noAction = false, bool isInsert = fal
}
else
{
if (!isDot)
if (!isDot && !this.IsWordInQuotationChar(token))
{
this.ClearStyle(token);
}
Expand Down Expand Up @@ -1070,4 +1099,4 @@ private void tsmiFindText_Click(object sender, EventArgs e)
this.ShowFindBox();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<Authors>victor-wiki</Authors>
<Description>Database manage tool for: SqlServer, MySql, Oracle and Postgres.</Description>
<PackageProjectUrl>https://github.com/victor-wiki/DatabaseManager</PackageProjectUrl>
<Version>2.0.24</Version>
<Version>2.0.25</Version>
<ApplicationIcon>Resources\_dbManager.ico</ApplicationIcon>
<PackageReleaseNotes>table desinger: auto update value when focus leave cell for data type column</PackageReleaseNotes>
<PackageReleaseNotes>bug fix:
handle query editor content that within single quotation chars</PackageReleaseNotes>
<Platforms>AnyCPU;x64</Platforms>
<AssemblyVersion>2.0.24</AssemblyVersion>
<FileVersion>2.0.24</FileVersion>
<AssemblyVersion>2.0.25</AssemblyVersion>
<FileVersion>2.0.25</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit e4aab39

Please sign in to comment.