Allow single quote in query 
October 2nd, 2008, 07:22 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| |
I got one last question. Its more related to my question about the serials and would post it in that forum but we already closed it an i think its a simple question, if it needs a new forum let me know :).
When i was testing out insertinga description and a resolution (both textarea fields).When i go to submit i noticed a problem.if you put any words like for example: here's in the field it will not submit it. The comma is what it is having trouble on. An i have a textarea field like these 2 an it has no trouble with it an they have everything the same except how it inserts. This is what i have for when it inserts for both resolution and description - <CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount)>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = "Form.serialnum_" & machineCount>
-
<CFSET modelno = "Form.modelno_" & machineCount>
-
<CFSET producttype = "Form.producttype_" & machineCount>
-
<CFSET softhardware = "Form.softhardware_" & machineCount>
-
<CFSET resolution = "Form.resolution_" & machineCount>
-
<CFSET resdate = "Form.resdate_" & machineCount>
-
<CFSET resvertified = "Form.resvertified_" & machineCount>
-
<CFSET vertifidate = "Form.vertifidate_" & machineCount>
-
<CFSET deptvendor = "Form.deptvendor_" & machinecount>
-
<CFSET hardwarefailure = "Form.hardwarefailure_" & machineCount>
-
<CFSET rma = "Form.rma_" & machineCount>
-
<CFSET thedescription = "Form.thedescription_" & machineCount>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
'#evaluate(serialnum)#','#Form.ID#','#evaluate(modelno)#','#evaluate(producttype)#',
-
'#evaluate(softhardware)#','#evaluate(resolution)#','#evaluate(resdate)#',
-
'#evaluate(resvertified)#','#evaluate(vertifidate)#','#evaluate(deptvendor)#',
-
'#evaluate(hardwarefailure)#','#evaluate(rma)#'
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
'#evaluate(serialnum)#','#Form.ID#','#evaluate(thedescription)#','#Form.fk_addedBy#'
-
</cfquery>
-
-
</CFLOOP>
-
</CFIF>
I thought/think its the listLen causing the trouble an i tried this listLen(Form.serialcount," ' ") to make it so it would accept commas, but
it didn't work. But i am basically wondering if there is a way to make it accept commas or if the way i am doing it will just not accept commas?
Thank you,
Rach
Last edited by acoder; October 3rd, 2008 at 02:47 PM.
Reason: Removed irrelevant text
| 
October 2nd, 2008, 08:14 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
You need to escape the single quotes. If you use cfqueryparam (read up on it), it will do it for you automatically.
You can also avoid the evaluate statements by using the form struct, e.g. - <CFSET serialnum = Form["serialnum_" & machineCount]>
Last edited by acoder; October 3rd, 2008 at 02:48 PM.
Reason: Removed text
| 
October 2nd, 2008, 08:38 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query
Hey Acoder,
But i am confused on the cfqueryparam. Basically from the examples online
it looks like you put the cfqueryparam inside the cfquery correct? an since i am using 2 different cfquerys would i put the cfqueryparam in both cfquerys?and then what would the value be for both? here is the example i am looking at http://www.cimmyt.org/CFDOCS/CFML_Reference/Tags79.html
Thank you again :),
Rach
Last edited by acoder; October 3rd, 2008 at 02:48 PM.
Reason: Removed text
| 
October 2nd, 2008, 10:41 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
Yes, you should be using cfqueryparam for all user input into a cfquery and you would use it for each field.
Instead of the link that you've looked at, get the latest docs from the Adobe website and for your version of Coldfusion. Tags can sometimes change from version to version.
| 
October 3rd, 2008, 02:13 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query
Hey Acoder,
Well it looks like what i have is for the correct version of mine. But i must admit i am still baffled. Are you saying to do something like - <cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
'#evaluate(serialnum)#','#Form.ID#','#evaluate(modelno)#','#evaluate(producttype)#',
-
'#evaluate(softhardware)#','#evaluate(resolution)#','#evaluate(resdate)#',
-
'#evaluate(resvertified)#','#evaluate(vertifidate)#','#evaluate(deptvendor)#',
-
'#evaluate(hardwarefailure)#','#evaluate(rma)#'
-
<cfqueryPARAM value =#evaluate(serialnum)#>
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
'#evaluate(serialnum)#','#Form.ID#','#evaluate(thedescription)#',
-
'#Form.fk_addedBy#'
-
<cfqueryPARAM value =#evaluate(serialnum)#>
-
</cfquery>
-
i am just confused on what the value should be.
Thank you,
Rach
| 
October 3rd, 2008, 02:51 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
Yes, but not just for one value, but all values. As I mentioned earlier, you can avoid using evaluate() by using the form struct. For some fields, you should also use the CFSQLTYPE attribute of the cfqueryparam tag.
Note: split from URL Method for 3 tables?.
| 
October 3rd, 2008, 03:18 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query
Hey Acoder,
I decided to try your other way with the avoid the evaluate and it won't work :(.
here is what i have, it starts having a problem after exec usp_cs_insertserial. do i need to change the names in the cfquery to something else? - <!---Inserts information into serial table.--->
-
<CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount, " ' ")>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = Form["serialnum_" & machineCount]>
-
<CFSET modelno = Form["modelno_" & machineCount]>
-
<CFSET producttype = Form["producttype_" & machineCount]>
-
<CFSET softhardware = Form["softhardware_" & machineCount]>
-
<CFSET resolution = Form["resolution_" & machineCount]>
-
<CFSET resdate = Form["resdate_" & machineCount]>
-
<CFSET resvertified = Form["resvertified_" & machineCount]>
-
<CFSET vertifidate = Form["vertifidate_" & machineCount]>
-
<CFSET deptvendor = Form["deptvendor_" & machinecount]>
-
<CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
-
<CFSET rma = Form["rma_" & machineCount]>
-
<CFSET thedescription = Form["thedescription_" & machineCount]>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
'#serialnum#','#Form.ID#','#modelno#','#producttype#',
-
'#softhardware#','#resolution#','#resdate#',
-
'#resvertified#','#vertifidate#','#deptvendor#',
-
'#hardwarefailure#','#rma#'
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
'#serialnum#','#Form.ID#','#thedescription#','#Form.fk_addedBy#'
-
</cfquery>
-
-
</CFLOOP>
-
</CFIF>
Thank you,
Rach
| 
October 3rd, 2008, 10:05 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
When you say it doesn't work, do you mean with a single quote ' or just in general? Check the values of the variables.
Together with avoiding evaluate (which was just a best practice/performance issue), you still need to use cfqueryparam.
| 
October 7th, 2008, 02:20 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder When you say it doesn't work, do you mean with a single quote ' or just in general? Check the values of the variables.
Together with avoiding evaluate (which was just a best practice/performance issue), you still need to use cfqueryparam. | Hey Acoder,
I am meaning the whole thing does not work right now. But where does the cfqueryparam need to go? never done one so i am just confused on how to go about that. But here is what i have - <!---Inserts information into serial table.--->
-
<CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount, " ' ")>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = Form["serialnum_" & machineCount]>
-
<CFSET modelno = Form["modelno_" & machineCount]>
-
<CFSET producttype = Form["producttype_" & machineCount]>
-
<CFSET softhardware = Form["softhardware_" & machineCount]>
-
<CFSET resolution = Form["resolution_" & machineCount]>
-
<CFSET resdate = Form["resdate_" & machineCount]>
-
<CFSET resvertified = Form["resvertified_" & machineCount]>
-
<CFSET vertifidate = Form["vertifidate_" & machineCount]>
-
<CFSET deptvendor = Form["deptvendor_" & machinecount]>
-
<CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
-
<CFSET rma = Form["rma_" & machineCount]>
-
<CFSET thedescription = Form["thedescription_" & machineCount]>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
'#serialnum#','#Form.ID#','#modelno#','#producttype#',
-
'#softhardware#','#resolution#','#resdate#',
-
'#resvertified#','#vertifidate#','#deptvendor#',
-
'#hardwarefailure#','#rma#'
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
'#serialnum#','#Form.ID#','#thedescription#','#Form.fk_addedBy#'
-
</cfquery>
-
-
</CFLOOP>
-
</CFIF>
Thank you,
Rach
| 
October 7th, 2008, 02:58 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
For each of the inputs, so #serialnum# would be replaced be <cfqueryparam ...> and the same for the rest.
| 
October 7th, 2008, 04:05 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder For each of the inputs, so #serialnum# would be replaced be <cfqueryparam ...> and the same for the rest. | hey acoder,
so something like this,except apply it to every field? - <cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
'<cfqueryparam value="#serialnum#"></cfqueryparam>','#Form.ID#','#modelno#',
-
'#producttype#','#softhardware#','#resolution#','#resdate#',
-
'#resvertified#','#vertifidate#','#deptvendor#',
-
'#hardwarefailure#','#rma#'
-
</CFQUERY>
-
Thank you,
Rach
| 
October 7th, 2008, 04:29 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
Also set the cfsqltype attribute too to the correct type. Optionally, it might be an idea to set maxlength and scale where appropriate. Note that there's no closing tag. See the documentation.
| 
October 7th, 2008, 05:03 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder Also set the cfsqltype attribute too to the correct type. Optionally, it might be an idea to set maxlength and scale where appropriate. Note that there's no closing tag. See the documentation. | Hey Acoder,
Well i tried it an it gave me the error of optional feature not implemented.Got that error after i put date for 2 of the fields -
Microsoft][ODBC SQL Server Driver]Optional feature not implemented
-
-
-
SQL = "exec usp_CS_Insertserial '?', '123', '?', '?', '?', '?', '?', '?', '?', '?', '?', '?'"
-
-
Query Parameter Value(s) -
-
-
Parameter #1 = 3242
-
-
Parameter #2 = 340TWIN
-
-
Parameter #3 = Labtop
-
-
Parameter #4 = Processor
-
-
Parameter #5 = test's
-
-
Parameter #6 = {d '2008-10-07'}
-
-
Parameter #7 = Greg Cason
-
-
Parameter #8 = {d '2008-10-07'}
-
-
Parameter #9 = Vendor Software
-
-
Parameter #10 = OutOfWarranty
-
-
Parameter #11 = rest's
-
-
Data Source = "CUSTOMERSUPPORT"
here is what i have in there right now - <!---Inserts information into serial table.--->
-
<CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount, " ' ")>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = Form["serialnum_" & machineCount]>
-
<CFSET modelno = Form["modelno_" & machineCount]>
-
<CFSET producttype = Form["producttype_" & machineCount]>
-
<CFSET softhardware = Form["softhardware_" & machineCount]>
-
<CFSET resolution = Form["resolution_" & machineCount]>
-
<CFSET resdate = Form["resdate_" & machineCount]>
-
<CFSET resvertified = Form["resvertified_" & machineCount]>
-
<CFSET vertifidate = Form["vertifidate_" & machineCount]>
-
<CFSET deptvendor = Form["deptvendor_" & machinecount]>
-
<CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
-
<CFSET rma = Form["rma_" & machineCount]>
-
<CFSET thedescription = Form["thedescription_" & machineCount]>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
'<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_NUMERIC">',
-
'#Form.ID#',
-
'<cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#resdate#" CFSQLType = "CF_SQL_DATE">',
-
'<cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#vertifidate#" CFSQLType = "CF_SQL_DATE">',
-
'<cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">',
-
'<cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">'
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
'<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">',
-
'#Form.ID#',
-
'<cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">',
-
'#Form.fk_addedBy#'
-
</cfquery>
-
-
</CFLOOP>
-
</CFIF>
Any suggestion on what i am doing wrong?
Thank you,
Rach
| 
October 7th, 2008, 05:41 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
When using cfqueryparam, you don't need the single quotes around the tag. Remove them. Also make sure that the SQL types match those in the database.
| 
October 7th, 2008, 06:36 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder When using cfqueryparam, you don't need the single quotes around the tag. Remove them. Also make sure that the SQL types match those in the database. | Hey Acoder,
I got rid of the single quotes. But i am not sure what you mean by the sql types. Like are you saying instead of using serialnum in my cfquery to use what the name is in the table which is pka_serialNo?here is what i have - <!---Inserts information into serial table.--->
-
<CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount)>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = Form["serialnum_" & machineCount]>
-
<CFSET modelno = Form["modelno_" & machineCount]>
-
<CFSET producttype = Form["producttype_" & machineCount]>
-
<CFSET softhardware = Form["softhardware_" & machineCount]>
-
<CFSET resolution = Form["resolution_" & machineCount]>
-
<CFSET resdate = Form["resdate_" & machineCount]>
-
<CFSET resvertified = Form["resvertified_" & machineCount]>
-
<CFSET vertifidate = Form["vertifidate_" & machineCount]>
-
<CFSET deptvendor = Form["deptvendor_" & machinecount]>
-
<CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
-
<CFSET rma = Form["rma_" & machineCount]>
-
<CFSET thedescription = Form["thedescription_" & machineCount]>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_NUMERIC">,
-
#Form.ID#,
-
<cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#resdate#" CFSQLType = "CF_SQL_DATE">,
-
<cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#vertifidate#" CFSQLType = "CF_SQL_DATE">,
-
<cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">
-
</CFQUERY>
-
<!---Inserts information into notes_descr table.--->
<cfquery name="description" datasource="CustomerSupport">
exec usp_CS_Insertdescription
<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
#Form.ID#,
<cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
#Form.fk_addedBy#'
</cfquery>
</CFLOOP>
</CFIF>
Thank you,
Rach
| 
October 7th, 2008, 06:56 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
No, what you now have is almost there. If #form.id# is a string, then keep the quotes around that field, because you're not using cfqueryparam.
| 
October 7th, 2008, 07:04 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder No, what you now have is almost there. If #form.id# is a string, then keep the quotes around that field, because you're not using cfqueryparam. | Hey Acoder,
Here is what i have but i am still having the same trouble. - <CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount)>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = Form["serialnum_" & machineCount]>
-
<CFSET modelno = Form["modelno_" & machineCount]>
-
<CFSET producttype = Form["producttype_" & machineCount]>
-
<CFSET softhardware = Form["softhardware_" & machineCount]>
-
<CFSET resolution = Form["resolution_" & machineCount]>
-
<CFSET resdate = Form["resdate_" & machineCount]>
-
<CFSET resvertified = Form["resvertified_" & machineCount]>
-
<CFSET vertifidate = Form["vertifidate_" & machineCount]>
-
<CFSET deptvendor = Form["deptvendor_" & machinecount]>
-
<CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
-
<CFSET rma = Form["rma_" & machineCount]>
-
<CFSET thedescription = Form["thedescription_" & machineCount]>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_NUMERIC">,
-
'#Form.ID#',
-
<cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#resdate#" CFSQLType = "CF_SQL_DATE">,
-
<cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#vertifidate#" CFSQLType = "CF_SQL_DATE">,
-
<cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
-
'#Form.ID#',
-
<cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
-
'#Form.fk_addedBy#'
-
</cfquery>
-
-
</CFLOOP>
-
</CFIF>
Thank you,
Rach
| 
October 7th, 2008, 09:21 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
That error seems to be an SQL Server error most probably caused by an incorrect type. Instead of CF_SQL_DATE, try CF_SQL_TIMESTAMP.
| 
October 8th, 2008, 02:10 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder That error seems to be an SQL Server error most probably caused by an incorrect type. Instead of CF_SQL_DATE, try CF_SQL_TIMESTAMP. | Hey Acoder,
I get the error - [Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification
-
-
-
SQL = "exec usp_CS_Insertserial ?, '144', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?"
-
-
Query Parameter Value(s) -
here is what i have - <!---Inserts information into serial table.--->
-
<CFIF REQUEST_METHOD EQ "POST">
-
<CFSET machineListLen = listLen(Form.serialcount)>
-
<CFLOOP from="1" to="#machineListLen#" index="machineCount">
-
<CFSET serialnum = Form["serialnum_" & machineCount]>
-
<CFSET modelno = Form["modelno_" & machineCount]>
-
<CFSET producttype = Form["producttype_" & machineCount]>
-
<CFSET softhardware = Form["softhardware_" & machineCount]>
-
<CFSET resolution = Form["resolution_" & machineCount]>
-
<CFSET resdate = Form["resdate_" & machineCount]>
-
<CFSET resvertified = Form["resvertified_" & machineCount]>
-
<CFSET vertifidate = Form["vertifidate_" & machineCount]>
-
<CFSET deptvendor = Form["deptvendor_" & machinecount]>
-
<CFSET hardwarefailure = Form["hardwarefailure_" & machineCount]>
-
<CFSET rma = Form["rma_" & machineCount]>
-
<CFSET thedescription = Form["thedescription_" & machineCount]>
-
-
<cfquery name="serial" datasource="CustomerSupport">
-
exec usp_CS_Insertserial
-
<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_NUMERIC">,
-
'#Form.ID#',
-
<cfqueryparam value="#modelno#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#producttype#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#softhardware#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#resolution#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#resdate#" CFSQLType = "CF_SQL_TIMESTAMP">,
-
<cfqueryparam value="#resvertified#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#vertifidate#" CFSQLType = "CF_SQL_TIMESTAMP">,
-
<cfqueryparam value="#deptvendor#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#hardwarefailure#" CFSQLType = "CF_SQL_VARCHAR">,
-
<cfqueryparam value="#rma#" CFSQLType = "CF_SQL_VARCHAR">
-
</CFQUERY>
-
-
<!---Inserts information into notes_descr table.--->
-
<cfquery name="description" datasource="CustomerSupport">
-
exec usp_CS_Insertdescription
-
<cfqueryparam value="#serialnum#" CFSQLType = "CF_SQL_VARCHAR">,
-
'#Form.ID#',
-
<cfqueryparam value="#thedescription#" CFSQLType = "CF_SQL_VARCHAR">,
-
'#Form.fk_addedBy#'
-
</cfquery>
-
-
</CFLOOP>
-
</CFIF>
Thank you,
Rach
| 
October 8th, 2008, 02:50 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
What type are the two date fields and what are some example input values?
Also check the database to see how the values are stored.
PS. If you remember, I mentioned in an earlier thread about using cfstoredproc/cfprocparam instead of cfquery/cfqueryparam for stored procedures.
| 
October 8th, 2008, 03:10 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder What type are the two date fields and what are some example input values?
Also check the database to see how the values are stored.
PS. If you remember, I mentioned in an earlier thread about using cfstoredproc/cfprocparam instead of cfquery/cfqueryparam for stored procedures. | Hey Acoder,
Here is how it displays the date
2008-09-23 00:00:00.
Do i need to do the cfstoredproc/cfprocparam instead?
Thank you,
Rach
| 
October 8th, 2008, 04:39 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
How is it stored in the database? Do you know the exact type?
This may actually be a part-SQL Server question that you might want to ask in the SQL Server forum if the experts there have some tips.
Changing to cfstoredproc may not solve the problem, but it would make sense to anyway.
| 
October 8th, 2008, 04:50 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder How is it stored in the database? Do you know the exact type?
This may actually be a part-SQL Server question that you might want to ask in the SQL Server forum if the experts there have some tips.
Changing to cfstoredproc may not solve the problem, but it would make sense to anyway. | Hey Acoder,
This is how it is stored in the database
1/1/1900 12:00:00 AM
the exact type is datetime.
Thank you,
Rach
| 
October 8th, 2008, 06:02 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
Did you have it working before without the quotes?
If so, for a test, remove the cfsqltype for the two date files, e.g. - <cfqueryparam value="#resdate#">,
| 
October 8th, 2008, 06:40 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder Did you have it working before without the quotes?
If so, for a test, remove the cfsqltype for the two date files, e.g. - <cfqueryparam value="#resdate#">,
| Hey Acoder,
That was it, It works! Thank you so much for all the help, your awesome!!!
Thank you again!
Rach
| 
October 8th, 2008, 09:06 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
Well, I never...
If you aren't doing already, you should validate the input going into the database.
Anyway, glad it's now working.
| 
October 8th, 2008, 09:38 PM
| | Site Addict | | Join Date: Aug 2008 Location: United States
Posts: 769
| | | re: Allow single quote in query Quote: |
Originally Posted by acoder Well, I never...
If you aren't doing already, you should validate the input going into the database.
Anyway, glad it's now working. | Hey Acoder,
Yes it is definitely weird. I even read up on it an according to them (adobe) the date one should of worked. The only thing i can think of is when users submit a date they submit it like this 10/08/2008. But when it goes into the database its 10/08/2008 12:00:00am.So that could of been it. But thank you again for all the help :),
Rach
| 
October 9th, 2008, 08:11 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,528
Provided Answers: 12 | | | re: Allow single quote in query
If you're using the timestamp type, I think that format wouldn't work. You'd probably need 10-08-2008 or something. Consult the SQL Server documentation for that. Are you using CreateODBCDateTime() to convert it?
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,720 network members.
|