List:Internals« Previous MessageNext Message »
From:jan.lindstrom Date:December 13 2004 9:57am
Subject:bk commit into 5.0 tree (jan:1.1728)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of jan. When jan does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet
  1.1728 04/12/13 10:57:26 jan@stripped +1 -0
  Fixed a bug no error message for ALTER with InnoDB and AUTO_INCREMENT (Bug #7061).
  

  sql/ha_innodb.cc
    1.130 04/12/13 10:56:53 jan@stripped +42 -1
    Fixed a bug no error message for ALTER with InnoDB and AUTO_INCREMENT (Bug #7061).
    If AUTO_INCREMENT is given in the ALTER TABLE, this value is now set
    to the auto increment value of the table if the new value is creater or 
    equal than the current value of the auto increment value. If the new value
    is less than the old value no error message is given and the old value 
    is not changed.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	jan
# Host:	hundin.mysql.fi
# Root:	/home/jan/new/mysql-5.0

--- 1.129/sql/ha_innodb.cc	Tue Dec  7 15:46:55 2004
+++ 1.130/sql/ha_innodb.cc	Mon Dec 13 10:56:53 2004
@@ -1326,7 +1326,13 @@
 			&innodb_dummy_stmt_trx_handle: the latter means
 			that the current SQL statement ended */
 {
-	trx_t*	trx;
+	trx_t*		trx;
+	dict_table_t*	table;
+	ib_longlong	auto_inc_value;
+        ib_longlong	aic_new;
+	char 		table_name[1000];
+	ulint		db_name_len;
+	ulint		table_name_len;
 
   	DBUG_ENTER("innobase_commit");
   	DBUG_PRINT("trans", ("ending transaction"));
@@ -1359,6 +1365,41 @@
 	        fprintf(stderr,
 "InnoDB: Error: thd->transaction.all.innodb_active_trans == 0\n"
 "InnoDB: but trx->conc_state != TRX_NOT_STARTED\n");
+	}
+
+	if (thd->lex->sql_command == SQLCOM_ALTER_TABLE &&
+	   (thd->lex->create_info.used_fields & HA_CREATE_USED_AUTO) &&
+	   (thd->lex->create_info.auto_increment_value != 0)) {
+
+		/* Query was ALTER TABLE...AUTO_INC = x; Find out a table
+		definition from the dictionary and get the current value
+		of the auto increment field. Set a new value to the
+		auto increment field if the new value is creater than 
+		the current value. */
+
+		aic_new = thd->lex->create_info.auto_increment_value;
+		db_name_len = strlen(thd->lex->query_tables->db);
+		table_name_len = strlen(thd->lex->query_tables->real_name);
+
+		ut_ad((db_name_len + 1 + table_name_len) < 999);
+		strcpy(table_name, thd->lex->query_tables->db);
+		strcat(table_name, "/");
+		strcat(table_name, thd->lex->query_tables->real_name);
+
+		table = dict_table_get(table_name, trx);
+
+		if (table) {
+			auto_inc_value = dict_table_autoinc_peek(table);
+
+			if( auto_inc_value < aic_new) {
+
+				/* We have to decrease the new auto increment
+				value by one because this function will increase
+				the value given by one. */
+
+				dict_table_autoinc_update(table, aic_new - 1);
+			}
+		}
 	}
 
 	if (trx_handle != (void*)&innodb_dummy_stmt_trx_handle
Thread
bk commit into 5.0 tree (jan:1.1728)jan.lindstrom13 Dec