mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-19 09:35:36 -05:00
move checking if a file contains a create table statement to utils (#20512)
This commit is contained in:
@@ -689,3 +689,25 @@ export function throwIfNotConnected(connectionResult: azdataType.ConnectionResul
|
||||
throw new Error(`${connectionResult.errorMessage} (${connectionResult.errorCode})`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not the provided file contains a create table statement
|
||||
* @param fullPath full path to file to check
|
||||
* @param projectTargetVersion target version of sql project containing this file
|
||||
* @returns true if file includes a create table statement, false if it doesn't
|
||||
*/
|
||||
export async function fileContainsCreateTableStatement(fullPath: string, projectTargetVersion: string): Promise<boolean> {
|
||||
let containsCreateTableStatement = false;
|
||||
|
||||
if (getAzdataApi() && await exists(fullPath)) {
|
||||
const dacFxService = await getDacFxService() as mssql.IDacFxService;
|
||||
try {
|
||||
const result = await dacFxService.parseTSqlScript(fullPath, projectTargetVersion);
|
||||
containsCreateTableStatement = result.containsCreateTableStatement;
|
||||
} catch (e) {
|
||||
console.error(getErrorMessage(e));
|
||||
}
|
||||
}
|
||||
|
||||
return containsCreateTableStatement;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ 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';
|
||||
@@ -328,20 +327,10 @@ 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 = false;
|
||||
|
||||
// read file to check if it has a "Create Table" statement
|
||||
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(f));
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
const containsCreateTableStatement = await utils.fileContainsCreateTableStatement(fullPath, this.getProjectTargetVersion());
|
||||
|
||||
fileEntries.push(this.createFileProjectEntry(f, EntryType.File, typeEntry ? typeEntry.typeAttribute : undefined, containsCreateTableStatement));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user