0
error executing database query: too few parameters

/t5/coldfusion-discussions/error-executing-database-query-too-few-parameters/td-p/568222
Nov 28, 2007
Nov 28, 2007
Copy link to clipboard
Copied
Hi, I am having trouble with this error message - have used
similar code before without any problems (I'm pretty new to
coldfusion)
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
The error occurred in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\CFIDE\collinsvillerealestate\buypropertyresults.cfm: line 36
34 : <!---search by price range --->
35 : <cfif FORM.price IS NOT "">
36 : AND [price] <= #FORM.price#
37 : </cfif>
38 :
--------------------------------------------------------------------------------
SQLSTATE 07002
SQL SELECT shortDescription, propertyID, price, numberOfBedrooms, numberOfBathrooms, numberOfCarports, locationID, imageNameOne, categoryID, longDescritpionOne FROM propertiesForSale WHERE 0=0 AND locationID = 1 AND categoryID = 1 AND numberOfBedrooms = 2 AND [price] <= 300000 ORDER BY propertyID
VENDORERRORCODE -3010
DATASOURCE collinsvillerealestate
___________________________________________
My code is:
<cfquery datasource="collinsvillerealestate" name="properties">
SELECT shortDescription, propertyID, price, numberOfBedrooms,
numberOfBathrooms, numberOfCarports, locationID, imageNameOne,
categoryID, longDescritpionOne
FROM propertiesForSale
WHERE 0=0
<!---search by location --->
<cfif FORM.locationID IS NOT "">
AND locationID = #FORM.locationID#
</cfif>
<!---search by category--->
<cfif FORM.categoryID IS NOT "">
AND categoryID = #FORM.categoryID#
</cfif>
<!---search by number of bedrooms --->
<cfif FORM.numberOfBedrooms IS NOT "">
AND numberOfBedrooms = #FORM.numberOfBedrooms#
</cfif>
<!---search by price range --->
<cfif FORM.price IS NOT "">
AND price <= #FORM.price#
</cfif>
ORDER BY propertyID
</cfquery>
Have tried removing and fiddling with statement, but error message applies to all parts of the statement.
Thanks
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
The error occurred in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\CFIDE\collinsvillerealestate\buypropertyresults.cfm: line 36
34 : <!---search by price range --->
35 : <cfif FORM.price IS NOT "">
36 : AND [price] <= #FORM.price#
37 : </cfif>
38 :
--------------------------------------------------------------------------------
SQLSTATE 07002
SQL SELECT shortDescription, propertyID, price, numberOfBedrooms, numberOfBathrooms, numberOfCarports, locationID, imageNameOne, categoryID, longDescritpionOne FROM propertiesForSale WHERE 0=0 AND locationID = 1 AND categoryID = 1 AND numberOfBedrooms = 2 AND [price] <= 300000 ORDER BY propertyID
VENDORERRORCODE -3010
DATASOURCE collinsvillerealestate
___________________________________________
My code is:
<cfquery datasource="collinsvillerealestate" name="properties">
SELECT shortDescription, propertyID, price, numberOfBedrooms,
numberOfBathrooms, numberOfCarports, locationID, imageNameOne,
categoryID, longDescritpionOne
FROM propertiesForSale
WHERE 0=0
<!---search by location --->
<cfif FORM.locationID IS NOT "">
AND locationID = #FORM.locationID#
</cfif>
<!---search by category--->
<cfif FORM.categoryID IS NOT "">
AND categoryID = #FORM.categoryID#
</cfif>
<!---search by number of bedrooms --->
<cfif FORM.numberOfBedrooms IS NOT "">
AND numberOfBedrooms = #FORM.numberOfBedrooms#
</cfif>
<!---search by price range --->
<cfif FORM.price IS NOT "">
AND price <= #FORM.price#
</cfif>
ORDER BY propertyID
</cfquery>
Have tried removing and fiddling with statement, but error message applies to all parts of the statement.
Thanks
TOPICS
Database access
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Guide
,
/t5/coldfusion-discussions/error-executing-database-query-too-few-parameters/m-p/568223#M52290
Nov 28, 2007
Nov 28, 2007
Copy link to clipboard
Copied
Does the query run successfully if you omit all of the
parameters?
<cfquery datasource="collinsvillerealestate" name="properties">
SELECT shortDescription, propertyID, price, numberOfBedrooms,
numberOfBathrooms, numberOfCarports, locationID, imageNameOne,
categoryID, longDescritpionOne
FROM propertiesForSale
WHERE 0=0
ORDER BY propertyID
</cfquery>
If it works, start adding back the form field parameters one at a time. See which one causes the error. But you should use cfqueryparam for all form fields.
Also use a check that's appropriate for the values. For example, if the locationID value must be numeric then use IsNumeric(FORM.locationID) instead of testing for an empty value ""
<!---
The correct cfsqltype depends on the data type of your column. For a "text" column use "cf_sql_varchar" for "number" (long integer) use "cf_sql_integer", etc..
--->
<cfif IsNumeric(FORM.locationID)>
<cfqueryparam value="#FORM.locationID#" cfsqltype="cf_sql_integer">
</cfif>
<cfquery datasource="collinsvillerealestate" name="properties">
SELECT shortDescription, propertyID, price, numberOfBedrooms,
numberOfBathrooms, numberOfCarports, locationID, imageNameOne,
categoryID, longDescritpionOne
FROM propertiesForSale
WHERE 0=0
ORDER BY propertyID
</cfquery>
If it works, start adding back the form field parameters one at a time. See which one causes the error. But you should use cfqueryparam for all form fields.
Also use a check that's appropriate for the values. For example, if the locationID value must be numeric then use IsNumeric(FORM.locationID) instead of testing for an empty value ""
<!---
The correct cfsqltype depends on the data type of your column. For a "text" column use "cf_sql_varchar" for "number" (long integer) use "cf_sql_integer", etc..
--->
<cfif IsNumeric(FORM.locationID)>
<cfqueryparam value="#FORM.locationID#" cfsqltype="cf_sql_integer">
</cfif>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Engaged
,
/t5/coldfusion-discussions/error-executing-database-query-too-few-parameters/m-p/568224#M52291
Nov 29, 2007
Nov 29, 2007
Copy link to clipboard
Copied
WHERE 0=0
What is this? a typo? as far as I know you can't have a DB field with a number only as name.
Sometimes errors say they are thrownn in one spot in the debugging, but was actually a bit prior. This statement seems completely odd in the query.
What is this? a typo? as far as I know you can't have a DB field with a number only as name.
Sometimes errors say they are thrownn in one spot in the debugging, but was actually a bit prior. This statement seems completely odd in the query.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Mentor
,
LATEST
/t5/coldfusion-discussions/error-executing-database-query-too-few-parameters/m-p/568226#M52293
Nov 29, 2007
Nov 29, 2007
Copy link to clipboard
Copied
This WHERE 0=0 is commonly used where you have a dynamic
query using AND clauses within CFIF tags, and none may be "true".
In other words, if none of the CFIF statements are true, then WHERE
0=0 is always true and will return all rows. When using OR clauses
in your query, then WHERE 1=0 could be used to make sure that no
rows are returned unless at least one OR existed.
Phil
Phil
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/coldfusion-discussions/error-executing-database-query-too-few-parameters/m-p/568225#M52292
Nov 29, 2007
Nov 29, 2007
Copy link to clipboard
Copied
I think the 0=0 is a check that will always be true. I've
used 1=1 before. It just says this is true continue, then you are
free to use AND or OR's, etc.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

