473,414 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Perl DBI / SQL Question

Sorry if the cross-posting wasn't appropriate, but I need help with this and
am not sure if it's more appropriate to post under MySQL or Perl...I want to
be sure that I can get help from the best source.

My question is probably a simple answer, but I am not sure what I have to do
and the books I have here are either not answering the question, or I'm not
finding the answer.

I need to know how to retrieve through Perl DBI a listing of possible ENUM
elements from a field for processing under a CGI script. If all I need for
this is some form of SELECT statement, please provide a code snippet of this
so I can do it.

I want to make my code so I'm not having to edit hard-coded Perl CGI scripts
if/when I add new elements to the ENUM field. Any help you can provide
would be greatly appreciated.

Thanks!

Vance
Sep 14 '05 #1
11 2634
Vance M. Allen wrote:
Sorry if the cross-posting wasn't appropriate, but I need help with this
and am not sure if it's more appropriate to post under MySQL or Perl...I
want to be sure that I can get help from the best source.

My question is probably a simple answer, but I am not sure what I have to
do and the books I have here are either not answering the question, or I'm
not finding the answer.

I need to know how to retrieve through Perl DBI a listing of possible ENUM
elements from a field for processing under a CGI script. If all I need
for this is some form of SELECT statement, please provide a code snippet
of this so I can do it.

I want to make my code so I'm not having to edit hard-coded Perl CGI
scripts
if/when I add new elements to the ENUM field. Any help you can provide
would be greatly appreciated.

Thanks!

Vance

I don't know if there's a built-in may of doing this, but it got me
thinking. Here's a dirty was of doing it.

my $sth = $dbh->prepare("DESCRIBE tablename fieldname");
$sth->execute();
my @row = $sth->fetchrow_array();
my $enum = $row[1];
$enum =~ s!^enum\(!!;
$enum =~ s!\)$!!;
my @enum = split/,/,$enum;
foreach(@enum) {
s!^'!!;
s!'$!!;
}

print "$_\n" foreach @enum;
--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
Sep 14 '05 #2
Vance M. Allen wrote:
I need to know how to retrieve through Perl DBI a listing of possible ENUM
elements from a field for processing under a CGI script.


It's for this reason that I avoid using ENUM datatypes.
It's much easier to get the list of values if you define the set of
values in a lookup table, and just reference the lookup table in your
field definition.

CREATE TABLE foo_lookup (
foo VARCHAR(32) PRIMARY KEY
) TYPE=InnoDB;
CREATE TABLE t (
foo VARCHAR(32) REFERENCES foo_lookup
) TYPE=InnoDB;

Then you can get the list of values simply: "SELECT foo FROM
foo_lookup". Note that you must use InnoDB tables if you want these
references to be enforced by the DBMS.

This method makes it easier to change the set of values, too.
Otherwise you have to change the field definition when you change the
values in the ENUM.

I find ENUM is best used for cases when you know the set of values will
be unchanging. Like True/False (if your DBMS doesn't support a boolean
type), or Male/Female, or Approved/Denied, etc.

Regards,
Bill K.
Sep 14 '05 #3
Good point. My situation is this.. I basically have a Security table, and
currently the ENUM is listing the different actions that are available, and
the table has a simple Y/N for whether each of the access groups is
permitted for the action. If you have any good suggestions or examples for
how to handle this, it would be greatly appreciated.

Thanks,

Vance
"Bill Karwin" <bi**@karwin.com> wrote in message
news:dg*********@enews3.newsguy.com...
Vance M. Allen wrote:
I need to know how to retrieve through Perl DBI a listing of possible ENUM
elements from a field for processing under a CGI script.


It's for this reason that I avoid using ENUM datatypes.
It's much easier to get the list of values if you define the set of
values in a lookup table, and just reference the lookup table in your
field definition.

CREATE TABLE foo_lookup (
foo VARCHAR(32) PRIMARY KEY
) TYPE=InnoDB;
CREATE TABLE t (
foo VARCHAR(32) REFERENCES foo_lookup
) TYPE=InnoDB;

Then you can get the list of values simply: "SELECT foo FROM
foo_lookup". Note that you must use InnoDB tables if you want these
references to be enforced by the DBMS.

This method makes it easier to change the set of values, too.
Otherwise you have to change the field definition when you change the
values in the ENUM.

I find ENUM is best used for cases when you know the set of values will
be unchanging. Like True/False (if your DBMS doesn't support a boolean
type), or Male/Female, or Approved/Denied, etc.

Regards,
Bill K.
Sep 14 '05 #4
Vance M. Allen wrote:
Good point. My situation is this.. I basically have a Security table, and
currently the ENUM is listing the different actions that are available, and
the table has a simple Y/N for whether each of the access groups is
permitted for the action. If you have any good suggestions or examples for
how to handle this, it would be greatly appreciated.


You need another table:

CREATE TABLE privilege (
access_group_id INTEGER NOT NULL
REFERENCES access_group(access_group_id),
priv_type_id INTEGER NOT NULL
REFERENCES privelege_type(priv_type_id),
permitted BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (access_group_id, priv_type_id)
);

CREATE TABLE privilege_type (
priv_type_id INTEGER NOT NULL PRIMARY KEY,
priv_type_name VARCHAR(64)
);

Now you take all the priveleges info out of your access_group table, and
rely on the rows in the privelege table.

This allows you to add new types of privileges without changing your
schema, and also allows you to look up the list of currently valid
privilege types by "SELECT * FROM privelege_type".

Absence of a row in the privilege table for a given priv type could be
equivalent to not having that privilege. Or if you want to get fancy,
you can make certain privileges have different defaults. Add a
"default_permitted BOOLEAN" to the privilege_type table, and use a query
like the following to get all privileges for all access groups:

SELECT g.id, pt.priv_type_id,
COALESCE(p.permitted, pt.default_permitted) AS permitted
FROM access_group AS g
INNER JOIN privilege_type AS pt
LEFT OUTER JOIN privilege AS p ON pt.priv_type_id = p.priv_type_id;

(note the rare appropriate use of a Cartesian product!)

Regards,
Bill K.
Sep 14 '05 #5
I see where you're going with this, and I like it much better than what I
have. I have a question about it though. I currently have phpMyAdmin set
up to do hard edits to the data in my database when needed, and every time
I'm on the database structure page, I receive a message:

"The additional Features for working with linked Tables have been
deactivated."

Am I going to be able to use "REFERENCES" in the table definition with this
being the case? If not, do you know what I need to do in order to correct
this problem?

Thanks,

Vance
Sep 15 '05 #6
In article <hX***************@news.uswest.net>,
"Vance M. Allen" <vm******@vmacs.us> wrote:
I see where you're going with this, [...]


You see where who is going with what? Please quote the relevant parts
of the post you're responding to, which is long-standing Usenet practice.
--
Kevin Michael Vail | a billion stars go spinning through the night,
ke***@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . | will be, when all the stars are dead.
. . . . . . . . . | (Rainer Maria Rilke)
Sep 15 '05 #7
Vance M. Allen wrote:
"The additional Features for working with linked Tables have been
deactivated."


This is a new one for me. Fortunately google helps with all things:

http://www.psoft.net/HSdocumentation...ed_tables.html

Regards,
Bill K.
Sep 15 '05 #8
> You see where who is going with what? Please quote the relevant parts
of the post you're responding to, which is long-standing Usenet practice.


I saw where Bill was going with the entire message he wrote. As I wrote it
as a reply to his message, causing it to be part of the same thread, I did
not realize it was necessary to re-post the entire message. I will try
harder to meet Usenet etiquette. Apologies to anyone affected by my failure
to do so.

Vance
Sep 15 '05 #9
>I see where you're going with this, and I like it much better than what I
have. I have a question about it though. I currently have phpMyAdmin set
up to do hard edits to the data in my database when needed, and every time
I'm on the database structure page, I receive a message:

"The additional Features for working with linked Tables have been
deactivated."


As I recall, this type of message comes up for a number of reasons
relating to the database (often called 'phpmyadmin') used by
phpMyAdmin to store some of its own data. I think the problem is:

- It can't log into the database (or has the wrong name for
it) or doesn't have permissions on the tables it needs.
- You didn't create the database or tables for it.

I think the features that have been deactivated refer to making
diagrams of the relationships between tables and such, not using
references, which is a MySQL, not phpMyAdmin, feature.

Gordon L. Burditt
Sep 15 '05 #10
"Gordon Burditt" <go***********@burditt.org> wrote in message
news:11*************@corp.supernews.com...
"The additional Features for working with linked Tables have been
deactivated."
I think the features that have been deactivated refer to making
diagrams of the relationships between tables and such, not using
references, which is a MySQL, not phpMyAdmin, feature.


"Bill Karwin" <bi**@karwin.com> wrote in message
news:dg*********@enews3.newsguy.com... http://www.psoft.net/HSdocumentation...ed_tables.html


Thank you Gordon. I did the steps on the page Bill provided for me, and it
resolved the message in phpMyAdmin, but I didn't really see anything in
phpMyAdmin afterward that seemed relevant to my issue. I'm going to try his
SQL and we'll see if it works.

Thanks for everyone's help.

Vance
Sep 15 '05 #11
"Vance M. Allen" <vm******@vmacs.us> wrote in
news:lV***************@news.uswest.net:
You see where who is going with what? Please quote the relevant
parts of the post you're responding to, which is long-standing Usenet
practice.
....
I did not realize it was necessary to re-post the entire
message.


It is not.

Sinan
--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/cl...uidelines.html
Sep 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lionel | last post by:
Hi all, I would like having more informations on how we could exchange informations and/or objects between PERL and JAVA. We have a Java programs that open, maintain and close telnet...
6
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
31
by: surfunbear | last post by:
I've read some posts on Perl versus Python and studied a bit of my Python book. I'm a software engineer, familiar with C++ objected oriented development, but have been using Perl because it is...
3
by: lonelyplanet999 | last post by:
Hi, I'm a newbie to perl and is now studying about perl programming, I read some perl programming tutorials online (enter 'Perl tutorial' at google.com) and also find some sample perl scripts...
2
by: James Hull | last post by:
Hi All: I am new in the Perl world. So far I have installed cygwin and Perl 5.8.0 along with Perl DBI and DBD::Oracle modules. NowI am trying to install Perl Tk on my PC (Windows 2K). I have...
1
by: sm00thcrimnl13 | last post by:
if i have windows 2000 and know how to write perl scripts, how to i actuvate the script through perl?
3
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
1
by: M.N.A.Smadi | last post by:
hi guys; sorry for sending a perl question here, but python guy "HAD TO" look at perl code; how can i split a string that contains white spaces and '_' any clue? thanks
13
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.