Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlanywhere_adapter.rb

Constant Summary collapse

DEFAULT_CONFIG =
{ :username => 'dba', :password => 'sql' }

Class Method Summary collapse

Class Method Details

.sqlanywhere_connection(config) ⇒ Object

Main connection function to SQL Anywhere Connection Adapter takes four parameters:

  • :database (required, no default). Corresponds to “DatabaseName=” in connection string

  • :server (optional, defaults to :databse). Corresponds to “ServerName=” in connection string

  • :username (optional, default to ‘dba’)

  • :password (optional, deafult to ‘sql’)

  • :encoding (optional, defaults to charset of OS)

  • :commlinks (optional). Corresponds to “CommLinks=” in connection string

  • :connection_name (optional). Corresponds to “ConnectionName=” in connection string



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/active_record/connection_adapters/sqlanywhere_adapter.rb', line 55

def self.sqlanywhere_connection(config)
  
  if config[:connection_string]
    connection_string = config[:connection_string]
  else
    config = DEFAULT_CONFIG.merge(config)

    raise ArgumentError, "No database name was given. Please add a :database option." unless config.has_key?(:database)

    connection_string = "ServerName=#{(config[:server] || config[:database])};DatabaseName=#{config[:database]};UserID=#{config[:username]};Password=#{config[:password]};"
    connection_string += "CommLinks=#{config[:commlinks]};" unless config[:commlinks].nil?
    connection_string += "ConnectionName=#{config[:connection_name]};" unless config[:connection_name].nil?
    connection_string += "CharSet=#{config[:encoding]};" unless config[:encoding].nil?      
    connection_string += "Idle=0" # Prevent the server from disconnecting us if we're idle for >240mins (by default)
  end

  db = SA.instance.api.sqlany_new_connection()
  
  ConnectionAdapters::SQLAnywhereAdapter.new(db, logger, connection_string)
end