Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Ssc pull error when importing data with tables with reserved keywords #115

Closed
Jaxelr opened this issue Jul 8, 2020 · 2 comments
Closed

Comments

@Jaxelr
Copy link
Contributor

Jaxelr commented Jul 8, 2020

Describe the Issue

ssc pull prod with the data option enable errors with tables with reserved words. It works fine for pulling the table with the keyword.

Expected behavior

The command should import the data correctly.

Steps to Reproduce

Given the following sample sql (which includes the reserve word Plan):

CREATE TABLE [Plan]
(
    Id BIGINT IDENTITY(1, 1) NOT NULL,
    PlanId int
)

INSERT INTO dbo.[Plan](PlanId)
SELECT 1 UNION 
SELECT 2

running the command ssc pull throws an error message.

Other Information

I suspect the problem is on the following lines of the pull.ts file:

return Promise.all<sql.IResult<any>>(queries)
.then(results => {
const tables: sql.IRecordSet<SqlTable> = results[1].recordset;
const names = tables.map(item => `${item.schema}.${item.name}`);
const matched = multimatch(names, config.data);
if (!matched.length) {
return results;
}
return Promise.all<any>(
matched.map(item => {
const match = tables.find(table => item === `${table.schema}.${table.name}`);
return pool
.request()
.query(`SELECT * FROM ${item}`)
.then(result => ({
hasIdentity: match.identity_count > 0,
name: item,
result
}));
})
).then(data => [...results, ...data]);
})
.then(results => {
pool.close();
return results;
});
})
.then(results => this.writeFiles(config, results))
.catch(error => this.spinner.fail(error));
}

Specifically the lines

const names = tables.map(item => `${item.schema}.${item.name}`);

and

const match = tables.find(table => item === `${table.schema}.${table.name}`);

which should escape the schema and table with brackets ([])

@Jaxelr
Copy link
Contributor Author

Jaxelr commented Jul 8, 2020

After some evaluation i think its probably too much of a breaking change to add the change i previously suggested, i think its probably safer to internally manage the transformation prior to the lookup and then modify the interface SqlDataResult and Generator to to the parse correctly like the AbstractSqlObject interface

@Jaxelr
Copy link
Contributor Author

Jaxelr commented Jul 15, 2020

Closing since PR got merged, Thanks.

@Jaxelr Jaxelr closed this as completed Jul 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant