Book description
The implementation of stored procedures in MySQL 5.0 a hugemilestone -- one that is expected to lead to widespread enterprise adoption ofthe already extremely popular MySQL database. If you are serious aboutbuilding the web-based database applications of the future, you need toget up to speed quickly on how stored procedures work -- and how tobuild them the right way. This book, destined to be the bible of storedprocedure development, is a resource that no real MySQL programmer canafford to do without.
In the decade since MySQL burst on the scene, it has become thedominant open source database, with capabilities and performancerivaling those of commercial RDBMS offerings like Oracle and SQLServer. Along with Linux and PHP, MySQL is at the heart of millions ofapplications. And now, with support for stored procedures, functions,and triggers in MySQL 5.0, MySQL offers the programming power neededfor true enterprise use.
MySQL's new procedural language has a straightforward syntax, making iteasy to write simple programs. But it's not so easy to write secure,easily maintained, high-performance, and bug-free programs. Few in theMySQL world have substantial experience yet with stored procedures, butGuy Harrison and Steven Feuerstein have decades of combined expertise.
In MySQL Stored Procedure Programming, they putthat hard-won experience to good use. Packed with code examples and coveringeverything from language basics to application building to advancedtuning and best practices, this highly readable book is the one-stopguide to MySQL development. It consists of four major sections:
- MySQL stored programming fundamentals -- tutorial, basicstatements, 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 storedprograms with PHP, Java, Perl, Python, and .NET (C# and VB.NET)
- Optimizing MySQL stored programs -- security, basic andadvanced SQL tuning, optimizing stored program code, and programmingbest practices
A companion web site contains many thousands of lines of code, that youcan put to use immediately.
Guy Harrison is Chief Architect of Database Solutions at Quest Softwareand a frequent speaker and writer on MySQL topics. Steven Feuerstein isthe author of Oracle PL/SQL Programming, the classic reference for Oracle stored programming for more than ten years. Both have decades of experience as database developers, and between them they have authored a dozen books.
Table of contents
- A Note Regarding Supplemental Files
- Advance Praise for MySQL Stored Procedure Programming
- Preface
-
I. Stored Programming Fundamentals
- 1. Introduction to MySQL Stored Programs
-
2. MySQL Stored Programming Tutorial
- 2.1. What You Will Need
- 2.2. Our First Stored Procedure
- 2.3. Variables
- 2.4. Parameters
- 2.5. Conditional Execution
- 2.6. Loops
- 2.7. Dealing with Errors
- 2.8. Interacting with the Database
- 2.9. Calling Stored Programs from Stored Programs
- 2.10. Putting It All Together
- 2.11. Stored Functions
- 2.12. Triggers
- 2.13. Calling a Stored Procedure from PHP
- 2.14. Conclusion
- 3. Language Fundamentals
- 4. Blocks, Conditional Statements, and Iterative Programming
- 5. Using SQL in Stored Programming
- 6. Error Handling
-
II. Stored Program Construction
- 7. Creating and Maintaining Stored Programs
- 8. Transaction Management
-
9. MySQL Built-in Functions
-
9.1. String Functions
- 9.1.1. ASCII
- 9.1.2. CHAR
- 9.1.3. CHARSET
- 9.1.4. CONCAT
- 9.1.5. CONCAT_WS
- 9.1.6. INSERT
- 9.1.7. INSTR
- 9.1.8. LCASE
- 9.1.9. LEFT
- 9.1.10. LENGTH
- 9.1.11. LOAD_FILE
- 9.1.12. LOCATE
- 9.1.13. LPAD
- 9.1.14. LTRIM
- 9.1.15. REPEAT
- 9.1.16. REPLACE
- 9.1.17. RPAD
- 9.1.18. RTRIM
- 9.1.19. STRCMP
- 9.1.20. SUBSTRING
- 9.1.21. TRIM
- 9.1.22. UCASE
- 9.1.23. Other String Functions
- 9.2. Numeric Functions
-
9.3. Date and Time Functions
- 9.3.1. ADDTIME
- 9.3.2. CONVERT_TZ
- 9.3.3. CURRENT_DATE
- 9.3.4. CURRENT_TIME
- 9.3.5. CURRENT_TIMESTAMP
- 9.3.6. DATE
- 9.3.7. DATE_ADD
- 9.3.8. DATE_FORMAT
- 9.3.9. DATE_SUB
- 9.3.10. DATEDIFF
- 9.3.11. DAY
- 9.3.12. DAYNAME
- 9.3.13. DAYOFWEEK
- 9.3.14. DAYOFYEAR
- 9.3.15. EXTRACT
- 9.3.16. GET_FORMAT
- 9.3.17. MAKEDATE
- 9.3.18. MAKETIME
- 9.3.19. MONTHNAME
- 9.3.20. NOW
- 9.3.21. SEC_TO_TIME
- 9.3.22. STR_TO_DATE
- 9.3.23. TIME_TO_SEC
- 9.3.24. TIMEDIFF
- 9.3.25. TIMESTAMP
- 9.3.26. TIMESTAMPADD
- 9.3.27. TIMESTAMPDIFF
- 9.3.28. WEEK
- 9.3.29. WEEKDAY
- 9.3.30. YEAR
- 9.3.31. YEARWEEK
- 9.3.32. Other Date and Time Functions
- 9.4. Other Functions
- 9.5. Conclusion
-
9.1. String Functions
- 10. Stored Functions
- 11. Triggers
-
III. Using MySQL Stored Programs in Applications
-
12. Using MySQL Stored Programs in Applications
- 12.1. The Pros and Cons of Stored Programs in Modern Applications
- 12.2. Advantages of Stored Programs
- 12.3. Disadvantages of Stored Programs
-
12.4. Calling Stored Programs from Application Code
- 12.4.1. Preparing a Stored Program Call for Execution
- 12.4.2. Registering Parameters
- 12.4.3. Setting Output Parameters
- 12.4.4. Executing the Stored Program
- 12.4.5. Retrieving Result Sets
- 12.4.6. Retrieving Output Parameters
- 12.4.7. Closing or Re-Executing the Stored Program
- 12.4.8. Calling Stored Functions
- 12.5. Conclusion
-
13. Using MySQL Stored Programs with PHP
- 13.1. Options for Using MySQL with PHP
-
13.2. Using PHP with the mysqli Extension
- 13.2.1. Enabling the mysqli Extension
- 13.2.2. Connecting to MySQL
- 13.2.3. Checking for Errors
- 13.2.4. Executing a Simple Non-SELECT Statement
- 13.2.5. Retrieving a Result Set
- 13.2.6. Managing Transactions
- 13.2.7. Using Prepared Statements
- 13.2.8. Retrieving Result Sets from Prepared Statements
- 13.2.9. Getting Result Set Metadata
- 13.2.10. Processing a Dynamic Result Set
- 13.2.11. Calling Stored Programs with mysqli
- 13.2.12. Handling Output Parameters
- 13.2.13. Retrieving Multiple Result Sets
-
13.3. Using MySQL with PHP Data Objects
- 13.3.1. Connecting to MySQL
- 13.3.2. Executing a Simple Non-SELECT Statement
- 13.3.3. Catching Errors
- 13.3.4. Managing Transactions
- 13.3.5. Issuing a One-Off Query
- 13.3.6. Using Prepared Statements
- 13.3.7. Binding Parameters to a Prepared Statement
- 13.3.8. Getting Result Set Metadata
- 13.3.9. Processing a Dynamic Result Set
- 13.3.10. Calling Stored Programs with PDO
- 13.3.11. Binding Input Parameters to Stored Programs
- 13.3.12. Handling Multiple Result Sets
- 13.3.13. Handling Output Parameters
- 13.3.14. A Complete Example
- 13.4. Conclusion
-
14. Using MySQL Stored Programs with Java
-
14.1. Review of JDBC Basics
- 14.1.1. Installing the Driver and Configuring Your IDE
- 14.1.2. Registering the Driver and Connecting to MySQL
- 14.1.3. Issuing a Non-SELECT Statement
- 14.1.4. Issuing a SELECT and Retrieving a Result Set
- 14.1.5. Getting Result Set Metadata
- 14.1.6. Using Prepared Statements
- 14.1.7. Handling Transactions
- 14.1.8. Handling Errors
-
14.2. Using Stored Programs in JDBC
- 14.2.1. Using the CallableStatement Interface
- 14.2.2. Registering OUT Variables
- 14.2.3. Supplying Input Parameters
- 14.2.4. Executing the Procedure
- 14.2.5. Retrieving a Result Set
- 14.2.6. Retrieving Multiple Result Sets
- 14.2.7. Dynamically Processing Result Sets
- 14.2.8. Retrieving Output Parameter Values
- 14.3. Stored Programs and J2EE Applications
- 14.4. Using Stored Procedures with Hibernate
- 14.5. Using Stored Procedures with Spring
- 14.6. Conclusion
-
14.1. Review of JDBC Basics
-
15. Using MySQL Stored Programs with Perl
-
15.1. Review of Perl DBD::mysql Basics
- 15.1.1. Installing DBD::mysql
- 15.1.2. Connecting to MySQL
- 15.1.3. Handling Errors
- 15.1.4. Issuing a Simple One-off Statement
- 15.1.5. Preparing a Statement for Reuse
- 15.1.6. Using Bind Variables
- 15.1.7. Issuing a Query and Retrieving Results
- 15.1.8. There’s More Than One Way To Do It
- 15.1.9. Getting Result Set Metadata
- 15.1.10. Performing Transaction Management
- 15.2. Executing Stored Programs with DBD::mysql
- 15.3. Conclusion
-
15.1. Review of Perl DBD::mysql Basics
- 16. Using MySQL Stored Programs with Python
-
17. Using MySQL Stored Programs with .NET
-
17.1. Review of ADO.NET Basics
- 17.1.1. Installing the Connector/Net Driver and Configuring Your IDE
- 17.1.2. Registering the Driver and Connecting to MySQL
- 17.1.3. Issuing a Non-SELECT Statement
- 17.1.4. Reusing a Statement Object
- 17.1.5. Using Parameters
- 17.1.6. Issuing a SELECT and Using a DataReader
- 17.1.7. Getting DataReader Metadata
- 17.1.8. DataSets
- 17.1.9. Handling Errors
- 17.1.10. Managing Transactions
-
17.2. Using Stored Programs in ADO.NET
- 17.2.1. Calling a Simple Stored Procedure
- 17.2.2. Supplying Input Parameters
- 17.2.3. Using a DataReader with a Stored Program
- 17.2.4. Processing Multiple Result Sets in a DataReader
- 17.2.5. Dynamically Processing Result Sets
- 17.2.6. Using DataSets with Stored Programs
- 17.2.7. Retrieving Output Parameters
- 17.2.8. Calling Stored Functions
- 17.3. Using Stored Programs in ASP.NET
- 17.4. Conclusion
-
17.1. Review of ADO.NET Basics
-
12. Using MySQL Stored Programs in Applications
-
IV. Optimizing Stored Programs
- 18. Stored Program Security
- 19. Tuning Stored Programs and Their SQL
-
20. Basic SQL Tuning
-
20.1. Tuning Table Access
- 20.1.1. Index Lookup Versus Full Table Scan
- 20.1.2. How MySQL Chooses Between Indexes
- 20.1.3. Manually Choosing an Index
- 20.1.4. Prefixed (“Partial”) Indexes
- 20.1.5. Concatenated Indexes
- 20.1.6. Comparing the Different Indexing Approaches
- 20.1.7. Avoiding Accidental Table Scans
- 20.1.8. Optimizing Necessary Table Scans
- 20.1.9. Using Merge or Partitioned Tables
- 20.2. Tuning Joins
- 20.3. Conclusion
-
20.1. Tuning Table Access
- 21. Advanced SQL Tuning
-
22. Optimizing Stored Program Code
- 22.1. Performance Characteristics of Stored Programs
- 22.2. How Fast Is the Stored Program Language?
- 22.3. Reducing Network Traffic with Stored Programs
- 22.4. Stored Programs as an Alternative to Expensive SQL
- 22.5. Optimizing Loops
- 22.6. IF and CASE Statements
- 22.7. Recursion
- 22.8. Cursors
- 22.9. Trigger Overhead
- 22.10. Conclusion
- 23. Best Practices in MySQL Stored Program Development
- About the Authors
- Colophon
- Copyright
Product information
- Title: MySQL Stored Procedure Programming
- Author(s):
- Release date: March 2006
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9780596100896
You might also like
book
Redis in Action
Summary Redis in Action introduces Redis and walks you through examples that demonstrate how to use …
book
Learning SQL, 3rd Edition
As data floods into your company, you need to put it to work right away—and SQL …
book
Articulating Design Decisions, 2nd Edition
Talking to people about your designs might seem like a basic skill, but it can be …
book
Adobe Photoshop Classroom in a Book (2023 Release)
Learn to create and edit images using Adobe Photoshop Adobe Photoshop Classroom in a Book (2023 …