Hello

My udf function (inet_aton functionality for 3.21.33 server) does work in 99%
percent of all cases, just when I use it on the output of a outer join
where some fields are NULL it crashes the server - when giving NULL as 
argument directly it works:

result of a join of 2 very simple tables (a,b are int; c is char):
+------+------+------+---------+
| a    | b    | a    | c       |
+------+------+------+---------+
|    1 |    1 | NULL | NULL    |
... 
mysql> select *,ewu_aton(NULL) from a left outer join c using (a);
ERROR: Wrong arguments to ewu_aton;  Use the source!
mysql> select *,ewu_aton(c) from a left outer join c using (a);
ERROR 2013: Lost connection to MySQL server during query

How does this come? In a INT_RESULT function I even have no  change to
do errors with malloc etc...

bye,

 -christian-

my_bool ewu_aton_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
  unsigned int  a,b,c,d;

  if (args->arg_count != 1 ||
      args->arg_type[0] != STRING_RESULT ||
      args->lengths[0] < 1 ||
      args->lengths[0] > 15) {
        strcpy(message,"Wrong arguments to ewu_aton;  Use the source!");
        return 1;
  }
  if (sscanf(args->args[0], "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
        strcpy(message,"This is not a dotted-quad IP;  Use the source!");
        return 1;
  }
  if (a>255 || b>255 || c>255 || d>255) {
        strcpy(message,"Invalid IP number;  Use the source!");
        return 1;
  }
  initid->maybe_null=0;
  return 0;
}
long long ewu_aton(UDF_INIT *initid, UDF_ARGS *args,
                   char *is_null, char *error)
{
  unsigned int          a,b,c,d;

  if (sscanf(args->args[0], "%u.%u.%u.%u", &a, &b, &c, &d) != 4) {
        /* cannot happen - init checks this...?! */
        *is_null=1;
        *error=1;
        return 0;
  }

  *is_null=0;
  *error=0;
  return (long unsigned int)( a*0x01000000 + b*0x00010000 + c*0x00000100 + d);
}


-- 
Christian Hammers    WESTEND GmbH - Aachen und Dueren     Tel 0241/701333-0
[EMAIL PROTECTED]     Internet & Security for Professionals    Fax 0241/911879
           WESTEND ist CISCO Systems Partner - Premium Certified

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to