MySQL Stored Procedure Programming (Paperback)

Guy Harrison, Steven Feuerstein

  • 出版商: O'Reilly
  • 出版日期: 2006-04-07
  • 售價: $1,550
  • 貴賓價: 9.5$1,473
  • 語言: 英文
  • 頁數: 640
  • 裝訂: Paperback
  • ISBN: 0596100892
  • ISBN-13: 9780596100896
  • 相關分類: MySQLSQL
  • 下單後立即進貨 (約1週~2週)




MySQL Stored Procedure Programming covers a lot of ground. The book starts with a thorough introduction to stored procedures programming and functions, covering the fundamentals of data types, operators, and using SQL in stored procedures. You'll learn how to build and maintain stored programs -- covering transactions, stored functions, and triggers -- and how to call and use MySQL-based stored procedures in a variety of languages, including PHP, Perl, Python, .NET, and Java. This book, destined to be the bible of stored procedure development, is a resource that no real MySQL programmer can afford to do without.

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:

  • MySQL stored programming fundamentals -- tutorial, basic
    statements, SQL in stored programs, and error handling
  • Building MySQL stored programs -- transaction handling,
    built-in functions, stored functions, and triggers
  • MySQL stored programs in applications -- using stored
    programs with PHP, Java, Perl, Python, and .NET (C# and VB.NET)
  • Optimizing MySQL stored programs -- security, basic and
    advanced SQL tuning, optimizing stored program code, and programming
    best practices

A companion web site contains many thousands of lines of code, that you
can put to use immediately.


Table of Contents


Part I. Stored Programming Fundamentals

1. Introduction to MySQL Stored Programs

     What Is a Stored Program?

     A Quick Tour

     Resources for Developers Using Stored Programs

     Some Words of Advice for Developers


2. MySQL Stored Programming Tutorial

     What You Will Need

     Our First Stored Procedure



     Conditional Execution


     Dealing with Errors

     Interacting with the Database

     Calling Stored Programs from Stored Programs

     Putting It All Together

     Stored Functions


     Calling a Stored Procedure from PHP


3. Language Fundamentals

     Variables, Literals, Parameters, and Comments



     Built-in Functions

     Data Types

     MySQL 5 "Strict" Mode


4. Blocks, Conditional Statements, and Iterative Programming

     Block Structure of Stored Programs

     Conditional Control

     Iterative Processing with Loops


5. Using SQL in Stored Programming

     Using Non-SELECT SQL in Stored Programs

     Using SELECT Statements with an INTO Clause

     Creating and Using Cursors

     Using Unbounded SELECT Statements

     Performing Dynamic SQL with Prepared Statements

     Handling SQL Errors:  A Preview


6. Error Handling

     Introduction to Error Handling

     Condition Handlers

     Named Conditions

     Missing SQL:2003 Features

     Putting It All Together

     Handling Stored Program Errors in the Calling Application


Part II. Stored Program Construction

7. Creating and Maintaining Stored Programs

     Creating Stored Programs

     Editing an Existing Stored Program

     SQL Statements for Managing Stored Programs

     Getting Information About Stored Programs


8. Transaction Management

     Transactional Support in MySQL

     Defining a Transaction

     Working with Savepoints

     Transactions and Locks

     Transaction Design Guidelines


9. MySQL Built-in Functions

     String Functions

     Numeric Functions

     Date and Time Functions

     Other Functions


10. Stored Functions

     Creating Stored Functions

     SQL Statements in Stored Functions

     Calling Stored Functions

     Using Stored Functions in SQL


11. Triggers

     Creating Triggers

     Using Triggers

     Trigger Overhead


Part III. Using MySQL Stored Programs in Applications

12. Using MySQL Stored Programs in Applications

     The Pros and Cons of Stored Programs in Modern Applications

     Advantages of Stored Programs

     Disadvantages of Stored Programs

     Calling Stored Programs from Application Code


13. Using MySQL Stored Programs with PHP

     Options for Using MySQL with PHP

     Using PHP with the mysqli Extension

     Using MySQL with PHP Data Objects


14. Using MySQL Stored Programs with Java

     Review of JDBC Basics

     Using Stored Programs in JDBC

     Stored Programs and J2EE Applications

     Using Stored Procedures with Hibernate

     Using Stored Procedures with Spring


15. Using MySQL Stored Programs with Perl

     Review of Perl DBD::mysql Basics

     Executing Stored Programs with DBD::mysql


16. Using MySQL Stored Programs with Python

     Installing the MySQLdb Extension

     MySQLdb Basics

     Using Stored Programs with MySQLdb

     A Complete Example


17. Using MySQL Stored Programs with .NET

     Review of ADO.NET Basics

     Using Stored Programs in ADO.NET

     Using Stored Programs in ASP.NET


Part IV. Optimizing Stored Programs

18. Stored Program Security

     Permissions Required for Stored Programs

     Execution Mode Options for Stored Programs

     Stored Programs and Code Injection


19. Tuning Stored Programs and Their SQL

     Why SQL Tuning Is So Important

     How MySQL Processes SQL

     SQL Tuning Statements and Practices

     About the Upcoming Examples


20. Basic SQL Tuning

     Tuning Table Access

     Tuning Joins


21. Advanced SQL Tuning

     Tuning Subqueries

      Tuning "Anti-Joins" Using Subqueries

     Tuning Subqueries in the FROM Clause

     Tuning ORDER and GROUP BY



22. Optimizing Stored Program Code

     Performance Characteristics of Stored Programs

     How Fast Is the Stored Program Language?

     Reducing Network Traffic with Stored Programs

     Stored Programs as an Alternative to Expensive SQL

     Optimizing Loops

     IF and CASE Statements



     Trigger Overhead


23. Best Practices in MySQL Stored Program Development

     The Development Process

     Coding Style and Conventions


     Conditional Logic

     Loop Processing

     Exception Handling

     SQL in Stored Programs

     Dynamic SQL

     Program Construction