[FIXED] Oracle Sproc woes

Posts   
 
    
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 08-Mar-2004 11:08:38   

I've been trying trying to use an action stored proc with some difficulty. The stored proc in the db looks like this:

CREATE OR REPLACE  PROCEDURE "CAP13TEST"."GET_LTLKEY_NUMBER"  (
    what_counter IN VARCHAR2, next_number OUT NUMBER) AS

  temp_number NUMBER;

BEGIN
  SELECT SYSCOUNT_VAL
  INTO temp_number
  FROM SYSCOUNTER
  WHERE SYSCOUNT_TAB = what_counter
  FOR UPDATE NOWAIT;

  temp_number := temp_number + 1;

  UPDATE SYSCOUNTER
  SET SYSCOUNT_VAL = temp_number
  WHERE SYSCOUNT_TAB = what_counter;
  next_number := temp_number;

  COMMIT;

END;

Nothing much to it... but it results in an action proc which looks like this:

        public static int GET_LTLKEY_NUMBER(System.String wHAT_COUNTER, ref System.Int16 nEXT_NUMBER, DataAccessAdapter adapter)
        {
            // create parameters
            OracleParameter[] parameters = new OracleParameter[2];
            parameters[0] = new OracleParameter("WHAT_COUNTER", OracleDbType.Varchar2, 4000, ParameterDirection.Input, true, 0, 0, "",  DataRowVersion.Current, wHAT_COUNTER);
            parameters[1] = new OracleParameter("NEXT_NUMBER", OracleDbType.Decimal, 0, ParameterDirection.Output, true, 0, 0, "",  DataRowVersion.Current, nEXT_NUMBER);
            // Call the stored proc.
            int toReturn = adapter.CallActionStoredProcedure("GET_LTLKEY_NUMBER", parameters);
            if(parameters[1].Value!=System.DBNull.Value)
            {
                nEXT_NUMBER = (System.Int16)parameters[1].Value;
            }
            return toReturn;
        }

the initial error message i got told me that the precision value for the NEXT_NUMBER param was out of range, that it had to be between 1 and 38. So i changed that to 38 but then i started getting invalid cast errors. Anyway, to cut a long story short (ish) i had to change the NEXT_NUMBER params to Int32, e.g.

        public static int GET_LTLKEY_NUMBER(System.String wHAT_COUNTER, ref System.Int32 nEXT_NUMBER, DataAccessAdapter adapter)
        {
            // create parameters
            OracleParameter[] parameters = new OracleParameter[2];
            parameters[0] = new OracleParameter("WHAT_COUNTER", OracleDbType.Varchar2, 4000, ParameterDirection.Input, true, 0, 0, "",  DataRowVersion.Current, wHAT_COUNTER);
            parameters[1] = new OracleParameter("NEXT_NUMBER", OracleDbType.Int32, 0, ParameterDirection.Output, true, 38, 0, "",  DataRowVersion.Current, nEXT_NUMBER);
            // Call the stored proc.
            int toReturn = adapter.CallActionStoredProcedure("GET_LTLKEY_NUMBER", parameters);
            if(parameters[1].Value!=System.DBNull.Value)
            {
                nEXT_NUMBER = (System.Int32)parameters[1].Value;
            }
            return toReturn;
        }

and now all seems well simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 08-Mar-2004 13:11:29   

I think you can solve this by specifying a precision with NUMBER. Default this is 1 if I'm not mistaken. (which thus results in an Int16. If you want to specify a precision of 5 for example, you should change the NUMBER specification in the stored proc header to NUMBER(5), or not?

Please correct me if I'm wrong.

Frans Bouma | Lead developer LLBLGen Pro
netclectic avatar
netclectic
User
Posts: 255
Joined: 28-Jan-2004
# Posted on: 08-Mar-2004 13:18:03   

This is true, but NUMBER without a precision should default to NUMBER(3sunglasses, not NUMBER(0).

[edit] "Default this is 1 if I'm not mistaken" i must learn to read properly... no, default is 38.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39897
Joined: 17-Aug-2003
# Posted on: 08-Mar-2004 13:58:48   

Ok.

I'll patch this in the driver which is shipped with the update released later today.

Btw, if I set it to default 38, the type of the .NET parameter representing the stored proc parameter will by System.Decimal.

Edit2: The official 9i docs confirm this: if no precision is specified, precision should be considered 38. This is thus also true for table fields and view fields.

Frans Bouma | Lead developer LLBLGen Pro