Learn XQuery |
Home:Learn XQuery:XQuery Examples:XQueryWebService:Photo Search:XQuery Source XQuery Source — Updating Relational DataOnce you start the Photo Search demonstration, you need to log in. This section describes the XQuery code that's used both to generate the HTML for the Photo Search login page and to perform login functions. The Log In PageAs shown in the following illustration, the Log In page is generated by two XQuery files — loging.xquery and toolbar.xquery. The login.xquery file, which you can see in the URL displayed in the browser's Address field, is the file directly responsible for generating the Log In page.
Note, though, that the DataDirect XQuery logo and the toolbar come from the declare option ddtek:serialize "method=html"; Creating a New UserSo far, what we've seen is pretty straightforward usage of XQuery. Let's take a closer look at the login functionality defined in the HTML inside <html> As you can see, the second <script type="text/javascript"> element defines an inline function, function checkLogin(). If the User Name field is not empty, the ajax_insertUser() function defined in the ajax.js is called, passing the login value as the parameter. The ajax.js JavascriptThe Javascript file ajax.js is just a library of Javascript functions, like ajax_insertUser(): function ajax_insertUser(login) The ajax_insertUser() function concatenates the URL with insertUser.xquery?login= with the login value provided by the user — so, we have http://examples.xquery.com/photo-search/insertUser.xquery?login=ohenry, for example. Next, let's look at insertUser.xquery to see what it does with the login value. The insertUser.xquery QueryThe insertUser.xquery is, as the name suggests, responsible for adding new users to the database. This is accomplished using the proprietary DataDirect XQuery ddtek:sql-insert function to insert a single record into a database table. declare variable $login as xs:string external; Here, the ddtek:sql-insert function is being used to insert the user name value ($login) into the "login" column of the "users" table. Once the user name is added to the database, the ajax_insertUser() function opens a new URL for main.xquery, again creating the URL by concatenating the query name with the user name (login) value — http://examples.xquery.com/photo-search/main.xquery?login=ohenry, for example. The URL is opened in the same browser ("_self"): ... It is main.xquery that provides the search and query-listing capabilities of the Photo Search demonstration application. What's Next?Now that you have seen how you can use XQuery to update a relational database, let's take a look at the heart of the Photo Search application — searching Flickr photos using DataDirect XQuery and a Flickr Web service. There you'll learn how the XQueryWebService framework was used to implement this search functionality. |






