ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

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
  #1  
Old April 16th, 2004, 11:35 AM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 763 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 7 h 42 m 24 sec
Reputation Power: 13
CFOUTPUT based upon SQL IF statement?

I have a query that checks to see if a primary key exists in the table before inserting a row entered by a user. The statement reads:

Code:
IF #form.itemid# NOT IN(SELECT ItemID FROM Merchandise)
	INSERT INTO Merchandise (...) VALUES (...)


So what I want to do is print confirmation. If the record was inserted, print something, and if the primary key already existed in the database, print something like "could not insert, pk already exists..."

I assume this will require a getRowCount(), but what do I count? myQuery.getRowCount() always returns 0 regardless of whether it was inserted or not.

I know I'll need to use CFINSERT too, but how can I check to make sure the primary key being inserted doesn't already exist in the table?
__________________
Reinventing the wheel again

Last edited by mateoc15 : April 16th, 2004 at 12:28 PM.

Reply With Quote
  #2  
Old April 16th, 2004, 01:08 PM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 763 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 7 h 42 m 24 sec
Reputation Power: 13
OK, I've narrowed the question.

Code:
<CFQUERY datasource="#DataSource#" name="merchandise">
	SELECT	DISTINCT ItemID
	FROM	Merchandise	
</CFQUERY>
<CFIF (CHECK form.itemid against all mechandise ItemID 
to make sure it's not already in there)>
<CFINSERT ...>
<CFOUTPUT>Confirmation Message</CFOUTPUT>
</CFIF>


So how do I code the bolded, underlined part? Can something like ListQualify be used to get every value from a column in a select statement?

Last edited by mateoc15 : April 16th, 2004 at 01:12 PM.

Reply With Quote
  #3  
Old April 16th, 2004, 02:18 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,494 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 41 m 47 sec
Reputation Power: 45
Woah, why are you running a query and pulling out a list of all the id's, and then checking the form value against that list? That is total overkill and a very bad idea, and this solution will blow up in your face if the database has ten million records in it. Why not just do:

Code:
<CFQUERY name="checkForNewRecord" datasource="#DataSource#" name="merchandise">
	SELECT	ItemID
	FROM	Merchandise
	WHERE    ItemID = #form.itemid#
</CFQUERY>
<CFIF not checkForNewRecord.recordCount>
<CFINSERT ...>
<CFOUTPUT>Confirmation Message</CFOUTPUT>
</CFIF>


As an aside, using <cfinsert> is also a bad, bad idea, that tag sucks. Just write your own SQL insert statement using <cfquery>.

Last edited by kiteless : April 16th, 2004 at 02:20 PM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > CFOUTPUT based upon SQL IF statement?


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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway