Creates a sequence with name “name”. Drops it before if it exists
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/mysql.rb, line 10
10: def create_sequence(name)
11: drop_sequence(name)
12: self.execute("CREATE TABLE %s_sequence (id INTEGER PRIMARY KEY auto_increment)" % name)
13: end
Drops a sequence with name “name” if exists
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/mysql.rb, line 16
16: def drop_sequence(name)
17: self.execute("DROP TABLE IF EXISTS %s_sequence" % name)
18: end
Returns an array containing a list of the existing sequences that start with the given string
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/mysql.rb, line 21
21: def list_sequences(starts_with)
22: self.select_rows("SHOW TABLES LIKE '#{starts_with}%_sequence'").map { |result| result.first.gsub('_sequence', '') }
23: end
Returns the next value for the sequence “name“
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/mysql.rb, line 26
26: def next_val_sequence(name)
27: if self.class.equal? ActiveRecord::ConnectionAdapters::MysqlAdapter
28: self.insert_sql("INSERT INTO %s_sequence VALUES(NULL)" % name)
29: else
30: # the default insert_sql is nonsense, but jdbc_mysql doesn't override it
31: self.execute("INSERT INTO %s_sequence VALUES(NULL)" % name)
32: end
33: end
Reset a sequence so that it will return the specified value as the next one If next_value is not specified, the sequence will be reset to the “most appropiate value”, considering the values of existing records using this sequence
# File vendor/plugins/ubiquo_core/lib/ubiquo/adapters/mysql.rb, line 38
38: def reset_sequence_value(name, next_value = nil)
39: create_sequence(name)
40: unless next_value
41: table, field = name.split('_$_')
42: next_value = self.select_rows('SELECT MAX(%s) as max FROM %s' % [field, table]).first.first.to_i + 1
43: end
44: self.execute("ALTER TABLE %s_sequence AUTO_INCREMENT = %s" % [name, next_value || 1])
45: end
Disabled; run with $DEBUG to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.