Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 4th, 2001, 05:05 PM
lorsul lorsul is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Pittsburgh
Posts: 32 lorsul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Unhappy PL/MySQL

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

Reply With Quote
  #2  
Old September 4th, 2001, 05:18 PM
bumperbox bumperbox is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Tauranga, NZ
Posts: 349 bumperbox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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);

Reply With Quote
  #3  
Old September 4th, 2001, 05:28 PM
lorsul lorsul is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Pittsburgh
Posts: 32 lorsul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #4  
Old September 4th, 2001, 05:40 PM
bumperbox bumperbox is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Tauranga, NZ
Posts: 349 bumperbox User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
if you put this after use DBI;
use CGI::Carp qw(fatalsToBrowser);

it should print out the error message on the browser

Reply With Quote
  #5  
Old September 5th, 2001, 09:10 AM
lorsul lorsul is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Pittsburgh
Posts: 32 lorsul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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. :)

Reply With Quote
  #6  
Old September 5th, 2001, 10:20 AM
lorsul lorsul is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: Pittsburgh
Posts: 32 lorsul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Smile PL/SQL

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.

Reply With Quote
  #7  
Old September 5th, 2001, 11:40 AM
JeffCT JeffCT is offline
PHP & Ruby Developer
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2001
Posts: 1,437 JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level)JeffCT User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 5 h 36 m 40 sec
Reputation Power: 9
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > PL/MySQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT