From d986a875589bb26ce9fb4b958c589d2ba0f08ab8 Mon Sep 17 00:00:00 2001 From: Matthew Monaco Date: Wed, 10 Sep 2014 17:55:45 -0600 Subject: [PATCH] mysql_database: prevent syntax error with collate=>'binary' On MySQL v5.5.38, creating a database such as: CREATE DATABASE `mydb` CHARACTER SET binary COLLATE binary; seems to hit a parser bug. A workaround is simply to quote COLLATE `binary`. As the quoting is harmless, and for aesthetics, quote both the CHARACTER SET and COLLATE arguments. --- lib/puppet/provider/mysql_database/mysql.rb | 2 +- spec/unit/puppet/provider/mysql_database/mysql_spec.rb | 2 +- tests/mysql_database.pp | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb index 213e0de7a..4587c1882 100644 --- a/lib/puppet/provider/mysql_database/mysql.rb +++ b/lib/puppet/provider/mysql_database/mysql.rb @@ -31,7 +31,7 @@ def self.prefetch(resources) end def create - mysql([defaults_file, '-NBe', "create database if not exists `#{@resource[:name]}` character set #{@resource[:charset]} collate #{@resource[:collate]}"].compact) + mysql([defaults_file, '-NBe', "create database if not exists `#{@resource[:name]}` character set `#{@resource[:charset]}` collate `#{@resource[:collate]}`"].compact) @property_hash[:ensure] = :present @property_hash[:charset] = @resource[:charset] diff --git a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb index d97f2535f..465e59dd5 100644 --- a/spec/unit/puppet/provider/mysql_database/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -56,7 +56,7 @@ describe 'create' do it 'makes a database' do - provider.expects(:mysql).with([defaults_file, '-NBe', "create database if not exists `#{resource[:name]}` character set #{resource[:charset]} collate #{resource[:collate]}"]) + provider.expects(:mysql).with([defaults_file, '-NBe', "create database if not exists `#{resource[:name]}` character set `#{resource[:charset]}` collate `#{resource[:collate]}`"]) provider.expects(:exists?).returns(true) expect(provider.create).to be_truthy end diff --git a/tests/mysql_database.pp b/tests/mysql_database.pp index 8747f707d..1ba24dfd9 100644 --- a/tests/mysql_database.pp +++ b/tests/mysql_database.pp @@ -10,3 +10,8 @@ ensure => present, charset => 'latin1', } +database{ 'test5': + ensure => present, + charset => 'binary', + collate => 'binary', +}