mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-14 01:25:37 -05:00
use reliable way to detect createtable statements (#19897)
* use reliable way to detect createtable statements * PR comments * comments
This commit is contained in:
@@ -10,6 +10,7 @@ import * as utils from '../common/utils';
|
||||
import * as xmlFormat from 'xml-formatter';
|
||||
import * as os from 'os';
|
||||
import * as UUID from 'vscode-languageclient/lib/utils/uuid';
|
||||
import * as mssql from 'mssql';
|
||||
|
||||
import { Uri, window } from 'vscode';
|
||||
import { EntryType, IDatabaseReferenceProjectEntry, IProjectEntry, ISqlProject, ItemType, SqlTargetPlatform } from 'sqldbproj';
|
||||
@@ -247,14 +248,19 @@ export class Project implements ISqlProject {
|
||||
const fileEntries: FileProjectEntry[] = [];
|
||||
for (let f of Array.from(filesSet.values())) {
|
||||
const typeEntry = entriesWithType.find(e => e.relativePath === f);
|
||||
let containsCreateTableStatement;
|
||||
let containsCreateTableStatement = false;
|
||||
|
||||
// read file to check if it has a "Create Table" statement
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(f));
|
||||
|
||||
if (await utils.exists(fullPath)) {
|
||||
const fileContents = await fs.readFile(fullPath);
|
||||
containsCreateTableStatement = fileContents.toString().toLowerCase().includes('create table');
|
||||
if (utils.getAzdataApi()) {
|
||||
const dacFxService = await utils.getDacFxService() as mssql.IDacFxService;
|
||||
try {
|
||||
const result = await dacFxService.parseTSqlScript(fullPath, this.getProjectTargetVersion());
|
||||
containsCreateTableStatement = result.containsCreateTableStatement;
|
||||
} catch (e) {
|
||||
console.error(utils.getErrorMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
fileEntries.push(this.createFileProjectEntry(f, EntryType.File, typeEntry ? typeEntry.typeAttribute : undefined, containsCreateTableStatement));
|
||||
|
||||
@@ -140,6 +140,7 @@ export class MockDacFxService implements mssql.IDacFxService {
|
||||
public generateDeployPlan(_: string, __: string, ___: string, ____: azdata.TaskExecutionMode): Thenable<mssql.GenerateDeployPlanResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public getOptionsFromProfile(_: string): Thenable<mssql.DacFxOptionsResult> { return Promise.resolve(mockDacFxOptionsResult); }
|
||||
public validateStreamingJob(_: string, __: string): Thenable<mssql.ValidateStreamingJobResult> { return Promise.resolve(mockDacFxResult); }
|
||||
public parseTSqlScript(_: string, __: string): Thenable<mssql.ParseTSqlScriptResult> { return Promise.resolve({ containsCreateTableStatement: true }); }
|
||||
}
|
||||
|
||||
export function createContext(): TestContext {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
import * as constants from '../common/constants';
|
||||
import * as templates from '../templates/templates';
|
||||
|
||||
import { promises as fs } from 'fs';
|
||||
import should = require('should');
|
||||
@@ -34,6 +35,10 @@ export async function createTestSqlProjFile(contents: string, folderPath?: strin
|
||||
}
|
||||
|
||||
export async function createTestProject(contents: string, folderPath?: string): Promise<Project> {
|
||||
const macroDict: Record<string, string> = {
|
||||
'PROJECT_DSP': constants.defaultDSP
|
||||
};
|
||||
contents = templates.macroExpansion(contents, macroDict);
|
||||
return await Project.openProject(await createTestSqlProjFile(contents, folderPath));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user