Merge pull request #199 from hunner/ansi_quotes
Fix SQL when ANSI_QUOTES is enabled in mysql config.
This commit is contained in:
commit
16affe5af8
2 changed files with 16 additions and 16 deletions
|
@ -96,7 +96,7 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
|
|||
if name[:type] == :db
|
||||
fields << :db
|
||||
end
|
||||
not mysql([defaults_file, "mysql", '-NBe', 'SELECT "1" FROM %s WHERE %s' % [ name[:type], fields.map do |f| "%s=\"%s\"" % [f, name[f]] end.join(' AND ')]].compact).empty?
|
||||
not mysql([defaults_file, "mysql", '-NBe', "SELECT '1' FROM %s WHERE %s" % [ name[:type], fields.map do |f| "%s='%s'" % [f, name[f]] end.join(' AND ')]].compact).empty?
|
||||
end
|
||||
|
||||
def all_privs_set?
|
||||
|
@ -118,9 +118,9 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
|
|||
|
||||
case name[:type]
|
||||
when :user
|
||||
privs = mysql([defaults_file, "mysql", "-Be", 'select * from mysql.user where user="%s" and host="%s"' % [ name[:user], name[:host] ]].compact)
|
||||
privs = mysql([defaults_file, "mysql", "-Be", "select * from mysql.user where user='%s' and host='%s'" % [ name[:user], name[:host] ]].compact)
|
||||
when :db
|
||||
privs = mysql([defaults_file, "mysql", "-Be", 'select * from mysql.db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]].compact)
|
||||
privs = mysql([defaults_file, "mysql", "-Be", "select * from mysql.db where user='%s' and host='%s' and db='%s'" % [ name[:user], name[:host], name[:db] ]].compact)
|
||||
end
|
||||
|
||||
if privs.match(/^$/)
|
||||
|
@ -149,11 +149,11 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
|
|||
case name[:type]
|
||||
when :user
|
||||
stmt = 'update user set '
|
||||
where = ' where user="%s" and host="%s"' % [ name[:user], name[:host] ]
|
||||
where = " where user='%s' and host='%s'" % [ name[:user], name[:host] ]
|
||||
all_privs = user_privs
|
||||
when :db
|
||||
stmt = 'update db set '
|
||||
where = ' where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
|
||||
where = " where user='%s' and host='%s' and db='%s'" % [ name[:user], name[:host], name[:db] ]
|
||||
all_privs = db_privs
|
||||
end
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ EOT
|
|||
end
|
||||
|
||||
it 'should query set priviliges' do
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"']).returns <<-EOT
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT
|
||||
Host User Password Select_priv Insert_priv Update_priv
|
||||
host user Y N Y
|
||||
EOT
|
||||
|
@ -49,7 +49,7 @@ EOT
|
|||
end
|
||||
|
||||
it 'should recognize when all priviliges are set' do
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"']).returns <<-EOT
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT
|
||||
Host User Password Select_priv Insert_priv Update_priv
|
||||
host user Y Y Y
|
||||
EOT
|
||||
|
@ -57,7 +57,7 @@ EOT
|
|||
end
|
||||
|
||||
it 'should recognize when all privileges are not set' do
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"']).returns <<-EOT
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT
|
||||
Host User Password Select_priv Insert_priv Update_priv
|
||||
host user Y N Y
|
||||
EOT
|
||||
|
@ -65,30 +65,30 @@ EOT
|
|||
end
|
||||
|
||||
it 'should be able to set all privileges' do
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"']).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user=\"user\" and host=\"host\""])
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(["--defaults-file=#{root_home}/.my.cnf", "flush-privileges"])
|
||||
@provider.privileges=(['all'])
|
||||
end
|
||||
|
||||
it 'should be able to set partial privileges' do
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"']).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user=\"user\" and host=\"host\""])
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(["--defaults-file=#{root_home}/.my.cnf", "flush-privileges"])
|
||||
@provider.privileges=(['Select_priv', 'Update_priv'])
|
||||
end
|
||||
|
||||
it 'should be case insensitive' do
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"']).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user=\"user\" and host=\"host\""])
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(["--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(["--defaults-file=#{root_home}/.my.cnf", 'flush-privileges'])
|
||||
@provider.privileges=(['SELECT_PRIV', 'insert_priv', 'UpDaTe_pRiV'])
|
||||
end
|
||||
|
||||
it 'should not pass --defaults-file if $root_home/.my.cnf is absent' do
|
||||
File.stubs(:file?).with("#{root_home}/.my.cnf").returns(false)
|
||||
provider_class.expects(:mysql).with(['mysql', '-NBe', 'SELECT "1" FROM user WHERE user="user" AND host="host"']).returns "1\n"
|
||||
provider_class.expects(:mysql).with(['mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user=\"user\" and host=\"host\""])
|
||||
provider_class.expects(:mysql).with(['mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n"
|
||||
provider_class.expects(:mysql).with(['mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user='user' and host='host'"])
|
||||
provider_class.expects(:mysqladmin).with(["flush-privileges"])
|
||||
@provider.privileges=(['Select_priv', 'Update_priv'])
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue