>>>>> "Thomas" == Thomas Lund <tld@stripped> writes:
Thomas> Michael Widenius wrote:
>>
>> >>>>> "Thomas" == Thomas Lund <tld@stripped> writes:
>>
Thomas> Hi
>>
Thomas> Sorry - haven't followed this thread, but I have just filed a bug report
Thomas> on this problem. I guess you are using 3.23.4. If you show fields from
Thomas> tablename, then your auto_increment/primary key field has NULL as
Thomas> default - even though you state not null in create table.
>>
Thomas> I got the same error in my application
Thomas> ERROR 1062: Duplicate entry '1' for key 1
>>
Thomas> when I tried to insert into the table and expecting mysql to
Thomas> auto_increment it automatically.
<cut>
Thomas> Here it goes wrong! It looks like the index() is f*cking it up.
Thomas> $ mysql test2
mysql> create table test2 (ordid int(8) not null auto_increment, ord
Thomas> varchar(50) not null, primary key (ordid), index(ord,ordid));
Thomas> Query OK, 0 rows affected (0.00 sec)
mysql> insert into test2 (ordid,ord) values (NULL,'sdj');
Thomas> Query OK, 1 row affected (0.00 sec)
mysql> insert into test2 (ordid,ord) values (NULL,'dsfg');
Thomas> ERROR 1062: Duplicate entry '1' for key 1
mysql> insert into test2 (ord) values ('sear');
Thomas> ERROR 1062: Duplicate entry '1' for key 1
mysql> insert into test2 (ordid,ord) values (0,'dsfg');
Thomas> ERROR 1062: Duplicate entry '1' for key 1
mysql> insert into test2 (ordid,ord) values ('0','dsfg');
Thomas> ERROR 1062: Duplicate entry '1' for key 1
<cut>
Thomas> Hope this helps!
It did!
The problem was when using MyISAM and using an auto_increment column
in two keys.
Here is a fix for this:
*** /my/monty/master/mysql-3.23.4-alpha/sql/crebas.cc Mon Aug 30 00:03:02 1999
--- ./crebas.cc Thu Oct 7 14:35:14 1999
***************
*** 261,266 ****
--- 261,267 ----
{
int error;
uint i,j,recpos,minpos,fieldpos,temp_length,length;
+ bool found_auto_increment=0;
enum ha_base_keytype type;
char buff[FN_REFLEN];
KEY *pos;
***************
*** 329,336 ****
keydef[i].seg[j].null_bit=0;
keydef[i].seg[j].null_pos=0;
}
! if (field->flags & AUTO_INCREMENT_FLAG)
keydef[i].flag|=HA_AUTO_KEY;
if (field->type() == FIELD_TYPE_BLOB)
{
keydef[i].seg[j].flag|=HA_BLOB_PART;
--- 330,341 ----
keydef[i].seg[j].null_bit=0;
keydef[i].seg[j].null_pos=0;
}
! if (j == 0 && field->flags & AUTO_INCREMENT_FLAG &&
! !found_auto_increment)
! {
keydef[i].flag|=HA_AUTO_KEY;
+ found_auto_increment=1;
+ }
if (field->type() == FIELD_TYPE_BLOB)
{
keydef[i].seg[j].flag|=HA_BLOB_PART;
Regards,
Monty