Module: DataMapper::Migrations::OracleAdapter::SQL
- Included in:
- DataMapper::Migrations::OracleAdapter
- Defined in:
- lib/dm-migrations/adapters/dm-oracle-adapter.rb
Overview
:nodoc:
Instance Method Summary collapse
- #create_sequence_statements(model) ⇒ Object private
- #delete_table_statement(model) ⇒ Object private
- #drop_sequence_statement(model) ⇒ Object private
- #reset_sequence_statement(model) ⇒ Object private
- #schema_name ⇒ Object private
- #truncate_table_statement(model) ⇒ Object private
Instance Method Details
#create_sequence_statements(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 169 def create_sequence_statements(model) name = self.name table_name = model.storage_name(name) serial = model.serial(name) statements = [] if sequence_name = model_sequence_name(model) sequence_name = quote_name(sequence_name) column_name = quote_name(serial.field) statements << DataMapper::Ext::String.compress_lines(<<-SQL) CREATE SEQUENCE #{sequence_name} NOCACHE SQL # create trigger only if custom sequence name was not specified unless serial.[:sequence] statements << DataMapper::Ext::String.compress_lines(<<-SQL) CREATE OR REPLACE TRIGGER #{quote_name(default_trigger_name(table_name))} BEFORE INSERT ON #{quote_name(table_name)} FOR EACH ROW BEGIN IF inserting THEN IF :new.#{column_name} IS NULL THEN SELECT #{sequence_name}.NEXTVAL INTO :new.#{column_name} FROM dual; END IF; END IF; END; SQL end end statements end |
#delete_table_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
237 238 239 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 237 def delete_table_statement(model) "DELETE FROM #{quote_name(model.storage_name(name))}" end |
#drop_sequence_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
203 204 205 206 207 208 209 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 203 def drop_sequence_statement(model) if sequence_name = model_sequence_name(model) "DROP SEQUENCE #{quote_name(sequence_name)}" else nil end end |
#reset_sequence_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 212 def reset_sequence_statement(model) if sequence_name = model_sequence_name(model) sequence_name = quote_name(sequence_name) DataMapper::Ext::String.compress_lines(<<-SQL) DECLARE cval INTEGER; BEGIN SELECT #{sequence_name}.NEXTVAL INTO cval FROM dual; EXECUTE IMMEDIATE 'ALTER SEQUENCE #{sequence_name} INCREMENT BY -' || cval || ' MINVALUE 0'; SELECT #{sequence_name}.NEXTVAL INTO cval FROM dual; EXECUTE IMMEDIATE 'ALTER SEQUENCE #{sequence_name} INCREMENT BY 1'; END; SQL else nil end end |
#schema_name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
164 165 166 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 164 def schema_name @schema_name ||= select("SELECT SYS_CONTEXT('userenv','current_schema') FROM dual").first.freeze end |
#truncate_table_statement(model) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
232 233 234 |
# File 'lib/dm-migrations/adapters/dm-oracle-adapter.rb', line 232 def truncate_table_statement(model) "TRUNCATE TABLE #{quote_name(model.storage_name(name))}" end |