PowerBuilder Tips, Tricks, and Techniques

Berndt Hamboeck

Subscribe to Berndt Hamboeck: eMailAlertsEmail Alerts
Get Berndt Hamboeck: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

PowerBuilder: Article

SQL Anywhere Studio 9 Developer's Guide

A new book by Breck Carter

As a PowerBuilder developer I'm sure you have already used SQL Anywhere a few times, but did you know that SQL Anywhere owns over 70% of the mobile database market?

There are several good reasons for this big market share; it's easy to use, easy to administer, and doesn't take up much space, but SQL Anywhere isn't just for mobile and embedded databases; it's got the features and the flexibility to work as a network server with hundreds of active users pounding away on a single database. And it's got a solid foundation and a long history from its roots with Watcom in the 1980s through to Powersoft and Sybase in the 1990s and now with iAnywhere Solutions in the new millennium. But there are still some features that aren't fully covered by the documentation so Breck Carter decided to write a book about this wonderful database. It's called SQL Anywhere Studio 9 Developer's Guide. So let's have a look at this book this month.

The Book
The book includes a companion CD that includes the full Backus-Naur Form notation for the SQL syntax from the book in HTML format for easy browsing. It also includes all of the examples in the book, plus a full copy of SQL Anywhere Studio 9 Developer Edition for Windows. The book itself is about 450 pages long and starts with the history of the database, beginning with the story of Watcom in 1965 and ending with the release of SQL Anywhere version 9. Then the reader dives into the deep world of the product and learns a lot in the next 10 chapters.

Chapter 1: Creating
This chapter begins with 12 rules to answer the question "What is a relational database?" It then describes the five kinds of tables (global permanent, global temporary, remote, proxy and local temporary) available using the seven different syntax options for the CREATE TABLE statement and, moving on to the wide variety of built-in string, date-time, and numeric data types, it continues with column properties, computed columns, default values, the NULL property, and column constraints. User-defined data types, table constraints, remote data access, and temporary tables are also covered. The chapter ends with a discussion of normalization to answer the question, "What is a good relational database?" An interesting chapter, compactly written.

Chapter 2: Inserting
With the first chapter covering so much information, the second one is exactly right. It talks about putting data into the database, covering five different flavors of INSERT (with a values list for all columns or a list of named columns, a select for all column values or a list of named columns, and use of the auto name facility as well as the load table statement and ISQL's client-side alternative, the input statement.

Chapter 3: Selecting
This one talks about the inverse of Chapter 2, getting data out of the database with SELECT, UNLOAD, and the ISQL OUTPUT statement. This is the longest chapter in the book, which should come as no surprise since the SQL SELECT statement may be the most powerful and complex single syntactic construction available in any database programming language.

Chapter 3 starts by explaining the SELECT statement, and the logical execution of a SELECT, which shows how all the various clauses fit together and contribute to the final result set without concern for how SQL Anywhere actually executes a SELECT. Most of the rest of Chapter 3 follows the steps laid out and explained at the beginning of the chapter. If you've ever had trouble with the GROUP BY clause, or had a SELECT that returned 10,000 rows instead of the three you wanted, or wondered why you can't call NUMBER(*) in a WHERE clause, this is the chapter for you.

Chapter 4: Updating
This chapter covers the UPDATE statement and how it can be used to update a single row in one table, or multiple rows, or even multiple rows in multiple tables. It also includes a section on the logical execution of a set UPDATE and a discussion of cursor UPDATE statements using the WHERE CURRENT OF clause.

Chapter 5: Deleting
Breck calls deleting the evil twin of Chapter 4; he talks about deleting single and multiple rows, and includes a section on the logical execution of a set DELETE as well as information about cursor DELETE statements using WHERE CURRENT OF. He also has a section on TRUNCATE TABLE and how it compares with DELETE: sometimes faster, sometimes not, and why.

Chapter 6: Fetching
A chapter six is a chapter a PowerBuilder developer should read since it talks about the DECLARE, OPEN, FETCH, and CLOSE statements as they apply to cursors using SELECT queries and procedure calls. It also describes the cursor FOR loop, which vastly simplifies the cursor loops in SQL by eliminating the need to DECLARE all those local variables or code those endless FETCH lists. Something a PowerBuilder developer doesn't do very often because of the datawindow and datastore we have.

Chapter 7: Synchronizing
Here you have it - the MobiLink chapter. It discusses how the MobiLink server works together with the MobiLink client for ASA to synchronize data back and forth between a consolidated database and dozens or thousands of remote databases. MobiLink scripts are classified by level (connection, session, table, and row) and by direction (upload versus download). And error handling on the server and client sides is described. This is an interesting chapter for every serious PocketBuilder developer. I can highly recommend it if you want to synchronize your mobile device with a desktop machine.

Chapter 8: Packaging
This chapter is about moving application logic into the database using BEGIN blocks and SQL modules based on BEGIN blocks: procedures, functions, triggers, and events. The SET assignment statement is described, as well as the flow-of-control structures IF, CASE, and WHILE, the EXECUTE IMMEDIATE statement, and the connection-level CREATE VARIABLE statement. This section introduces the basics of exception handling, a topic expanded on in Chapter 9.

Chapter 9: Protecting
Chapter 9 is the second-longest chapter in the book. It explores a wide variety of topics including options, transactions, exceptions, errors, subtransactions, locks, blocks, isolation levels, deadlocks, mutexes, user IDs, privileges, user groups, logging, recovery, backup, restore, and (gasp!) database validation. Many of these topics are only loosely connected to one another, but they all fall under the general heading "Crashing, Bashing, Thrashing, and Protection Therefrom."

Chapter 10: Tuning
This chapter might be the one with the biggest audience since everyone's interested in speed, speed, speed. This chapter should be read last because the first rule of optimization is "Don't do it." If you're an expert, Rule 2 also applies: "Don't do it yet."

Chapter 10 explains the four big performance tuning tools that SQL Anywhere provides: request-level logging, the Index Consultant, the Execution Profiler, and the Graphical Plan. It then moves on to more arcane topics such as file, table, and index fragmentation, and table, index, and database reorganization.

Sections on the syntax of CREATE INDEX and database performance counters are included, and the book ends with a performance tuning "Tips and Techniques" section that lists 36 do's and don'ts that didn't find a home earlier in the book.

The book is easy to read and contains important details about SQL Anywhere development. If you're new to SQL Anywhere the material will save you hours of time and dramatically shorten your learning curve. This book is simply a must-have for SQL Anywhere database developers because it's a complete and compact reference for experienced developers as well as comprehensive immersion for beginners and less experienced coders. It's written by someone who has a great deal of experience using SQL Anywhere Studio to build real-world software solutions. Have fun reading it.


Breck Carter is an experienced database developer. He first worked with a relational database in 1973 (the year I was born) before there were any practical commercial implementations. Over the years he has worked as an independent consultant to develop enterprise databases and applications using IMS DB/DC, DB2, Oracle, SQL Server, ASE, and, beginning in 1995, SQL Anywhere.

Breck has been a member of Team Sybase since 1993, which means you can find him answering questions on the SQL Anywhere newsgroups on behalf of Sybase and iAnywhere Solutions. He is also a member of the iAnywhere Solutions Customer Advisory Board, helping to shape future product direction.

More Stories By Berndt Hamboeck

Berndt Hamboeck is a senior consultant for BHITCON (www.bhitcon.net). He's a CSI, SCAPC8, EASAC, SCJP2, and started his Sybase development using PB5. You can reach him under [email protected]

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.