SQL generators must not execute changes in DB. Just provide the needed SQL

in order to make database_manager to execute it. reset_sequence reimplemented.
This commit is contained in:
stronk7
2009-08-31 14:23:40 +00:00
parent 576ace3245
commit b1ca138716
8 changed files with 57 additions and 48 deletions

View File

@@ -84,19 +84,21 @@ class mysql_sql_generator extends sql_generator {
/**
* Reset a sequence to the id field of a table.
* @param string $table name of table
* @return bool success
* @param string $table name of table or xmldb_table object
* @return array sql commands to execute
*/
public function reset_sequence($table) {
if (is_string($table)) {
$tablename = $table;
} else {
public function getResetSequenceSQL($table) {
if ($table instanceof xmldb_table) {
$tablename = $table->getName();
} else {
$tablename = $table;
}
// From http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
$value = (int)$this->mdb->get_field_sql('SELECT MAX(id) FROM {'.$tablename.'}');
$value++;
return $this->mdb->change_database_structure("ALTER TABLE $this->prefix$tablename AUTO_INCREMENT = $value");
return array("ALTER TABLE $this->prefix$tablename AUTO_INCREMENT = $value");
}