From: clubley@remove_me.eisner.decus.org-Earth.UFP   
      
   On 2025-08-12, Arne Vajhøj wrote:   
   > Code:   
   >   
   > #include    
   >   
   > #include    
   >   
   > my_bool demo_init(UDF_INIT *initid, UDF_ARGS *args, char *message)   
   > {   
   > if(args->arg_count == 2 && args->arg_type[0] == STRING_RESULT &&   
   > args->arg_type[1] == INT_RESULT)   
      
   Is it guaranteed that arg_type[] will always have at least elements ?   
   If not, that's dangerous unless the compiler you are using does   
   expression short-circuiting.   
      
   > {   
   > return 0;   
   > }   
   > else   
   > {   
   > strcpy(message, "demo function requires two arguments: one   
   > string and one integer");   
   > return 1;   
      
   YUCK!!! :-) Does MySQL provide a maximum error message size field or   
   constant that you can use with strncpy() instead ?   
      
   > }   
   > }   
   >   
   > long long demo(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned   
   > long *length, unsigned char *is_null, unsigned char *error)   
   > {   
   > const char *sv = args->args[0];   
   > long long iv = *((long long *)args->args[1]);   
   > return strlen(sv) + iv;   
   > }   
   >   
   > void demo_deinit(UDF_INIT *initid)   
   > {   
   > }   
   >   
   > Build:   
   >   
   > $ cc /include=mysql055_root:[include.mysql] /names=as_is demo.c   
   > $ link/share=demo_shr.exe demo + sys$input/opt   
   > mysql055_root:[lib.alpha]libclientlib/lib   
   > mysql055_root:[lib.alpha]libsql/lib   
   > mysql055_root:[lib.alpha]libmysys/lib   
   > mysql055_root:[lib.alpha]libdbug/lib   
   > mysql055_root:[lib.alpha]libstrings/lib   
   > mysql055_root:[lib.alpha]libvio/lib   
   > mysql055_root:[lib.alpha]libz/lib   
   > mysql055_root:[lib.alpha]ssl_libssl32/lib   
   > mysql055_root:[lib.alpha]ssl_libcrypto32/lib   
   > CASE_SENSITIVE=YES   
   > SYMBOL_VECTOR=(demo_init=PROCEDURE, -   
   > demo=PROCEDURE, -   
   > demo_deinit=PROCEDURE)   
   > $   
   >   
   > Install (DCL):   
   >   
   > $ copy/log demo_shr.exe mysql055_root:[plugin.alpha]*.*   
   > $ def/sys demo_shr   
   > "''f$parse("mysql055_root:[plugin.alpha]demo_shr.exe",,,,"NO_CONCEAL")'"   
   >   
   > Install (SQL):   
   >   
   > CREATE FUNCTION demo   
   > RETURNS INTEGER   
   > SONAME 'demo_shr';   
   >   
   > Demo:   
   >   
   > MariaDB [test]> select demo('ABC', 1);   
   > +----------------+   
   >| demo('ABC', 1) |   
   > +----------------+   
   >| 4 |   
   > +----------------+   
   > 1 row in set (0.01 sec)   
   >   
   > MariaDB [test]> select demo('ABCD', 1);   
   > +-----------------+   
   >| demo('ABCD', 1) |   
   > +-----------------+   
   >| 5 |   
   > +-----------------+   
   > 1 row in set (0.00 sec)   
   >   
   > MariaDB [test]> select demo('ABC', 2);   
   > +----------------+   
   >| demo('ABC', 2) |   
   > +----------------+   
   >| 5 |   
   > +----------------+   
   > 1 row in set (0.00 sec)   
   >   
   > MariaDB [test]> SELECT demo();   
   > ERROR 1123 (HY000): Can't initialize function 'demo'; demo function   
   > requires two arguments: one string and one integer   
   > MariaDB [test]> SELECT demo('ABC');   
   > ERROR 1123 (HY000): Can't initialize function 'demo'; demo function   
   > requires two arguments: one string and one integer   
   > MariaDB [test]> SELECT demo('ABC', 'DEF');   
   > ERROR 1123 (HY000): Can't initialize function 'demo'; demo function   
   > requires two arguments: one string and one integer   
   > MariaDB [test]> SELECT demo('ABC', 1, 1);   
   > ERROR 1123 (HY000): Can't initialize function 'demo'; demo function   
   > requires two arguments: one string and one integer   
   >   
   > Arne   
   >   
      
      
   --   
   Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP   
   Walking destinations on a map are further away than they appear.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|