Vscode-sqltools: A complete SQL statement will be truncated at a location that may be a keyword

Created on 11 May 2019  路  8Comments  路  Source: mtxr/vscode-sqltools

Bug information
If your SQL statement exists as part of the SQL keyword, SQLTools will truncate here.

How to make this bug shows up

  1. Create a table in SQL Server Express 2017, which the table name is called [Market].[dbo].[Goods]. The table has 5 columns. They are [Name], [Series], [TradeMark], [MadeIn] and [Price].
  2. Connect to database [Market] with SQLTools.
  3. Show table records of [Market].[dbo].[Goods] using keyboard shortcuts Ctrl+E Ctrl+S.
  4. Bug has appeared! In SQLTools Results window, there are label Showing 1 [Market].[dbo].[Goods] records - which is expected - and ods] - which is unexpected.
  5. The first label shows results exactly what I want, but the second label returns nothing and its query statement is also a mess.

Expected behavior
I hope that SQLTools can ignore keywords GO in word Goods and do not truncate it.

Screenshots
Database Details
Reproduce Guide 1
image
image
image

Desktop (please complete the following information):

  • SQLTools Version: 0.18.2
  • VSCode Version: 1.33.1 (system setup)
  • Dialect Used: MSSQL, with SQL Server Express 2017
  • OS: Windows 10 Home China 1809 17763.475

Additional context
I am a Simplified Chinese user and this is my first time to report an issue on GitHub. Due to the use of the Simplified Chinese system, the menu buttons and prompts in the screenshot are all in Chinese, please forgive me.

bug

Most helpful comment

Hey guys, I'll take a look at this today and release it in the next release as well.

The parser is a third-party based code, so I'll need to dig a bit deeper to fix and write tests to avoid this from happening in the future.

All 8 comments

I've noticed this too; I believe this is the GO keyword being identified in the middle of such queries/names and interpreted as a split in the queries.

The Following advice was suggested by my classmate. Is it easy to realize?

Use full word matching to solve this problem.

If the GO or other keyword is surrounded by only whitespace characters \s, newline characters (\r, \n), or on a separate line, then these words are recognized as keywords; otherwise, they are associated with adjacent characters (strings) and treated as a whole, not identified as a keyword.

I haven't looked through the codebase, so only @mtxr can say better, but i assume it's a case of just correcting a regex in a similar manner to what your classmate suggested, yeah.

Places that could be relevant after searching the codebase:

https://github.com/mtxr/vscode-sqltools/blob/master/packages/core/dialect/mssql/index.ts#L78 - Seems to be OK if i check the regex on its own - Only detects and replaces GO keywords wrapped by space or tabs, and only in the beginning and ending of lines.

https://github.com/mtxr/vscode-sqltools/blob/master/packages/core/utils/query/parse.ts#L123-L129 - Can't quite follow the algorithm here without delving into the other parser parts yet.

https://github.com/mtxr/vscode-sqltools/blob/master/packages/extension/language/sql.tmLanguage.json#L31 - This defines the keyword list, Maybe VSCode itself is doing something odd with it?

I should really install a VSCode extension dev env at some point just to check these things. If you don't get to this "soon", @mtxr , let me know - I'll try to take a shot at it, Seems like a relatively "simple" bug to start with?

Hey guys, I'll take a look at this today and release it in the next release as well.

The parser is a third-party based code, so I'll need to dig a bit deeper to fix and write tests to avoid this from happening in the future.

I received an e-mail from GitHub that you fixed this bug and closed the issue. I can't wait reciving the new release and update to it! Thanks @mtxr 馃帀馃帀馃帀

Hi @Drogon1573!

How is it going with the extension? Is it working as expected now? Hope so!

Just came to remember, if you like the project, please consider a donation or reviewing it on VSCode marketplace. That you help it to keep evolving.

Thanks!

@mtxr

I have received your comment. Thank you very much for your ability to fix the bug in time. Now it can work correctly.

image

image

I want to donate to your project. But I have no credit cards to donate in another currency. Sorry for that. 馃槶

@Drogon1573 nice!

No problem, just please, take a few minutes to review it at https://marketplace.visualstudio.com/items?itemName=mtxr.sqltools

That will help more people find the extension as well. More people using, more feedbacks, more improvements, more donations :smiley:

Thanks!

Was this page helpful?
0 / 5 - 0 ratings