Databases Reference
In-Depth Information
Bookmark Parameters
If we look again at the irst bookmark we created (inding all topics for author 1 ), we
realize that, although useful, it was limited to always finding the same author.
A special query syntax enables the passing of parameters to bookmarks. This syntax
uses the fact that SQL comments enclosed within /* and */ are ignored by MySQL.
If the /*[VARIABLE]*/ construct exists somewhere in the query, it will be expanded
at execution time with the value provided when recalling the bookmark.
Creating a Parameterized Bookmark
Let's say we want to ind all topics for a given author when we don't know the
author's name. We first enter the following query:
SELECT author.name, author.id, book.title
FROM book, author
WHERE book.author_id = author.id
/* AND author.name LIKE '%[VARIABLE]%' */
The part between the comments characters ( /* */ ) will be expanded later, and the
tags removed:
We label it and click Go . The first execution of the query just stores the bookmark.
In this example, we have two conditions in the WHERE clause, of which one contains
the special syntax. If our only criterion in the WHERE clause needed a parameter, we
could use a syntax like WHERE 1 /* and author_id = [VARIABLE] */ .
 
Search WWH ::




Custom Search