Database Reference
In-Depth Information
Bookmark manipulation
Sometimes, we may just want to ascertain the contents of a bookmark. This is done
by choosing a bookmark and selecting View only . Only the query will be displayed.
We could then click Edit and rework its contents. By doing so, we would be editing
a copy of the original bookmarked query. To keep this new edited query, we can
save it as a bookmark. Again, this will create another bookmark even if we choose
the same bookmark label, unless we explicitly ask for the original bookmark to
be replaced.
A bookmark can be erased with the Delete option. There is no confirmation dialog
to confirm the deletion of the bookmark. Deletion is followed only by a message
stating: The bookmark has been deleted .
Bookmark parameters
If we look again at the irst bookmark we created (inding all topics for author 1 ), we
realize that although it is useful, it is limited to finding the same author.
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 the 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 will be removed. We label this query as a bookmark named find author by
name and click Go . The first execution of the query just stores the bookmark while
retrieving all topics by all the authors, as this time we haven't passed a parameter to
the query.
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 needs a parameter, we can
use a syntax such as WHERE 1 /* and author_id = [VARIABLE] */ .
 
Search WWH ::




Custom Search