|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
PROBLEM:
First line of code just will not work for me. It does not make the column unique and allows for duplicates. WHY????? Can anyone tell me where I am going wrong??????? Thanks in advance. CODE: $dbh->do("CREATE UNIQUE INDEX idx_name ON t0(name)"); $dbh->do("DELETE FROM t0"); my $loop = 0; foreach $key (keys(%FORM)) { $loop += $loop + 1; print "$key = $FORM{$key}<br>"; my $val = $FORM{$key}; $dbh->do("INSERT INTO t0 VALUES ($loop, '$val')"); } $dbh->do("DELETE FROM t0 WHERE name < '0'"); my $sth = $dbh->prepare("SELECT pk, name FROM t0"); $sth->{"mysql_use_result"} = 1; $sth->execute(); my $numFields = $sth->{'NUM_OF_FIELDS'}; print $numFields; my $names = $sth->{'NAME'}; print '<select name=Choice>'; while (my $ref = $sth->fetchrow_arrayref) { for (my $i = 0; $i < $numFields; $i++) { if ($i) { printf ("%s</option>",$$ref[$i]); } else { printf ("<option value=%s>",$i); } } print '<br>'; } print '</select><br><br>'; $dbh->disconnect();
__________________
******* Lorraine |
|
#2
|
|||
|
|||
|
you should check that the index is actually being created, incase that's the problem
$dbh->do("CREATE UNIQUE INDEX idx_name ON t0(name)") or die ('Error creating index', $dbh->errstr); |
|
#3
|
|||
|
|||
|
PL/SQL
i tried out your suggestion:
$dbh->do("CREATE UNIQUE INDEX idx_name ON t0(name)") or die ('Error creating index', $dbh->errstr); I only get a blank screen. when i don't include the 'or die........' part the code carry's on but it allows for duplicates. |
|
#4
|
|||
|
|||
|
if you put this after use DBI;
use CGI::Carp qw(fatalsToBrowser); it should print out the error message on the browser |
|
#5
|
|||
|
|||
|
PL/SQL
Thanks
I used use CGI::Carp qw(fatalsToBrowser); and this what it keeps telling me Error creating indexDuplicate key name 'idx_name' at 0.cgi line 31. I changed the name of the index to something i know is not in the database eg.butterfly, sky etc. and it still gives me that error. do you have any idea why??? Thanks for all your help. :) |
|
#6
|
|||
|
|||
|
Forget last message. It works now when I use the following code:-
use CGI::Carp qw(fatalsToBrowser); $dbh->do("ALTER TABLE t0 MODIFY name CHAR(255) NOT NULL") or die('Error creating modify', $dbh->errstr); $dbh->do("ALTER TABLE t0 ADD UNIQUE (name(6))") or die ('Error creating index', $dbh->errstr); THANKS for all your help. You were tremendous. ![]() |
|
#7
|
|||
|
|||
|
Just a note, PL/SQL is a procedural language used by the Oracle database, it has nothing to do with perl.. Maybe you should refer to perl and mysql as perl/mysql to prevent confusion.
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > PL/MySQL |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|