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
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 24th, 2004, 11:35 AM
mike_uk mike_uk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 9 mike_uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m
Reputation Power: 0
Inserting data into tables with SQL

Right i have made a simple orderform whereby an individual will choose from a product from a drop-menu, they will also provide details about the quantity needed of the product ordered. When the order is submitted then the data will go into the necessary fields and an ordernumber automatically generated.

I need to insert data into two tables. Into one of the tables is a field called OrderNo, this is an autonumber field so i have been told that for the SQL INSERT command if i put 0 then this will be okay and the order will be assigned a number. The other field is this table is called RecipeCode which is passed through when the Pizza is chosen i.e. RecipeCode idtentifies the PizzaName.

For the 2nd table again there is the field OrderNo, this is the key that links upto the ORDERDETAIL table so will the value be automatically passed through? In addition, when the order is placed i need to create an OrderDate, I've been told that the command Now() will insert the current date to the required field, is this correct?
Finally I also need to obtain a price for the order that has been placed. Now I'm using the RecipeCode field that tells me the PizzaName, this will also give me the cost for a pizza but i'm not too sure how to calculate this figure...
could it be something like <variable> = PizzaQuantity * PizzaPrice

so far the commands that i have are as follows:
<CFQUERY NAME="InsertPizzaDetails" DATASOURCE="******">
INSERT INTO ORDERDETAIL (OrderNo, RecipeCode)
VALUES (0,form.PizzaName)
<!-- when passing data through use keywords such as form.PizzaName (i.e SELECT NAME option on order form, this will uniquely store only one pizza name value to process onto the form, same goes with other fields too -->
<CFQUERY NAME="InsertDatePrice">
INSERT INTO ORDERS (OrderNo, OrderDate,TotalOrder)
VALUES (0,Now())

Reply With Quote
  #2  
Old April 25th, 2004, 05:37 AM
mike_uk mike_uk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 9 mike_uk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m
Reputation Power: 0
follow up....

How does coldfusion make use out of autonumbers? Also when using the INSERT INTO command how is it best to input todays date?
would it just be
INSERT INTO table_name
VALUES (?,Date(),?)

Reply With Quote
  #3  
Old April 25th, 2004, 11:09 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 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 10 m 11 sec
Reputation Power: 42
This seems to be a recurring theme lately, with people trying to figure out "what ColdFusion does with SQL", or "does CF support X in my SQL statement..."

ColdFusion does nothing with SQL except process any CFML functions or tags in the statement, format it, and forward it to a database. So, a SQL statement in CF will support whatever the database it is being forwarded to supports.

So, for an autonumber field, you don't even have to include it in the SQL statement at all, the database will automatically insert a unique value in that column at the time of the insert (that is what an autonumber column does, it is basically a trigger under the hood, but that's going off on a tangent).

The CFML Now() function will be replaced by a date/time value before the SQL is forwarded to the database. So in the end, your statement should be something like:

<CFQUERY NAME="InsertDatePrice">
INSERT INTO ORDERS (OrderDate,TotalOrder)
VALUES (#now()#,#form.totalOrder#)
</CFQUERY>

(Now might need quotes around it like '#now()#' depending on your database. Note that a huge part of your problem is that you are not qualifying the ColdFusion variables and functions with pound signs in your SQL statement.)

Reply With Quote
  #4  
Old April 25th, 2004, 09:40 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,743 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 15 m 47 sec
Reputation Power: 870
good job, kiteless, except i would recommend not using coldfusion's now() function, which, in the context of a query, will be translated into a string

this causes the database needless extra processing (okay, it's only a few micro-nano-pico-seconds, but the point still stands) to parse the string, validate the date, and convert it to internal datetime format

if, on the other hand, you use a builtin database function for this purpose, it will go much more slickly

thus,

<CFQUERY NAME="InsertDatePrice">
INSERT INTO ORDERS (OrderDate,TotalOrder)
VALUES (current_date,#form.totalOrder#)
</CFQUERY>

use current_date or sysdate or getdate(), or even -- as for access, what a coincidence, eh? -- now()
__________________
r937.com | rudy.ca

Reply With Quote
  #5  
Old April 27th, 2004, 12:12 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 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 10 m 11 sec
Reputation Power: 42
Spot on, r937. Always get the database to do as much work as possible!

Reply With Quote
  #6  
Old April 27th, 2004, 12:28 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,743 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 15 m 47 sec
Reputation Power: 870
thank you

but i think i was pointing out how to let the database do as little work as possible


Reply With Quote
  #7  
Old April 27th, 2004, 02:56 PM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,488 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 10 m 11 sec
Reputation Power: 42
heh...I think we're calling the same thing 2 different names. Every time I can offload a function call, some conditional logic, or number crunching from CF to the database, I try to do it. That's what I mean when I say make the database do as much work as possible.

Reply With Quote
  #8  
Old April 27th, 2004, 04:14 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 24th Plane (16500 - 16999 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 16,743 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 2 Days 21 h 15 m 47 sec
Reputation Power: 870
oh, i understand that, and i totally agree

it's just that this was a different scenario

using ColdFusion's #now()# function makes the database actually do more work than if you let the database use its own current date function, so i was suggesting offloading the function to the database because that's actually less work for the database, not "make the database do as much work as possible"

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Inserting data into tables with SQL


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 6 hosted by Hostway