Problem with output param

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Problem with output param

    I've been beating my head against this one, and there's probably some simple
    problem that I just keep overlooking.

    I have a stored proc to perform an insert (SQL Server), and there's an output
    parameter that is set to the identity from the new row (scope_identity()).
    Standard stuff, working in Query Analyser perfectly.

    I then have a CFSTOREDPROC tag set to call that procedure, and to put the
    output parameter into a variable. I've done this a few times without incident,
    but this time, I get an error that the identity value is not an integer, and if
    I output the value to the page, it indeed displays as a series of "square box"
    characters rather than the number. I am stumped. Other similar procedures work
    with the same design.

    I imagine I'm just overlooking some obvious syntax error. Anyone see the
    problem?

    <cfstoredproc procedure="addLostPropReq" returncode="no"
    datasource="YardiTracking" debug="no">
    <cfprocparam type="in" dbvarname=@db cfsqltype="cf_sql_varchar"
    value="#form.db#">
    <cfprocparam type="in" dbvarname=@propcode cfsqltype="cf_sql_char"
    value="#form.propcode#">
    <cfprocparam type="in" dbvarname=@propname cfsqltype="cf_sql_varchar"
    value="#form.propname#">
    <cfprocparam type="in" dbvarname=@datelost cfsqltype="cf_sql_timestamp"
    value="#form.datelost#">
    <cfprocparam type="in" dbvarname=@submittedby cfsqltype="cf_sql_varchar"
    value="#form.submittedby#">
    <cfprocparam type="in" dbvarname=@notes cfsqltype="cf_sql_varchar"
    value="#form.notes#">

    <cfprocparam type="out" dbvarname=@reqID cfsqltype="cf_sql_integer"
    variable="newreqid">
    </cfstoredproc>

    <cfquery name="newReq" datasource="YardiTracking">
    select * from getLostPropReq(
    <cfqueryparam cfsqltype="cf_sql_integer" value="#newreqid#">
    )
    </cfquery>

    and the stored procedure

    CREATE PROCEDURE addLostPropReq

    @db varchar(20),
    @propcode char(8),
    @propname varchar(50),
    @datelost datetime,
    @submittedby varchar(50),
    @notes varchar(512),

    @reqID int output

    AS

    set nocount on

    declare @err int

    insert into lostPropRequests (
    db,
    propcode,
    propname,
    datelost,
    submittedby,
    notes
    ) values (
    @db,
    @propcode,
    @propname,
    @datelost,
    @submittedby,
    @notes
    )

    set @reqID = scope_identity()

    return 0

    merrillaldrich Guest

  2. Similar Questions and Discussions

    1. Problem with getting value in Output param Using ActiveXDll
      Hi Pals, As I am trying to access the ActivexDll function developed in VB from the ASP page, it works smoothly but the output parameter(By Ref ...
    2. Problem with Select output
      Hi I am facing some issues with select query. The values of the columns in one table contains "\n" as a part of the value. So when I execute the...
    3. output param & multiple recordests from stored procedures
      here's my code: my $sth = $dbhSQL->prepare('{call proc(?,?,?)}'); $sth->bind_param(1,"asd"); $sth->bind_param(2,"klm");...
    4. Ruby-dl problem: calling func with param
      Hi, I'm trying out ruby-dl and it looks great. However, I get a seg fault when calling funcs that take parameters. Anyone can spot the problem?...
    5. Problem with IE parsing of PHP output
      Hi, I have a class which write a menu, it works fine with Mozilla and Opera but with IE (6 on XP) got a extrange behaviour. Links works and...
  3. #2

    Default Re: Problem with output param

    This is the error message:

    Error Diagnostic Information
    VALUE

    Invalid data '' for CFSQLTYPE 'CF_SQL_INTEGER'.

    The error occurred while processing an element with a general identifier of
    (CFQUERYPARAM), occupying document position (35:5) to (35:64).



    merrillaldrich Guest

  4. #3

    Default Re: Problem with output param

    The dbvarname values need to be in quotes like: dbvarname="@db".

    HOWEVER, dbvarname is depricated and CF goes by order only! So if the CF
    param order and the SP param order become mismatched, that can cause this.

    Finally, are you always inserting into lostPropRequests?
    What about duplicates?

    You should also definitely initialize @reqID to 0 or a safe value at the top
    of the SP.
    Also, return non-zero if the scope ID was not set for some reason.


    MikerRoo Guest

  5. #4

    Default Re: Problem with output param

    try this...
    set @reqID =@@identity
    reenaroy Guest

  6. #5

    Default Re: Problem with output param

    Thank you for the suggestions -- however, I am confident about using
    scope_identity(), because I have a great many procedures that use that, that
    are all working. It's generally prefered over @@identity in SQL Server 2000 +
    because of @@identity's limitations. Note that the SP works perfectly, and
    returns the right value, in Query Analyser.

    I'll look into the quotation marks thing -- but similarly, I have a whole lot
    of these working and none of them have quotation marks there. I'll also
    initialize @reqid.

    It's really odd. Any other thoughts?



    merrillaldrich Guest

  7. #6

    Default Re: Problem with output param

    I seem to have isolated the problem: parameters in cfstoredproc that use
    type="cf_sql_timestamp" in this old version of cold fusion will somehow hose
    the output parameter. If I use "cf_sql_varchar" instead, the problem magically
    disappears. Odd. But now reproducible :-).



    This works:

    <cfstoredproc procedure="addLostPropReq" returncode="no"
    datasource="YardiTracking" debug="no">
    <cfprocparam type="in" dbvarname=@db cfsqltype="cf_sql_varchar"
    value="#form.db#">
    <cfprocparam type="in" dbvarname=@propcode cfsqltype="cf_sql_char"
    value="#form.propcode#">
    <cfprocparam type="in" dbvarname=@propname cfsqltype="cf_sql_varchar"
    value="#form.propname#">

    <!--- Following is really a date, but is passed as varchar to work around some
    problem with output parameter
    in CFSTOREDPROC --->
    <cfprocparam type="in" dbvarname=@datelost cfsqltype="cf_sql_varchar"
    value="#form.datelost#">

    <cfprocparam type="in" dbvarname=@submittedby cfsqltype="cf_sql_varchar"
    value="#form.submittedby#">
    <cfprocparam type="in" dbvarname=@notes cfsqltype="cf_sql_varchar"
    value="#form.notes#">

    <cfprocparam type="out" dbvarname=@reqID cfsqltype="cf_sql_integer"
    variable="newreqID">
    </cfstoredproc>

    merrillaldrich Guest

  8. #7

    Default Re: Problem with output param

    Good, but you should still quote the dbvarnames in case the code is ever run in later versions of CF.
    MikerRoo Guest

  9. #8

    Default Re: Problem with output param

    Good point, thank you :-)
    merrillaldrich Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139