dbTalk Databases Forums  

Stored procedure unknown arguments

comp.databases.sybase comp.databases.sybase


Discuss Stored procedure unknown arguments in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ed Avis
 
Posts: n/a

Default Stored procedure unknown arguments - 05-12-2004 , 03:24 AM






How can I get Sybase to print a warning or error when an unknown
argument is given to a stored procedure?

Quote:
create procedure foo @a int as print "hello"
go

foo @a = 44
go
hello
(return status = 0)

Quote:
foo
go
Msg 201, Level 16, State 2
Server 'TEST_LN', Procedure 'foo'
Procedure foo expects parameter @a, which was not supplied.
(return status = -6)

Okay so far - if I leave out the parameter @a then it gives an error.
But if I specify a nonexistent parameter it silently ignores it:

Quote:
foo @a = 44, @b = 44
go
hello
(return status = 0)

Can I make Sybase warn about bad parameters? I'm using 11.9.2 with
OCS 12.5.

--
Ed Avis <ed (AT) membled (DOT) com>



Reply With Quote
  #2  
Old   
Michael Peppler
 
Posts: n/a

Default Re: Stored procedure unknown arguments - 05-12-2004 , 04:03 AM






On Wed, 12 May 2004 09:24:50 +0100, Ed Avis wrote:

Quote:
How can I get Sybase to print a warning or error when an unknown argument
is given to a stored procedure?

Okay so far - if I leave out the parameter @a then it gives an error. But
if I specify a nonexistent parameter it silently ignores it:

foo @a = 44, @b = 44
go
hello
(return status = 0)

Can I make Sybase warn about bad parameters? I'm using 11.9.2 with OCS
12.5.
You can't (AFAIK). Sybase will simply silently ignore any additional
parameters that are supplied.

Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler (AT) peppler (DOT) org http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.peppler.org/resume.html



Reply With Quote
  #3  
Old   
Carl Kayser
 
Posts: n/a

Default Re: Stored procedure unknown arguments - 05-12-2004 , 05:39 AM



Add on an additional argument with a default of NULL and check it at the
beginning of your code. I had an sp_add num1, .....[num12]]]]]] proc which
would add and comma-format the sum. If someone ever used it with more than
12 arguments they would get an incorrect result. So I used this technique
of first checking that the 13th numeric argument was NULL.

"Ed Avis" <ed (AT) membled (DOT) com> wrote

Quote:
How can I get Sybase to print a warning or error when an unknown
argument is given to a stored procedure?

create procedure foo @a int as print "hello"
go

foo @a = 44
go
hello
(return status = 0)

foo
go
Msg 201, Level 16, State 2
Server 'TEST_LN', Procedure 'foo'
Procedure foo expects parameter @a, which was not supplied.
(return status = -6)

Okay so far - if I leave out the parameter @a then it gives an error.
But if I specify a nonexistent parameter it silently ignores it:

foo @a = 44, @b = 44
go
hello
(return status = 0)

Can I make Sybase warn about bad parameters? I'm using 11.9.2 with
OCS 12.5.

--
Ed Avis <ed (AT) membled (DOT) com




Reply With Quote
  #4  
Old   
Larry Coon
 
Posts: n/a

Default Re: Stored procedure unknown arguments - 05-12-2004 , 12:36 PM



Michael Peppler wrote:

Quote:
You can't (AFAIK). Sybase will simply silently ignore any additional
parameters that are supplied.
You can kludge it. For example, if your proc expects only
one parameter:

create procedure sp_myproc
@param1 varchar(255),
@param2 varchar(255) = null
as
if @param2 is not null
begin
print "Too many parameters"
return -1
end

-- etc...
return


Reply With Quote
  #5  
Old   
Michael Peppler
 
Posts: n/a

Default Re: Stored procedure unknown arguments - 05-12-2004 , 12:45 PM



On Wed, 12 May 2004 10:36:55 -0700, Larry Coon wrote:

Quote:
Michael Peppler wrote:

You can't (AFAIK). Sybase will simply silently ignore any additional
parameters that are supplied.

You can kludge it. For example, if your proc expects only one parameter:

create procedure sp_myproc
@param1 varchar(255),
@param2 varchar(255) = null
as
if @param2 is not null
begin
print "Too many parameters"
return -1
end
But that doesn't work with named parameters.

I can call the above with

exec sp_myproc @param1 = 'foo', @bar = 'baz'

and not get an error...

Michael
--
Michael Peppler Data Migrations, Inc.
mpeppler (AT) peppler (DOT) org http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or
long term contract positions - http://www.peppler.org/resume.html



Reply With Quote
  #6  
Old   
Larry Coon
 
Posts: n/a

Default Re: Stored procedure unknown arguments - 05-12-2004 , 06:10 PM



Michael Peppler wrote:

Quote:
But that doesn't work with named parameters.
Good point.


Reply With Quote
  #7  
Old   
Bret Halford
 
Posts: n/a

Default Re: Stored procedure unknown arguments - 05-13-2004 , 11:39 AM



Larry Coon <lcnospam (AT) assist (DOT) org> wrote

Quote:
Michael Peppler wrote:

But that doesn't work with named parameters.

Good point.
There is an open CR on this issue, 292153.
It may get addressed in 15.0.

-bret


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.