MySQL Stored Procedure Programming

MySQL Stored Procedure Programming

Guy Harrison, Steven Feuerstein

Language: English

Pages: 640

ISBN: 0596100892

Format: PDF / Kindle (mobi) / ePub

The implementation of stored procedures in MySql 5.0 a huge milestone -- one that is expected to lead to widespread enterprise adoption of the already extremely popular MySql database. If you are serious about building the web-based database applications of the future, you need to get up to speed quickly on how stored procedures work -- and how to build them the right way. This book, destined to be the bible of stored procedure development, is a resource that no real MySql programmer can afford to do without.

In the decade since MySql burst on the scene, it has become the dominant open source database, with capabilities and performance rivaling those of commercial Rdbms offerings like Oracle and Sql Server. Along with Linux and Php, MySql is at the heart of millions of applications. And now, with support for stored procedures, functions, and triggers in MySql 5.0, MySql offers the programming power needed for true enterprise use.

MySql's new procedural language has a straightforward syntax, making it easy to write simple programs. But it's not so easy to write secure, easily maintained, high-performance, and bug-free programs. Few in the MySql world have substantial experience yet with stored procedures, but Guy Harrison and Steven Feuerstein have decades of combined expertise.

In MySql Stored Procedure Programming, they put that hard-won experience to good use. Packed with code examples and covering everything from language basics to application building to advanced tuning and best practices, this highly readable book is the one-stop guide to MySql development. It consists of four major sections:

multiple rows within the stored procedure. If we execute such a stored procedure from the MySQL command line, the results are returned to us in the same way as if we executed a SELECT or SHOW statement. Figure 2-12 shows a stored procedure that contains such an unbounded SELECT statement. Figure 2-12. An unbounded SELECT statement in a stored procedure If we execute the stored procedure and supply an appropriate value for the input parameter, the results of the SELECT within the stored

MySQL stored program involves fetching one or more rows of data. You can do this in a stored program through the use of a cursor (explained in Chapter 5). However, MySQL (and the ANSI standard) considers an attempt to fetch past the last row of the cursor an error. Therefore, you almost always need to catch that particular error when looping through the results from a cursor. Consider the simple cursor loop shown in Example 6-4. At first glance, you might worry that we might inadvertently have

clauses in turn. Types of Handlers Condition handlers can be one of two types: EXIT When an EXIT handler fires, the currently executing block is terminated. If this block is the main block for the stored program, the procedure terminates, and control is returned to the procedure or external program that invoked the procedure. If the block is enclosed within an outer block inside of the same stored program, control is returned to that outer block. CONTINUE With a CONTINUE handler,

CREATE FUNCTION statements return the CREATE statement necessary to re-create a particular stored program. Figure 7-12 shows the output of this version of SHOW. Note that we used the "View Field pop-up editor" right-click option to load the text output returned by this statement into a more readable Field Viewer window. INFORMATION_SCHEMA.ROUTINES Table The INFORMATION_SCHEMA.ROUTINES table returns a variety of information about stored procedures and functions. You can use the WHERE