lib/gratan/driver.rb in gratan-0.2.3 vs lib/gratan/driver.rb in gratan-0.2.4

- old
+ new

@@ -1,8 +1,10 @@ class Gratan::Driver include Gratan::Logger::Helper + ER_NO_SUCH_TABLE = 1146 + def initialize(client, options = {}) @client = client @options = options end @@ -82,10 +84,18 @@ sql << " IDENTIFIED BY #{quote_identifier(identified)}" if identified sql << " REQUIRE #{required}" if required sql << " WITH #{with_option}" if with_option - update(sql) + begin + update(sql) + rescue Mysql2::Error => e + if @options[:ignore_not_exist] and e.error_number == ER_NO_SUCH_TABLE + log(:warn, e.message, :color => :yellow) + else + raise e + end + end end def identify(user, host, identifier) sql = 'GRANT USAGE ON *.* TO %s IDENTIFIED BY %s' % [ quote_user(user, host),