Class: ActiveRecord::ConnectionAdapters::OpenBaseAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::OpenBaseAdapter
- Defined in:
- lib/active_record/connection_adapters/openbase_adapter.rb
Overview
The OpenBase adapter works with the Ruby/Openbase driver by Tetsuya Suzuki. www.spice-of-life.net/ruby-openbase/ (needs version 0.7.3+)
Options:
-
:host
– Defaults to localhost -
:username
– Defaults to nothing -
:password
– Defaults to nothing -
:database
– The name of the database. No default, must be provided.
The OpenBase adapter will make use of OpenBase’s ability to generate unique ids for any column with an unique index applied. Thus, if the value of a primary key is not specified at the time an INSERT is performed, the adapter will prefetch a unique id for the primary key. This prefetching is also necessary in order to return the id after an insert.
Caveat: Operations involving LIMIT and OFFSET do not yet work!
Maintainer: [email protected]
Instance Method Summary collapse
- #adapter_name ⇒ Object
-
#add_limit_offset!(sql, options) ⇒ Object
DATABASE STATEMENTS ======================================.
-
#begin_db_transaction ⇒ Object
begin.
-
#columns(table_name, name = nil) ⇒ Object
:nodoc:.
-
#commit_db_transaction ⇒ Object
:nodoc:.
-
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:.
-
#execute(sql, name = nil) ⇒ Object
:nodoc:.
-
#indexes(table_name, name = nil) ⇒ Object
:nodoc:.
-
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
:nodoc:.
- #native_database_types ⇒ Object
- #next_sequence_value(sequence_name) ⇒ Object
- #prefetch_primary_key?(table_name = nil) ⇒ Boolean
-
#quote(value, column = nil) ⇒ Object
QUOTING ==================================================.
- #quoted_false ⇒ Object
- #quoted_true ⇒ Object
-
#rollback_db_transaction ⇒ Object
:nodoc:.
-
#select_all(sql, name = nil) ⇒ Object
:nodoc:.
-
#select_one(sql, name = nil) ⇒ Object
:nodoc:.
- #supports_migrations? ⇒ Boolean
-
#tables(name = nil) ⇒ Object
Return the list of all tables in the schema search path.
-
#update(sql, name = nil) ⇒ Object
(also: #delete)
:nodoc:.
Methods inherited from AbstractAdapter
#active?, #disconnect!, #initialize, #raw_connection, #reconnect!, #reset_runtime, #supports_count_distinct?, #verify!
Methods included from Quoting
#quote_column_name, #quote_string, #quoted_date
Methods included from DatabaseStatements
#add_limit!, #reset_sequence!, #select_value, #select_values, #transaction
Methods included from SchemaStatements
#add_column, #add_column_options!, #add_index, #change_column, #change_column_default, #create_table, #drop_table, #dump_schema_information, #initialize_schema_information, #remove_column, #remove_index, #rename_column, #rename_table, #structure_dump, #table_alias_for, #table_alias_length, #type_to_sql
Constructor Details
This class inherits a constructor from ActiveRecord::ConnectionAdapters::AbstractAdapter
Instance Method Details
#adapter_name ⇒ Object
60 61 62 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 60 def adapter_name 'OpenBase' end |
#add_limit_offset!(sql, options) ⇒ Object
DATABASE STATEMENTS ======================================
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 124 def add_limit_offset!(sql, ) #:nodoc if limit = [:limit] unless offset = [:offset] sql << " RETURN RESULTS #{limit}" else limit = limit + offset sql << " RETURN RESULTS #{offset} TO #{limit}" end end end |
#begin_db_transaction ⇒ Object
begin
161 162 163 164 165 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 161 def begin_db_transaction #:nodoc: execute "START TRANSACTION" rescue Exception # Transactions aren't supported end |
#columns(table_name, name = nil) ⇒ Object
:nodoc:
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 189 def columns(table_name, name = nil) #:nodoc: sql = "SELECT * FROM _sys_tables " sql << "WHERE tablename='#{table_name}' AND INDEXOF(fieldname,'_')<>0 " sql << "ORDER BY columnNumber" columns = [] select_all(sql, name).each do |row| columns << OpenBaseColumn.new(row["fieldname"], default_value(row["defaultvalue"]), sql_type_name(row["typename"],row["length"]), row["notnull"] ) # breakpoint() if row["fieldname"] == "content" end columns end |
#commit_db_transaction ⇒ Object
:nodoc:
167 168 169 170 171 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 167 def commit_db_transaction #:nodoc: execute "COMMIT" rescue Exception # Transactions aren't supported end |
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 88 def default_sequence_name(table_name, primary_key) # :nodoc: "#{table_name} #{primary_key}" end |
#execute(sql, name = nil) ⇒ Object
:nodoc:
151 152 153 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 151 def execute(sql, name = nil) #:nodoc: log(sql, name) { @connection.execute(sql) } end |
#indexes(table_name, name = nil) ⇒ Object
:nodoc:
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 205 def indexes(table_name, name = nil)#:nodoc: sql = "SELECT fieldname, notnull, searchindex, uniqueindex, clusteredindex FROM _sys_tables " sql << "WHERE tablename='#{table_name}' AND INDEXOF(fieldname,'_')<>0 " sql << "AND primarykey=0 " sql << "AND (searchindex=1 OR uniqueindex=1 OR clusteredindex=1) " sql << "ORDER BY columnNumber" indexes = [] execute(sql, name).each do |row| indexes << IndexDefinition.new(table_name,index_name(row),row[3]==1,[row[0]]) end indexes end |
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
:nodoc:
145 146 147 148 149 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 145 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) #:nodoc: execute(sql, name) update_nulls_after_insert(sql, name, pk, id_value, sequence_name) id_value end |
#native_database_types ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 64 def native_database_types { :primary_key => "integer UNIQUE INDEX DEFAULT _rowid", :string => { :name => "char", :limit => 4096 }, :text => { :name => "text" }, :integer => { :name => "integer" }, :float => { :name => "float" }, :datetime => { :name => "datetime" }, :timestamp => { :name => "timestamp" }, :time => { :name => "time" }, :date => { :name => "date" }, :binary => { :name => "object" }, :boolean => { :name => "boolean" } } end |
#next_sequence_value(sequence_name) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 92 def next_sequence_value(sequence_name) ary = sequence_name.split(' ') if (!ary[1]) then ary[0] =~ /(\w+)_nonstd_seq/ ary[0] = $1 end @connection.unique_row_id(ary[0], ary[1]) end |
#prefetch_primary_key?(table_name = nil) ⇒ Boolean
84 85 86 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 84 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
QUOTING ==================================================
104 105 106 107 108 109 110 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 104 def quote(value, column = nil) if value.kind_of?(String) && column && column.type == :binary "'#{@connection.insert_binary(value)}'" else super end end |
#quoted_false ⇒ Object
116 117 118 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 116 def quoted_false "0" end |
#quoted_true ⇒ Object
112 113 114 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 112 def quoted_true "1" end |
#rollback_db_transaction ⇒ Object
:nodoc:
173 174 175 176 177 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 173 def rollback_db_transaction #:nodoc: execute "ROLLBACK" rescue Exception # Transactions aren't supported end |
#select_all(sql, name = nil) ⇒ Object
:nodoc:
135 136 137 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 135 def select_all(sql, name = nil) #:nodoc: select(sql, name) end |
#select_one(sql, name = nil) ⇒ Object
:nodoc:
139 140 141 142 143 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 139 def select_one(sql, name = nil) #:nodoc: add_limit_offset!(sql,{:limit => 1}) results = select(sql, name) results.first if results end |
#supports_migrations? ⇒ Boolean
80 81 82 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 80 def supports_migrations? false end |
#tables(name = nil) ⇒ Object
Return the list of all tables in the schema search path.
183 184 185 186 187 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 183 def tables(name = nil) #:nodoc: tables = @connection.tables tables.reject! { |t| /\A_SYS_/ === t } tables end |
#update(sql, name = nil) ⇒ Object Also known as: delete
:nodoc:
155 156 157 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 155 def update(sql, name = nil) #:nodoc: execute(sql, name).rows_affected end |