MySQL Stored Procedure Programming (Paperback)

Guy Harrison, Steven Feuerstein

  • 出版商: O'Reilly
  • 出版日期: 2006-05-02
  • 定價: $1,575
  • 售價: 9.5$1,496
  • 貴賓價: 8.8$1,386
  • 語言: 英文
  • 頁數: 640
  • 裝訂: Paperback
  • ISBN: 0596100892
  • ISBN-13: 9780596100896
  • 相關分類: MySQLSQL
  • 立即出貨 (庫存=1)




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






MySQL 5.0中儲存過程的實現是一個重要的里程碑,預計將促使廣泛的企業採用已經非常受歡迎的MySQL數據庫。如果您真的想要構建未來的基於Web的數據庫應用程序,您需要迅速掌握儲存過程的工作原理,以及如何正確地構建它們。這本書將成為儲存過程開發的聖經,是任何真正的MySQL程序員都不能錯過的資源。

自MySQL出現以來的十年中,它已成為主流的開源數據庫,具有與Oracle和SQL Server等商業關聯數據庫相媲美的功能和性能。與Linux和PHP一起,MySQL是數百萬應用程序的核心。現在,隨著MySQL 5.0對儲存過程、函數和觸發器的支持,MySQL提供了真正的企業級編程能力。

MySQL的新程序語言具有直觀的語法,使得編寫簡單的程序變得容易。但是,編寫安全、易於維護、高性能和無錯誤的程序並不容易。在MySQL世界中,對儲存過程的實際經驗還不多,但Guy Harrison和Steven Feuerstein擁有數十年的經驗。在《MySQL儲存過程編程》中,他們將這些寶貴的經驗充分利用起來。這本易讀的書籍充滿了代碼示例,涵蓋了從語言基礎到應用程序構建再到高級調優和最佳實踐的所有內容,是MySQL開發的一站式指南。它由四個主要部分組成:

- MySQL儲存編程基礎知識:教程、基本語句、儲存程序中的SQL和錯誤處理。
- 構建MySQL儲存程序:事務處理、內置函數、儲存函數和觸發器。
- 應用中的MySQL儲存程序:使用PHP、Java、Perl、Python和.NET(C#和VB.NET)與儲存程序一起使用。
- 優化MySQL儲存程序:安全性、基本和高級SQL調優、優化儲存程序代碼和編程最佳實踐。