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!, #requires_reloading?, #reset_runtime, #supports_count_distinct?, #verify!
Methods included from Quoting
#quote_column_name, #quote_string, #quoted_date
Methods included from SchemaStatements
#add_column, #add_column_options!, #add_index, #add_order_by_for_association_limiting!, #change_column, #change_column_default, #create_table, #distinct, #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 ======================================
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 125 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
162 163 164 165 166 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 162 def begin_db_transaction #:nodoc: execute "START TRANSACTION" rescue Exception # Transactions aren't supported end |
#columns(table_name, name = nil) ⇒ Object
:nodoc:
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 190 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:
168 169 170 171 172 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 168 def commit_db_transaction #:nodoc: execute "COMMIT" rescue Exception # Transactions aren't supported end |
#default_sequence_name(table_name, primary_key) ⇒ Object
:nodoc:
89 90 91 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 89 def default_sequence_name(table_name, primary_key) # :nodoc: "#{table_name} #{primary_key}" end |
#execute(sql, name = nil) ⇒ Object
:nodoc:
152 153 154 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 152 def execute(sql, name = nil) #:nodoc: log(sql, name) { @connection.execute(sql) } end |
#indexes(table_name, name = nil) ⇒ Object
:nodoc:
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 206 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:
146 147 148 149 150 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 146 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 79 |
# 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" }, :decimal => { :name => "decimal" }, :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
93 94 95 96 97 98 99 100 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 93 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
85 86 87 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 85 def prefetch_primary_key?(table_name = nil) true end |
#quote(value, column = nil) ⇒ Object
QUOTING ==================================================
105 106 107 108 109 110 111 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 105 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
117 118 119 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 117 def quoted_false "0" end |
#quoted_true ⇒ Object
113 114 115 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 113 def quoted_true "1" end |
#rollback_db_transaction ⇒ Object
:nodoc:
174 175 176 177 178 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 174 def rollback_db_transaction #:nodoc: execute "ROLLBACK" rescue Exception # Transactions aren't supported end |
#select_all(sql, name = nil) ⇒ Object
:nodoc:
136 137 138 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 136 def select_all(sql, name = nil) #:nodoc: select(sql, name) end |
#select_one(sql, name = nil) ⇒ Object
:nodoc:
140 141 142 143 144 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 140 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
81 82 83 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 81 def supports_migrations? false end |
#tables(name = nil) ⇒ Object
Return the list of all tables in the schema search path.
184 185 186 187 188 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 184 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:
156 157 158 |
# File 'lib/active_record/connection_adapters/openbase_adapter.rb', line 156 def update(sql, name = nil) #:nodoc: execute(sql, name).rows_affected end |