>>>>> "Michael" == Michael Farr <farrm@stripped>
> writes:
<cut>
Michael> CREATE FUNCTION balance RETURNS REAL SONAME "udf_example.so";
Michael> double balance(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
Michael> char *error)
Michael> {
Michael> if(currentRow == 0)
Michael> return value(currentRow, currentColumn-1)
Michael> return value(currentRow-1, currentColumn) + value(currentRow, currentColum
Michael> -1)
Michael> }
Michael> Apparently my code may have to look more like this, by using the primary
Michael> key of the table to get the values I need.
Michael> double balance(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
Michael> char *error)
Michael> {
Michael> if(indexId == 1)
Michael> return indexId.debit;
Michael> return account(indexId).debit + account(indexId - 1).balance
Michael> }
Michael> or
Michael> double balance(UDF_INIT *initid, UDF_ARGS *args, char *is_null,
Michael> char *error)
Michael> {
Michael> float total = 0;
Michael> for(int i = 1; i<=indexId; i++)
Michael> total += account(i).debit;
Michael> }
Michael> If anyone can tell me how to access the data structures in MySQL to get any
Michael> of those things out I should be able to finish this little problem.
Michael> Mike
Hi!
Sorry, you can't access the data structures in a UDF function.
You can however solve your problem this way:
Allocate a variable in your init function (you should save this in
UDF_INIT -> ptr)
For each call to the balance function, add the new value to the old
value and return the new value.
Regards,
Monty