Skip navigation
Oregon Will
Currently Being Moderated

cfqueryparam truncates values even when scale is specified

May 2, 2012 11:42 AM

Tags: #scale #coldfusion_9 #cfqueryparam #cf_sql_decimal

I'm connecting ColdFusion 9.0.1 with MySQL 5.5 using the MySQL 5.1 ODBC connector. I have a table with a field defined as DECIMAL(11,2) intended to store currency amounts.

 

When I use <cfqueryparam cfsqltype="cf_sql_decimal" scale="2" value="#nValue#"> to insert a value in that field, the value stored in the parameter (when I show debug output on the parameters after the query is run) is correct and not truncated, but the value stored in MySQL is truncated (not rounded).

 

I know this is probably a driver issue, but I'm hoping that this forum will be able to help me troubleshoot the problem.

 
Replies
  • Currently Being Moderated
    May 2, 2012 6:42 PM   in reply to Oregon Will

    I rarely use ODBC anymore. But it works as expected with a jdbc connection. This inserts "11.57":

     

                          <cfqueryparam cfsqltype="cf_sql_decimal" scale="2" value="11.565">

     

    Aside from switching to jdbc

     

    1) Can you dump the generated sql? What is the value of #nValue# and the actual value inserted into the table?

     

    2) It should not make a difference, but any change if you temporarily use hard coded values? ie INSERT INTO ... VALUES (11.56) OR use cf_sql_numeric?

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2012 8:28 AM   in reply to Oregon Will

    Oregon Will wrote:

     

    I'm connecting ColdFusion 9.0.1 with MySQL 5.5 using the MySQL 5.1 ODBC connector. I have a table with a field defined as DECIMAL(11,2) intended to store currency amounts.

     

    When I use <cfqueryparam cfsqltype="cf_sql_decimal" scale="2" value="#nValue#"> to insert a value in that field, the value stored in the parameter (when I show debug output on the parameters after the query is run) is correct and not truncated, but the value stored in MySQL is truncated (not rounded).

    What is the value? How is it truncated?

     
    |
    Mark as:
  • Currently Being Moderated
    May 9, 2012 11:58 PM   in reply to Oregon Will

    The issue arises perhaps from incorrect syntax. Try this:

     

    <cfquery datasource="telcomm" name="insert_leftover_adj">

    INSERT INTO bill_warehouse(keyBill,keyBillItem,keyProgram,nAmount,sDescription)

    VALUES(<cfqueryparam cfsqltype="cf_sql_integer" value="#Bill.keyBill#">,

       <cfqueryparam cfsqltype="cf_sql_integer" value="#qryPoolItem.keyBillItem#">,

       #keyProgramTech#,

       <cfqueryparam cfsqltype="cf_sql_decimal" scale="2" value="#qryLeftover.nPool#">,

       'Adjustment ...'

    </cfquery>

     
    |
    Mark as:
  • Currently Being Moderated
    May 10, 2012 7:28 AM   in reply to Oregon Will

    Oregon Will wrote:

     

    The INSERT INTO...SET syntax may not be standard, but it is valid syntax for MySQL. I use the INSERT INTO...SET syntax because it is much easier to read, much easier to make sure that the field-value assignments are correct. Notice that the query works fine when the parameter is passed in with cfsqltype="cf_sql_double" and when the value is hard-coded.

    Sorry. No need to explain. I should have said non-standard instead of incorrect. The question remains: does the version with standard SQL work? If so, then we will only have to look into why the MySQL syntax leads to truncation. 

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points