At 12:40 PM +0530 12/19/00, Rama Krishna wrote:
>Hi,
>
> I got a problem while inserting the primary key in a table, for
>which AUTO_INCREMENT was given.
>I'am using MySQL Database with Perl using DBI module ;
>
>Table was created using the following ..
>
>CREATE TABLE user (
> id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
> name varchar(20)
>) ;
>
>Below is the table structure...
>------------------------------------------------------------------------------------------------------------
>Field Type Null Key Default
>Extra
>------------------------------------------------------------------------------------------------------------
>id bigint(20) PRI 0
>auto_increment
>name varchar YES NULL
>
>-------------------------------------------------------------------------------------------------------------
>
>
>After the value of "id" reached 256, and while inserting, the
>following error message was encountered.
>
>Duplicate entry '256' for key 1
>
>
>The code written was as following ;
>
>######## code starts here #################
>
>my $dbh = DBI->connect( $dsn, $db_user, $db_pass ) ;
>## $dsn is data sourse name, $db_user is username, $db_pass is password ###
>
>$qry = "insert into user values( last_insert_id( uid ), 'name')";
What is the function of "uid" here? You don't have any such column
in your table.
It's not clear what you expect this query to do.
>
>my $RS = $dbh->prepare( $qry ) ;
>
>if ( ! $RS ) {
> print "Unable to run query : " . $dbh->errstr ;
> exit( 0 ) ;
>}
>
>if ( ! $RS->execute() ) {
> print "Unable to execute query : " . $RS->errstr ;
> exit( 0 ) ;
>}
>
>######### code ends here #################
>
>Is the problem with "last_insert_id" or "AUTO_INCREMENT" or the way
>of executing the query ???
>
>Please reply....
>
>Rama Krishna
--
Paul DuBois, paul@stripped