Skip to content

Commit

Permalink
Escape query that read table schema to allow reserved words as catalo…
Browse files Browse the repository at this point in the history
…g name
  • Loading branch information
jimmystelzer committed Jan 23, 2021
1 parent 873359e commit 495365f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to the Selec Top N extension will be documented in this file

## [Unreleased]

## [0.0.5] - 2021-01-23

### Changed

- Escape query that read the schema to allow reserved words.

## [0.0.4] - 2021-01-03

### Changed
Expand Down Expand Up @@ -31,7 +37,8 @@ All notable changes to the Selec Top N extension will be documented in this file
- Create new menus under table and views objects int the objected browser to allow run the new commands.
- Add option to run generate the query without execute.

[Unreleased]: https://github.com/jimmystelzer/azuredatastudio-select-top-n/compare/0.0.4...HEAD
[Unreleased]: https://github.com/jimmystelzer/azuredatastudio-select-top-n/compare/0.0.5...HEAD
[0.0.5]: https://github.com/jimmystelzer/azuredatastudio-select-top-n/releases/tag/0.0.5
[0.0.4]: https://github.com/jimmystelzer/azuredatastudio-select-top-n/releases/tag/0.0.4
[0.0.3]: https://github.com/jimmystelzer/azuredatastudio-select-top-n/releases/tag/0.0.3
[0.0.2]: https://github.com/jimmystelzer/azuredatastudio-select-top-n/releases/tag/0.0.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is a list of current features of this extension.

## Installation

The current release is available to [download as a .vsix file](https://github.com/jimmystelzer/azuredatastudio-select-top-n/releases/download/0.0.1/azuredatastudio-select-top-n-0.0.1.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...`.
The current release is available to [download as a .vsix file](https://github.com/jimmystelzer/azuredatastudio-select-top-n/releases/download/0.0.5/azuredatastudio-select-top-n-0.0.5.vsix) and can be installed by opening the command palette (`ctrl/command+shift+p`) and selecting `Extensions: Install from VSIX...`.

## Change Log

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Azure data studio extension to select the first N rows from tables/views",
"icon": "artwork/icon.png",
"publisher": "jimmystelzer",
"version": "0.0.4",
"version": "0.0.5",
"engines": {
"vscode": "^1.39.0",
"azdata": "*"
Expand Down
9 changes: 8 additions & 1 deletion src/SelectTopN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@ export class SelectTopN {
static async generateSelectQuery(context: azdata.ObjectExplorerContext, topN:Number, autoRun:boolean) {
try{
if (!context ) {
console.log(context);
vscode.window.showInformationMessage("This cannot run from command menu.");
return;
}
let connection = await azdata.connection.getCurrentConnection();
let connectionId = (connection) ? connection.connectionId : undefined;

if(!connection || !connectionId || !context.connectionProfile || !context.nodeInfo || !context.nodeInfo.metadata){
console.log(connection, connectionId, context);
vscode.window.showInformationMessage("You need to be connected to run this.");
return;
}
let connectionUri = await azdata.connection.getUriForConnection(connectionId);
console.log(connectionUri);
let queryProvider = azdata.dataprotocol.getProvider<azdata.QueryProvider>(connection.providerId,azdata.DataProviderType.QueryProvider);
console.log(queryProvider);
let tableName: string = `[${context.connectionProfile.databaseName}].[${context.nodeInfo.metadata.schema}].[${context.nodeInfo.metadata.name}]`;
let query = `USE ${context.connectionProfile.databaseName}; SELECT [COLUMN_NAME] FROM INFORMATION_SCHEMA.COLUMNS WHERE [TABLE_NAME]='${context.nodeInfo.metadata.name}' AND [TABLE_SCHEMA]='${context.nodeInfo.metadata.schema}'` ;
console.log(tableName);
let query = `USE [${context.connectionProfile.databaseName}]; SELECT [COLUMN_NAME] FROM INFORMATION_SCHEMA.COLUMNS WHERE [TABLE_NAME]='${context.nodeInfo.metadata.name}' AND [TABLE_SCHEMA]='${context.nodeInfo.metadata.schema}'` ;
console.log(query);
let resultSchema = await queryProvider.runQueryAndReturn(connectionUri, query);
console.log(resultSchema);
if(resultSchema.rows.length > 0){
let finalQuery = `SELECT TOP (${topN})\n`;
resultSchema.rows.forEach(function(row){
Expand Down

1 comment on commit 495365f

@jimmystelzer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit may fix the #1 issue

Please sign in to comment.