| Preface | p. xiii |
| Stored Programming Fundamentals | |
| Introduction to MySQL Stored Programs | p. 3 |
| What Is a Stored Program? | p. 3 |
| A Quick Tour | p. 7 |
| Resources for Developers Using Stored Programs | p. 13 |
| Some Words of Advice for Developers | p. 15 |
| Conclusion | p. 19 |
| MySQL Stored Programming Tutorial | p. 20 |
| What You Will Need | p. 20 |
| Our First Stored Procedure | p. 20 |
| Variables | p. 25 |
| Parameters | p. 25 |
| Conditional Execution | p. 30 |
| Loops | p. 31 |
| Dealing with Errors | p. 32 |
| Interacting with the Database | p. 33 |
| Calling Stored Programs from Stored Programs | p. 38 |
| Putting It All Together | p. 39 |
| Stored Functions | p. 41 |
| Triggers | p. 43 |
| Calling a Stored Procedure from PHP | p. 45 |
| Conclusion | p. 46 |
| Language Fundamentals | p. 49 |
| Variables, Literals, Parameters, and Comments | p. 49 |
| Operators | p. 60 |
| Expressions | p. 64 |
| Built-in Functions | p. 64 |
| Data Types | p. 68 |
| MySQL 5 "Strict" Mode | p. 72 |
| Conclusion | p. 76 |
| Blocks, Conditional Statements, and Iterative Programming | p. 77 |
| Block Structure of Stored Programs | p. 77 |
| Conditional Control | p. 82 |
| Iterative Processing with Loops | p. 93 |
| Conclusion | p. 98 |
| Using SQL in Stored Programming | p. 99 |
| Using Non-Select SQL in Stored Programs | p. 99 |
| Using Select Statements with an Into Clause | p. 100 |
| Creating and Using Cursors | p. 101 |
| Using Unbounded Select Statements | p. 112 |
| Performing Dynamic SQL with Prepared Statements | p. 118 |
| Handling SQL Errors: A Preview | p. 123 |
| Conclusion | p. 124 |
| Error Handling | p. 125 |
| Introduction to Error Handling | p. 125 |
| Condition Handlers | p. 129 |
| Named Conditions | p. 139 |
| Missing SQL:2003 Features | p. 139 |
| Putting It All Together | p. 145 |
| Handling Stored Program Errors in the Calling Application | p. 150 |
| Conclusion | p. 155 |
| Stored Program Construction | |
| Creating and Maintaining Stored Programs | p. 159 |
| Creating Stored Programs | p. 159 |
| Editing an Existing Stored Program | p. 166 |
| SQL Statements for Managing Stored Programs | p. 170 |
| Getting Information About Stored Programs | p. 173 |
| Conclusion | p. 176 |
| Transaction Management | p. 179 |
| Transactional Support in MySQL | p. 180 |
| Defining a Transaction | p. 183 |
| Working with Savepoints | p. 185 |
| Transactions and Locks | p. 190 |
| Transaction Design Guidelines | p. 201 |
| Conclusion | p. 203 |
| MySQL Built-in Functions | p. 205 |
| String Functions | p. 205 |
| Numeric Functions | p. 218 |
| Date and Time Functions | p. 223 |
| Other Functions | p. 233 |
| Conclusion | p. 237 |
| Stored Functions | p. 238 |
| Creating Stored Functions | p. 238 |
| SQL Statements in Stored Functions | p. 242 |
| Calling Stored Functions | p. 242 |
| Using Stored Functions in SQL | p. 244 |
| Conclusion | p. 248 |
| Triggers | p. 249 |
| Creating Triggers | p. 249 |
| Using Triggers | p. 251 |
| Trigger Overhead | p. 256 |
| Conclusion | p. 257 |
| Using MySQL Stored Programs in Applications | |
| Using MySQL Stored Programs in Applications | p. 261 |
| The Pros and Cons of Stored Programs in Modern Applications | p. 261 |
| Advantages of Stored Programs | p. 264 |
| Disadvantages of Stored Programs | p. 268 |
| Calling Stored Programs from Application Code | p. 270 |
| Conclusion | p. 273 |
| Using MySQL Stored Programs with PHP | p. 275 |
| Options for Using MySQL with PHP | p. 276 |
| Using PHP with the mysqli Extension | p. 276 |
| Using MySQL with PHP Data Objects | p. 289 |
| Conclusion | p. 308 |
| Using MySQL Stored Programs with Java | p. 309 |
| Review of JDBC Basics | p. 310 |
| Using Stored Programs in JDBC | p. 317 |
| Stored Programs and J2EE Applications | p. 323 |
| Using Stored Procedures with Hibernate | p. 332 |
| Using Stored Procedures with Spring | p. 337 |
| Conclusion | p. 342 |
| Using MySQL Stored Programs with Perl | p. 343 |
| Review of Perl DBD::mysql Basics | p. 344 |
| Executing Stored Programs with DBD::mysql | p. 354 |
| Conclusion | p. 362 |
| Using MySQL Stored Programs with Python | p. 364 |
| Installing the MySQLdb Extension | p. 364 |
| MySQLdb Basics | p. 365 |
| Using Stored Programs with MySQLdb | p. 373 |
| A Complete Example | p. 380 |
| Conclusion | p. 385 |
| Using MySQL Stored Programs with .NET | p. 386 |
| Review of ADO.NET Basics | p. 386 |
| Using Stored Programs in ADO.NET | p. 401 |
| Using Stored Programs in ASP.NET | p. 413 |
| Conclusion | p. 417 |
| Optimizing Stored Programs | |
| Stored Program Security | p. 421 |
| Permissions Required for Stored Programs | p. 422 |
| Execution Mode Options for Stored Programs | p. 423 |
| Stored Programs and Code Injection | p. 434 |
| Conclusion | p. 440 |
| Tuning Stored Programs and Their SQL | p. 442 |
| Why SQL Tuning Is So Important | p. 443 |
| How MySQL Processes SQL | p. 445 |
| SQL Tuning Statements and Practices | p. 449 |
| About the Upcoming Examples | p. 459 |
| Conclusion | p. 462 |
| Basic SQL Tuning | p. 463 |
| Tuning Table Access | p. 463 |
| Tuning Joins | p. 480 |
| Conclusion | p. 485 |
| Advanced SQL Tuning | p. 486 |
| Tuning Subqueries | p. 486 |
| Tuning "Anti-Joins" Using Subqueries | p. 493 |
| Tuning Subqueries in the From Clause | p. 495 |
| Tuning Order and Group By | p. 501 |
| Tuning DML (Insert, Update, Delete) | p. 503 |
| Conclusion | p. 506 |
| Optimizing Stored Program Code | p. 508 |
| Performance Characteristics of Stored Programs | p. 508 |
| How Fast Is the Stored Program Language? | p. 509 |
| Reducing Network Traffic with Stored Programs | p. 512 |
| Stored Programs as an Alternative to Expensive SQL | p. 515 |
| Optimizing Loops | p. 519 |
| If and Case Statements | p. 522 |
| Recursion | p. 526 |
| Cursors | p. 528 |
| Trigger Overhead | p. 529 |
| Conclusion | p. 532 |
| Best Practices in MySQL Stored Program Development | p. 533 |
| The Development Process | p. 533 |
| Coding Style and Conventions | p. 539 |
| Variables | p. 544 |
| Conditional Logic | p. 551 |
| Loop Processing | p. 555 |
| Exception Handling | p. 559 |
| SQL in Stored Programs | p. 562 |
| Dynamic SQL | p. 566 |
| Program Construction | p. 569 |
| Performance | p. 577 |
| Conclusion | p. 581 |
| Index | p. 583 |
| Table of Contents provided by Ingram. All Rights Reserved. |