class DB::MariaDB::Connection

This implements the interface between the underyling native interface interface and “standardised” connection interface.

Public Class Methods

new(**options) click to toggle source
Calls superclass method
# File lib/db/mariadb/connection.rb, line 32
def initialize(**options)
        @native = Native::Connection.connect(**options)
        
        super()
end

Public Instance Methods

append_identifier(value, buffer = String.new) click to toggle source
# File lib/db/mariadb/connection.rb, line 71
def append_identifier(value, buffer = String.new)
        case value
        when Array
                first = true
                value.each do |part|
                        buffer << '.' unless first
                        first = false
                        
                        buffer << escape_identifier(part)
                end
        else
                buffer << escape_identifier(value)
        end
        
        return buffer
end
append_literal(value, buffer = String.new) click to toggle source
# File lib/db/mariadb/connection.rb, line 50
def append_literal(value, buffer = String.new)
        case value
        when Time, DateTime
                append_string(value.utc.strftime('%Y-%m-%d %H:%M:%S'), buffer)
        when Date
                append_string(value.strftime('%Y-%m-%d'), buffer)
        when Numeric
                buffer << value.to_s
        when TrueClass
                buffer << 'TRUE'
        when FalseClass
                buffer << 'FALSE'
        when nil
                buffer << 'NULL'
        else
                append_string(value, buffer)
        end
        
        return buffer
end
append_string(value, buffer = String.new) click to toggle source
# File lib/db/mariadb/connection.rb, line 44
def append_string(value, buffer = String.new)
        buffer << "'" << @native.escape(value) << "'"
        
        return buffer
end
close() click to toggle source
Calls superclass method
# File lib/db/mariadb/connection.rb, line 38
def close
        @native.close
        
        super
end
key_column(name = 'id', primary: true, null: false) click to toggle source
# File lib/db/mariadb/connection.rb, line 88
def key_column(name = 'id', primary: true, null: false)
        buffer = String.new
        
        append_identifier(name, buffer)
        
        buffer << " BIGINT"
        
        if primary
                buffer << " AUTO_INCREMENT PRIMARY KEY"
        elsif !null
                buffer << " NOT NULL"
        end
        
        return buffer
end
next_result() click to toggle source
# File lib/db/mariadb/connection.rb, line 114
def next_result
        @native.next_result
end
send_query(statement) click to toggle source
# File lib/db/mariadb/connection.rb, line 108
def send_query(statement)
        @native.discard_results
        
        @native.send_query(statement)
end
status() click to toggle source
# File lib/db/mariadb/connection.rb, line 104
def status
        @native.status
end

Protected Instance Methods

escape_identifier(value) click to toggle source
# File lib/db/mariadb/connection.rb, line 120
def escape_identifier(value)
        "`#{@native.escape(value)}`"
end