home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2828
Discussions: 188,380, Posts: 2,243,467, Members: 232,608
Old October 29th, 2002, 10:01 PM   Digg it!   #1 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Perl~SQLPlus question

If you have a form that asks for a table, and returns a

SELECT * from $table

How would you incorporate a 'safety' element for when the user inputs a table not in a database?

Rather than getting a 'blank' response, the user should see something like:

"The table you requested is not in the database."


*edited for slight retardation*


Last edited by tenor_david : October 29th, 2002 at 10:42 PM.
tenor_david is offline   Reply With Quote
Old October 29th, 2002, 10:13 PM     #2 (permalink)
Real gangstas sip on Yacc
 
jkrohn's Avatar
 
Join Date: Oct 2001
Location: Suckas-ville
Posts: 4,549
Send a message via ICQ to jkrohn Send a message via AIM to jkrohn Send a message via Yahoo to jkrohn
Hmm, I have little knowledge of SQL, but this seems possible.

1) Make a sub function called in_database
2) In this function compare the entered table to all the tables in teh database. If you get a match return 1. If not return zero with a message "Table not found"

Then in main run
if(in_database) for your select query


Jkrohn
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.

jkrohn is offline   Reply With Quote
Old October 29th, 2002, 10:22 PM     #3 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Let's back up a step....how do compare the entered table to tables that you have?

I am a SuperNewbie. I know next to nothing.

tenor_david is offline   Reply With Quote
Old October 29th, 2002, 10:36 PM     #4 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,019
I don't know how to do it mysql, but in sql server there is a table called sysobjects in each database. This is a special system table that holds all of the objects in that database.. including tables! So if you can find the table that stores all of the table names in the database that'd be one way

OR ... you could create your own table that stores that information.
vass0922 is online now   Reply With Quote
Old October 29th, 2002, 10:40 PM     #5 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: Alberta, Canada
Posts: 563
had a quick look at mysql docs, and couldn't come up with much of a query to check for a single table in a db... but that doesn't neccessarily mean the functionality doesn't exist tho!! might be out there somewhere...

you can however, return "all" the tables in a db with the statement "SHOW TABLES FROM your_database_name", but I'm not sure if it returns a proper query to loop thru and check for your table. you'd have to try it out...

anyways, I've never done perl w/mysql, just php, but I just wrote a quick script and it appears that mysql returns an error number of 1146 if the table doesn't exist... I imagine it'd be the same in perl... but might not, again, you'd have to try it out!!

so... you could do the query, then test the error code from mysql, if it is 1146 then the table doesn't exist... and display your message...

anyways, early morning tomorrow, bedtime!!

cheers and good luck!
^hyd^ is offline   Reply With Quote
Old October 29th, 2002, 10:41 PM     #6 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Sorry, I am an idiot. I meant Perl ~ SQLplus. Any thoughts on how to do it with SQLplus?
tenor_david is offline   Reply With Quote
Old October 29th, 2002, 10:44 PM     #7 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: Alberta, Canada
Posts: 563
DOH!!! well, could still do similar to how I mentioned... find the error number for "table doesn't exist" (ie: run a query on a table that ain't there, and get the sql error number) then test for it and act on it accordingly...

once again, g'night!!



dang it's hard to leave this computer to go to bed!!!
^hyd^ is offline   Reply With Quote
Old October 30th, 2002, 12:20 AM     #8 (permalink)
Ultimate Member
 
Join Date: Oct 2001
Posts: 21,019
sqlplus meaning oracle?
vass0922 is online now   Reply With Quote
Old October 30th, 2002, 08:50 AM     #9 (permalink)
Member
 
tenor_david's Avatar
 
Join Date: Nov 2001
Location: Bloomington IN
Posts: 219
Yes, I do mean Oracle.

I got it to work. We had to load the results into and array, so I used:

if ($#data < 0) {
$result = "Could not find " . $in{'table'} . " in the database.";
}

to check and see if there were no elements in the array.

Now I need to figure out how to display the records 10 records/page. I can get the query to only output 10 records via:

$db_command = "select * from " . $in{'table'} . " where rownum<=10";

But of course that only gives you 10 of xxx records...... Anyone have any pointers on getting all of the records and displaying them in xx amount of pages?



Last edited by tenor_david : October 30th, 2002 at 09:30 AM.
tenor_david is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may 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
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2885)
The United States Debt (20)
Looks like Burris will get his Sena.. (8)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
Folderchat Weekday thread (439)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (14)
Help with an Ati Radeon HD 4850 512.. (25)
Recent Discussions
RCA 52Inch HDTV wont turn on (1)
Building a gaming computer advi.. (1)
Best digital camera for under 2.. (14)
Help with an Ati Radeon HD 4850.. (25)
Install Problem for Windows Def.. (0)
New Build ( Finally ) (1)
dual monitors wont boot (0)
Folderchat Weekday thread (439)
MSN Hotmail Down??? (7)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 08:53 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28