#include <mysql.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

my_bool test_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
long long test(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
void test_deinit(UDF_INIT *initid);

#ifdef __cplusplus
}
#endif

my_bool test_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
{
     if (args->arg_count != 1) {
        strcpy(message, "test() requires exactly 1 argument");
        return 1; // Return 1 indicates an error
    }

    if (args->arg_type[0] != INT_RESULT) {
        strcpy(message, "test() argument must be an integer");
        return 1;
    }

    initid->max_length = 0; /* this will be replaced by MariaDB server (=MAX_BLOB_SIZE)*/
    initid->maybe_null = 0;

    return 0;
}

long long test(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
{
    long long input_val = *((long long*) args->args[0]);

    /* Perform our simple operation (increment by 1) */
    long long result = input_val + 1;

    return result;
}

void test_deinit(UDF_INIT *initid)
{
  /* Nothing to do here */
}
