Class: Og::SqlserverStore

Inherits:
SqlStore show all
Extended by:
SqlserverUtils
Includes:
SqlserverUtils
Defined in:
lib/og/store/alpha/sqlserver.rb

Overview

A Store that persists objects into a Sqlserver database. To read documentation about the methods, consult the documentation for SqlStore and Store.

Instance Attribute Summary

Attributes inherited from SqlStore

#conn

Attributes inherited from Store

#options, #transaction_nesting

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SqlserverUtils

escape, quote

Methods included from SqlUtils

#blob, #build_join_name, #create_join_table_sql, #date, #escape, #join_class_ordering, #join_object_ordering, #join_table, #join_table_index, #join_table_info, #join_table_key, #join_table_keys, #ordered_join_table_keys, #parse_blob, #parse_boolean, #parse_date, #parse_float, #parse_int, #parse_timestamp, #quote, #quote_array, #table, #tableize, #timestamp

Methods inherited from SqlStore

#aggregate, #commit, #count, #delete_all, #enable_logging, #find, #find_one, #join, #load, #managed_tables, #reload, #rollback, #select, #select_one, #sql_update, #start, #type_cast, #unjoin, #unmanaged_tables, #update, #update_by_sql, #update_properties

Methods inherited from Store

#commit, #count, #delete, #find, for_name, #force_save!, #insert, #load, #reload, #rollback, #save, #start, #transaction, #update, #update_properties

Constructor Details

#initialize(options) ⇒ SqlserverStore

Returns a new instance of SqlserverStore.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/og/store/alpha/sqlserver.rb', line 85

def initialize(options)
  super

  begin
    @conn = DBI.connect("DBI:ADO:Provider=SQLOLEDB;Data Source=#{options[:address]};Initial Catalog=#{options[:name]};User Id=#{options[:user]};Password=#{options[:password]};")
  rescue => ex
    # gmosx, FIXME: drak, fix this!
    if ex.to_s =~ /database .* does not exist/i
      Logger.info "Database '#{options[:name]}' not found!"
      self.class.create(options)
      retry
    end
    raise
  end
end

Class Method Details

.create(options) ⇒ Object



77
78
79
# File 'lib/og/store/alpha/sqlserver.rb', line 77

def self.create(options)
  raise 'Not implemented'
end

.destroy(options) ⇒ Object



81
82
83
# File 'lib/og/store/alpha/sqlserver.rb', line 81

def self.destroy(options)
  raise 'Not implemented'
end

Instance Method Details

#closeObject



101
102
103
104
# File 'lib/og/store/alpha/sqlserver.rb', line 101

def close
  @conn.disconnect
  super
end

#enchant(klass, manager) ⇒ Object



106
107
108
109
# File 'lib/og/store/alpha/sqlserver.rb', line 106

def enchant(klass, manager)
  klass.property :oid, Fixnum, :sql => 'integer AUTO_INCREMENT PRIMARY KEY'
  super
end

#exec(sql) ⇒ Object



118
119
120
121
122
123
# File 'lib/og/store/alpha/sqlserver.rb', line 118

def exec(sql)
#    Logger.debug sql if $DBG
  @conn.execute(sql).finish 
rescue => ex
  handle_sql_exception(ex, sql)
end

#query(sql) ⇒ Object



111
112
113
114
115
116
# File 'lib/og/store/alpha/sqlserver.rb', line 111

def query(sql)
#    Logger.debug sql if $DBG
  return @conn.select_all(sql)
rescue => ex
  handle_sql_exception(ex, sql)
end