From: Hugh W. <hwi...@op...> - 2012-11-13 13:30:17
|
Hi Quentin, If you create the procedure via isql it does actually warn you about the incompatible assign (unless the type is defined as ANY), thus action should be taken at that point to make them compatible for use down the line: SQL> create procedure Type the rest of statement, end with a semicolon (;)> DB.q.testBug() returns varchar Type the rest of statement, end with a semicolon (;)> { Type the rest of statement, end with a semicolon (;)> declare str varchar; Type the rest of statement, end with a semicolon (;)> declare intIn int; Type the rest of statement, end with a semicolon (;)> Type the rest of statement, end with a semicolon (;)> intIn := 4; Type the rest of statement, end with a semicolon (;)> str := intIn; Type the rest of statement, end with a semicolon (;)> Type the rest of statement, end with a semicolon (;)> return concat('test:',str,'.'); Type the rest of statement, end with a semicolon (;)> }; Warning 01V01: [Virtuoso Driver][Virtuoso Server]QW004: Incompatible types VARCHAR (182) and INTEGER (189) in := for str and intIn in lines 22-32 of Top-Level: #line 22 "(console)" create procedure DB.q.testBug() returns varchar { declare str varchar; declare intIn int; intIn := 4; str := intIn; return concat('test:',str,'.'); } Done. -- 31 msec. SQL> So the behaviour is by design ... Best Regards Hugh Williams Professional Services OpenLink Software, Inc. // http://www.openlinksw.com/ Weblog -- http://www.openlinksw.com/blogs/ LinkedIn -- http://www.linkedin.com/company/openlink-software/ Twitter -- http://twitter.com/OpenLink Google+ -- http://plus.google.com/100570109519069333827/ Facebook -- http://www.facebook.com/OpenLinkSoftware Universal Data Access, Integration, and Management Technology Providers On 13 Nov 2012, at 05:30, Quentin wrote: > The problem is that the variable "str" is declared as type varchar but has become an integer by the time of the concat. If we're being strict then the assignment ought not to have succeeded (which would be straight forward to debug) but instead, it has silently changed type to integer which can be quite difficult to debug because many lines of code later, it gets used in something that expects strict types. > > In my first example, the call to concat is (as far as a programmer can tell at design time) concat(literal varchar, variable varchar, literal varchar). In my contrived example the source is clear but consider a (slightly) more complicated example like: > ========================== > DB.q.outerFunc(in data ANY) returns varchar > { > declare str varchar; > str := data; > return DB.q.innerFunc(str); > } > > DB.q.innerFunc(in str VARCHAR) returns varchar > { > return concat('test:',str,'.'); > } > ========================== > SELECT DB.q.outerFunc(1); > Message: SR007: Function concat needs a string or UNAME or NULL as argument 2, not an arg of type INTEGER (189) > ========================== > > I don't have to imagine trying to debug this because I spent last Wednesday debugging something like this. Our fault of course but not made easier by weak typing on variables combined with strict typing on parameters. > > I would expect that the error in the above code is in outerFunc but it actually occurs in innerFunc which is merely executing concat on varchars. > > Is this by design? > > > On 13 November 2012 16:18, Hugh Williams <hwi...@op...> wrote: > Hi Quentin, > > The error is saying you are trying to concat and integer when a strings is expected, thus the integer should be cast as varchar for it to work: > > create procedure > DB.q.testBug() returns varchar > { > declare str varchar; > declare intIn int; > > intIn := cast (4 as varchar); > str := intIn; > > return concat('test:',str,'.'); > } > > You could argue that concat could implicitly perform the cast I suppose, but it is strictly enforcing the type it would seem ... > > In what way is this a problem for you ? > > Best Regards > Hugh Williams > Professional Services > OpenLink Software, Inc. // http://www.openlinksw.com/ > Weblog -- http://www.openlinksw.com/blogs/ > LinkedIn -- http://www.linkedin.com/company/openlink-software/ > Twitter -- http://twitter.com/OpenLink > Google+ -- http://plus.google.com/100570109519069333827/ > Facebook -- http://www.facebook.com/OpenLinkSoftware > Universal Data Access, Integration, and Management Technology Providers > > On 13 Nov 2012, at 01:53, Quentin wrote: > >> Is this a bug? It doesn't seem desirable behaviour. >> >> ============================= >> create procedure >> DB.q.testBug() returns varchar >> { >> declare str varchar; >> declare intIn int; >> >> intIn := 4; >> str := intIn; >> >> return concat('test:',str,'.'); >> } >> ============================= >> >> In isql: >> ============================= >> select DB.q.testBug(); >> ============================= >> Query result: >> testBug >> VARCHAR >> SQLState: 22023 >> Message: SR007: Function concat needs a string or UNAME or NULL as argument 2, not an arg of type INTEGER (189) >> ============================= >> >> I would (perhaps naively) expect that the error should be in the uncast assignment if we are being strictly typed or implicitly cast the variable to varchar on assignment if we want to be weakly typed. >> >> -- >> Quentin | Clear Blue Water Pty Ltd >> que...@cl... >> ------------------------------------------------------------------------------ >> Monitor your physical, virtual and cloud infrastructure from a single >> web console. Get in-depth insight into apps, servers, databases, vmware, >> SAP, cloud infrastructure, etc. Download 30-day Free Trial. >> Pricing starts from $795 for 25 servers or applications! >> http://p.sf.net/sfu/zoho_dev2dev_nov_______________________________________________ >> Virtuoso-users mailing list >> Vir...@li... >> https://lists.sourceforge.net/lists/listinfo/virtuoso-users > > > > > -- > Quentin | Clear Blue Water Pty Ltd > que...@cl... |