Class: FluentQuery::Drivers::MySQL

Inherits:
DBI
  • Object
show all
Defined in:
lib/fluent-query/drivers/mysql.rb

Overview

MySQL database driver.

Constant Summary collapse

@@__known_tokens =

Known tokens index. (internal cache)

Hash::new do |hash, key| 
    hash[key] = { }
end

Instance Method Summary collapse

Instance Method Details

#driver_nameObject



42
43
44
# File 'lib/fluent-query/drivers/mysql.rb', line 42

def driver_name
    "Mysql"
end

#known_token?(group, token_name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/fluent-query/drivers/mysql.rb', line 29

def known_token?(group, token_name)
    super(group, token_name, @@__known_tokens)
end

#native_connectionObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fluent-query/drivers/mysql.rb', line 67

def native_connection

    super()

    # Gets settings
    encoding = @_nconnection_settings[:encoding]
    
    if encoding.nil?
        encoding = "utf8"
    end

    # Sets encoding and default schema
    @_nconnection.do("SET NAMES " + self.quote_string(encoding) + ";")

    return @_nconnection
    
end

#open_connection(settings) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/fluent-query/drivers/mysql.rb', line 54

def open_connection(settings)
    if not settings[:database] or not settings[:username]
        raise FluentQuery::Drivers::Exception::new("Database name and username is required for connection.")
    end
    
    super(settings)
end

#quote_identifier(field) ⇒ Object



90
91
92
# File 'lib/fluent-query/drivers/mysql.rb', line 90

def quote_identifier(field)
    '`' + field.to_s.gsub(".", '`.`') + '`'
end