resend previous PR with test fixes (#19912)

* Revert "Revert "use reliable way to detect createtable statements (#19897)" (#19906)"

This reverts commit c211fb981c.

* fix tests

* fix test cases
This commit is contained in:
Alan Ren
2022-07-02 11:25:09 -07:00
committed by GitHub
parent 60026a39f9
commit 416e607f32
11 changed files with 80 additions and 19 deletions

View File

@@ -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() && await utils.exists(fullPath)) {
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));