diff --git a/lib/discovery.js b/lib/discovery.js index a9cf6c2c..70144dbb 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -298,6 +298,15 @@ function mixinDiscovery(MySQL, mysql) { return sql; }; + /** + * Build query to determine is strict mode + */ + + MySQL.prototype.buildQueryIsStrict = function() { + return 'SELECT @@GLOBAL.sql_mode LIKE \'%STRICT%\' AS globalStrictMode,' + + '@@SESSION.sql_mode LIKE \'%STRICT%\' AS sessionStrictMode;'; + }; + /** * Discover foreign keys that reference to the primary key of this table * @param {String} table The table name diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index 4fd1f290..9424cb18 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -257,6 +257,22 @@ describe('Discover LDL schema from a table', function() { }); }); +describe('Discover schema with strict mode on', function() { + let schema; + before(function(done) { + db.discoverSchema('INVENTORY', {owner: 'STRONGLOOP'}, function(err, schema_) { + schema = schema_; + done(err); + }); + }); + it('should return an LDL schema for INVENTORY with strict mode on', function() { + assert.strictEqual(schema.name, 'Inventory'); + if(schema.properties.length) { + assert.strictEqual(schema.properties.jsonSchema.maxLength, schema.properties.length); + } + }); +}); + describe('Discover and handle enum', function() { let schema; before(function(done) { diff --git a/test/schema.sql b/test/schema.sql index 589b3d1b..0f2fcaa9 100644 --- a/test/schema.sql +++ b/test/schema.sql @@ -24,7 +24,7 @@ CREATE DATABASE /*!32312 IF NOT EXISTS*/ `STRONGLOOP` /*!40100 DEFAULT CHARACTER SET utf8 */; USE `STRONGLOOP`; - +SET GLOBAL sql_mode = 'STRICT_ALL_TABLES'; -- -- Table structure for table `CUSTOMER` --