Search icon CANCEL
Subscription
0
Cart icon
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
MySQL 5.1 Plugin Development

You're reading from  MySQL 5.1 Plugin Development

Product type Book
Published in Aug 2010
Publisher Packt
ISBN-13 9781849510608
Pages 288 pages
Edition 1st Edition
Languages

Table of Contents (16) Chapters

MySQL 5.1 Plugin Development
Credits
About the Authors
About the Reviewer
1. Preface
1. Compiling and Using MySQL Plugins 2. User Defined Functions 3. Daemon Plugins 4. Information Schema Plugins 5. Advanced Information Schema Plugins 6. Full-text Parser Plugins 7. Practical Full-text Parsers 8. Storage Engine Plugins 9. HTML Storage Engine—Reads and Writes 10. TOCAB Storage Engine — Implementing Indexes Beyond MySQL 5.1

An integer echoing UDF


The next example is designed to show how to deal with inputs. It is similar to the previous one, but will demonstrate how to perform argument checking. As you remember, this check should happen in the initialization function, so that we can give a proper error message when there is a problem. We will call this UDF, udf_intexample, and will make it accept only one argument, which has to be an integer for the function to succeed:

#include <string.h>
#include <mysql.h>
my_bool udf_intexample_init(UDF_INIT *initid,
UDF_ARGS *args, char *message)
{

As before, we include everything needed for this example and create an initialization function with the same prefix as the function name.

if (args->arg_count != 1)
{
strcpy(message,
"udf_intexample() can only accept one argument");
return 1;
}

We want to ensure that only one argument is accepted for this UDF so we check that arg_count is 1. If it is not, we stick an error message into the message buffer and return...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}