不要怂,就是干,撸起袖子干!

Commit c9ace4d8 by Jason Jung Committed by Matt Broadstone

fixed identity column with Insert

1 parent 79b80a8e
var common;
common.quoteTable: function(param, as) {
var table = '';
if (as === true) {
as = param.as || param.name || param;
}
if (_.isObject(param)) {
if (common._dialect.supports.schemas) {
if (param.schema) {
table += common.quoteIdentifier(param.schema) + '.';
}
table += common.quoteIdentifier(param.tableName);
} else {
if (param.schema) {
table += param.schema + param.delimiter;
}
table += param.tableName;
table = common.quoteIdentifier(table);
}
} else {
table = common.quoteIdentifier(param);
}
if (as) {
table += ' AS ' + common.quoteIdentifier(as);
}
return table;
};
/*
Escape an identifier (e.g. a table or attribute name)
*/
/* istanbul ignore next */
common.quoteIdentifier: function(identifier, force) {
throwMethodUndefined('quoteIdentifier');
},
/*
Split an identifier into .-separated tokens and quote each part
*/
common.quoteIdentifiers: function(identifiers, force) {
if (identifiers.indexOf('.') !== -1) {
identifiers = identifiers.split('.');
return common.quoteIdentifier(identifiers.slice(0, identifiers.length - 1).join('.')) + '.' + common.quoteIdentifier(identifiers[identifiers.length - 1]);
} else {
return common.quoteIdentifier(identifiers);
}
},
module.exports = function (queryGenerator) {
common = queryGenerator;
};
......@@ -123,13 +123,6 @@ function addTableExistsWrapper(query, exists){
"END"
].join(" ");
}
function identityInsertOnWrapper(query){
return [
'SET IDENTITY_INSERT <%= tableName %> ON;',
query,
'SET IDENTITY_INSERT <%= tableName %> OFF;'
].join(' ');
}
//select stuff
function loadFields(attributes){
......@@ -139,7 +132,7 @@ function loadFields(attributes){
}
return attrStr;
}
function loadFields(attributes, tableName){
function loadFieldsWithName(attributes, tableName){
var attrStr = [];
for (var attr in attributes) {
if(tableName){
......@@ -236,6 +229,7 @@ module.exports = {
for (var key in valueHash) {
if(modelAttributeMap[key].autoIncrement){
insertKey = true;
delete valueHash[key];
}
}
......@@ -245,11 +239,12 @@ module.exports = {
selFields: fieldsToSql(valueHash, true),
values: valuesToSql(valueHash, modelAttributeMap)
};
query = (replacements.attributes.length ? valueQuery : emptyQuery) + ';';
if(insertKey){
query = identityInsertOnWrapper(query);
}
// if(insertKey){
// query = identityInsertOnWrapper(query);
// }
return Utils._.template(query)(replacements);
},
......@@ -465,7 +460,7 @@ module.exports = {
//add join table
if(options.include){
query.push(loadFields(model.rawAttributes, model.name));
query.push(loadFieldsWithName(model.rawAttributes, model.name));
for(var i = 0; i < options.include.length; i++){
if(options.include[i].as) {
query.push(joinFields(options.include[i].model.rawAttributes
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!