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

Commit f86987aa by Jason Ku

Fix empty default value schema describing in sqlite.

* When getting schema for table column that omits any kind of 'DEFAULT
  ...', return populate the returned object with undefined instead of
  null so that a 'DEFAULT NULL' is not appended to subsequent CREATE
  queries.
* Fixes #5051
1 parent bb472072
......@@ -174,11 +174,22 @@ Query.prototype.run = function(sql, parameters) {
// this is the sqlite way of getting the metadata of a table
result = {};
var defaultValue;
results.forEach(function(_result) {
if (_result.dflt_value === null) {
// Column schema omits any "DEFAULT ..."
defaultValue = undefined;
} else if (_result.dflt_value === 'NULL') {
// Column schema is a "DEFAULT NULL"
defaultValue = null;
} else {
defaultValue = _result.dflt_value;
}
result[_result.name] = {
type: _result.type,
allowNull: (_result.notnull === 0),
defaultValue: (_result.dflt_value === 'NULL' ? null : _result.dflt_value),
defaultValue: defaultValue,
primaryKey : (_result.pk === 1)
};
......@@ -186,10 +197,6 @@ Query.prototype.run = function(sql, parameters) {
result[_result.name].defaultValue = { '0': false, '1': true }[result[_result.name].defaultValue];
}
if (result[_result.name].defaultValue === undefined) {
result[_result.name].defaultValue = null;
}
if (typeof result[_result.name].defaultValue === 'string') {
result[_result.name].defaultValue = result[_result.name].defaultValue.replace(/'/g, '');
}
......
......@@ -50,6 +50,10 @@ if (dialect === 'sqlite') {
expectation: {id: 'INTEGER DEFAULT 0'}
},
{
arguments: [{id: {type: 'INTEGER', defaultValue: undefined}}],
expectation: {id: 'INTEGER'}
},
{
arguments: [{id: {type: 'INTEGER', unique: true}}],
expectation: {id: 'INTEGER UNIQUE'}
},
......
......@@ -182,7 +182,14 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}
expect(username.type).to.equal(assertVal);
expect(username.allowNull).to.be.true;
expect(username.defaultValue).to.be.null;
switch (dialect) {
case 'sqlite':
expect(username.defaultValue).to.be.undefined;
break;
default:
expect(username.defaultValue).to.be.null;
}
switch (dialect) {
case 'sqlite':
......@@ -201,7 +208,13 @@ describe(Support.getTestDialectTeaser('QueryInterface'), function() {
}
expect(isAdmin.type).to.equal(assertVal);
expect(isAdmin.allowNull).to.be.true;
expect(isAdmin.defaultValue).to.be.null;
switch (dialect) {
case 'sqlite':
expect(isAdmin.defaultValue).to.be.undefined;
break;
default:
expect(isAdmin.defaultValue).to.be.null;
}
if (dialect === 'postgres' || dialect === 'postgres-native') {
expect(enumVals.special).to.be.instanceof(Array);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!