$this->columns = array();
}
+ /**
+ * Reset a sequence to the id field of a table.
+ * @param string $table name of table
+ * @return success
+ */
+ public abstract function reset_sequence($table);
+
/**
* Returns sql generator used for db manipulation.
* Used mostly in upgrade.php scripts.
/**
* Returns the SQL for returning searching one string for the location of another.
- * Note, there is no guarantee which order $needle, $haystack will be in
+ * Note, there is no guarantee which order $needle, $haystack will be in
* the resulting SQL, so when using this method, and both arguments contain
* placeholders, you should use named placeholders.
* @param string $needle the SQL expression that will be searched for.
return ($returnid ? $id : true);
}
+
+ /**
+ * Reset a sequence to the id field of a table.
+ * @param string $table name of table
+ * @return bool success
+ */
+ public function reset_sequence($table) {
+ // From http://msdn.microsoft.com/en-us/library/ms176057.aspx
+ if (!$this->get_manager()->table_exists($table)) {
+ return false;
+ }
+ $value = (int)$this->get_field_sql('SELECT MAX(id) FROM {'.$table.'}');
+ if ($value == 0) {
+ $value = 1;
+ }
+ return $this->change_database_structure("DBCC CHECKIDENT ('$this->prefix$table', RESEED, $value)");
+ }
}
public function sql_regex($positivematch=true) {
return $positivematch ? 'REGEXP' : 'NOT REGEXP';
}
-}
+
+ /**
+ * Reset a sequence to the id field of a table.
+ * @param string $table name of table
+ * @return bool success
+ */
+ public function reset_sequence($table) {
+ // From http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
+ if (!$this->get_manager()->table_exists($table)) {
+ return false;
+ }
+ $value = (int)$this->get_field_sql('SELECT MAX(id) FROM {'.$table.'}');
+ $value++;
+ return $this->change_database_structure("ALTER TABLE $this->prefix$table AUTO_INCREMENT = $value");
+ }
+}
\ No newline at end of file
/// Fail safe to original value
return $value;
}
+
+ /**
+ * Reset a sequence to the id field of a table.
+ * @param string $table name of table
+ * @return bool success
+ */
+ public function reset_sequence($table) {
+ // From http://www.acs.ilstu.edu/docs/oracle/server.101/b10759/statements_2011.htm
+ $dbman = $this->get_manager();
+ if (!$dbman->table_exists($table)) {
+ return false;
+ }
+ $value = (int)$this->get_field_sql('SELECT MAX(id) FROM {'.$table.'}');
+ $value++;
+ $xmldb_table = new xmldb_table($table);
+ $this->reads++;
+ $seqname = $dbman->find_sequence_name($xmldb_table);
+ if (!$seqname) {
+ /// Fallback, seqname not found, something is wrong. Inform and use the alternative getNameForObject() method
+ $generator = $dbman->generator;
+ $generator->setPrefix($this->getPrefix());
+ $seqname = $generator->getNameForObject($table, 'id', 'seq');
+ }
+
+ $this->change_database_structure("DROP SEQUENCE $seqname");
+ return $this->change_database_structure("CREATE SEQUENCE $seqname START WITH $value INCREMENT BY 1 NOMAXVALUE");
+ }
}
public function sql_regex($positivematch=true) {
return $positivematch ? '~*' : '!~*';
}
-}
+
+ /**
+ * Reset a sequence to the id field of a table.
+ * @param string $table name of table
+ * @return bool success
+ */
+ public function reset_sequence($table) {
+ // From http://www.postgresql.org/docs/7.4/static/sql-altersequence.html
+ if (!$this->get_manager()->table_exists($table)) {
+ return false;
+ }
+ $value = (int)$this->get_field_sql('SELECT MAX(id) FROM {'.$table.'}');
+ $value++;
+ return $this->change_database_structure("ALTER SEQUENCE $this->prefix{$table}_id_seq RESTART WITH $value");
+ }
+}
\ No newline at end of file
}
return implode('||', $elements);
}
+
+ /**
+ * Reset a sequence to the id field of a table.
+ * @param string $table name of table
+ * @return bool success
+ */
+ public function reset_sequence($table) {
+ // From http://sqlite.org/autoinc.html
+ if (!$this->get_manager()->table_exists($table)) {
+ return false;
+ }
+ $value = (int)$this->get_field_sql('SELECT MAX(id) FROM {'.$table.'}');
+ return $this->change_database_structure("UPDATE sqlite_sequence SET seq=$value WHERE name='$this->prefix$table'");
+ }
}
\ No newline at end of file