SQL Anywhere® Server Programming
Total Page:16
File Type:pdf, Size:1020Kb
SQL Anywhere® Server Programming June 2008 Version 11.0.0 Copyright and trademarks Copyright © 2008 iAnywhere Solutions, Inc. Portions copyright © 2008 Sybase, Inc. All rights reserved. This documentation is provided AS IS, without warranty or liability of any kind (unless provided by a separate written agreement between you and iAnywhere). You may use, print, reproduce, and distribute this documentation (in whole or in part) subject to the following conditions: 1) you must retain this and all other proprietary notices, on all copies of the documentation or portions thereof, 2) you may not modify the documentation, 3) you may not do anything to indicate that you or anyone other than iAnywhere is the author or source of the documentation. iAnywhere®, Sybase®, and the marks listed at http://www.sybase.com/detail?id=1011207 are trademarks of Sybase, Inc. or its subsidiaries. ® indicates registration in the United States of America. All other company and product names mentioned may be trademarks of the respective companies with which they are associated. Contents About this book ........................................................................................... ix About the SQL Anywhere documentation ................................................................ x I. Introduction to Programming with SQL Anywhere ................................ 1 1. SQL Anywhere data access programming interfaces ......................................... 3 SQL Anywhere .NET API ....................................................................................... 4 SQL Anywhere OLE DB and ADO APIs ................................................................ 5 ODBC API .............................................................................................................. 6 JDBC API ............................................................................................................... 7 SQL Anywhere embedded SQL ............................................................................ 8 SQL Anywhere Perl DBI API ................................................................................. 9 SQL Anywhere Python Database API ................................................................. 10 SQL Anywhere PHP API ..................................................................................... 11 SQL Anywhere web services ............................................................................... 12 Sybase Open Client API ...................................................................................... 13 2. SQL Anywhere Explorer ....................................................................................... 15 Introduction to the SQL Anywhere Explorer ........................................................ 16 Using the SQL Anywhere Explorer ...................................................................... 17 3. Using SQL in applications .................................................................................... 21 Executing SQL statements in applications .......................................................... 22 Preparing statements ........................................................................................... 24 Introduction to cursors ......................................................................................... 27 Working with cursors ........................................................................................... 30 Choosing cursor types ......................................................................................... 37 SQL Anywhere cursors ........................................................................................ 39 Describing result sets .......................................................................................... 56 Controlling transactions in applications ............................................................... 58 4. Three-tier computing and distributed transactions ........................................... 63 Introduction to three-tier computing and distributed transactions ........................ 64 Three-tier computing architecture ........................................................................ 65 Using distributed transactions .............................................................................. 68 Using EAServer with SQL Anywhere ................................................................... 70 Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 iii SQL Anywhere® Server - Programming II. Java in the database .............................................................................. 73 5. Java support in SQL Anywhere ........................................................................... 75 Introduction to Java support ................................................................................ 76 Java in the database Q & A ................................................................................. 78 Java error handling .............................................................................................. 82 The runtime environment for Java in the database ............................................. 83 6. Tutorial: Using Java in the database ................................................................... 87 Introduction to Java in the database tutorial ........................................................ 88 Installing Java classes into a database ............................................................... 95 Special features of Java classes in the database ................................................ 99 Starting and stopping the Java VM .................................................................... 103 Unsupported Java classes ................................................................................. 104 III. SQL Anywhere Data Access APIs ..................................................... 105 7. SQL Anywhere .NET Data Provider ................................................................... 107 SQL Anywhere .NET Data Provider features .................................................... 108 Running the sample projects ............................................................................. 109 Using the .NET Data Provider in a Visual Studio project ................................... 110 Connecting to a database .................................................................................. 112 Accessing and manipulating data ...................................................................... 115 Using stored procedures .................................................................................... 132 Transaction processing ...................................................................................... 134 Error handling and the SQL Anywhere .NET Data Provider .............................. 136 Deploying the SQL Anywhere .NET Data Provider ........................................... 137 Tracing support .................................................................................................. 139 8. Tutorial: Using the SQL Anywhere .NET Data Provider ................................... 143 Introduction to the .NET Data Provider tutorial .................................................. 144 Using the Simple code sample .......................................................................... 145 Using the Table Viewer code sample ................................................................ 148 9. Tutorial: Developing a simple .NET database application with Visual Studio ....................................................................................................................... 153 Lesson 1. Create a table viewer ........................................................................ 154 Lesson 2. Add a synchronizing data control ...................................................... 158 10. SQL Anywhere .NET 2.0 API Reference .......................................................... 163 iv Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 SQL Anywhere® Server - Programming iAnywhere.Data.SQLAnywhere namespace (.NET 2.0) .................................... 164 iAnywhere.SQLAnywhere.Server namespace (.NET 2.0) ................................. 422 11. SQL Anywhere OLE DB and ADO APIs ........................................................... 425 Introduction to OLE DB ...................................................................................... 426 ADO programming with SQL Anywhere ............................................................ 427 Setting up a Microsoft Linked Server using OLE DB ......................................... 434 Supported OLE DB interfaces ........................................................................... 435 12. SQL Anywhere ODBC API ................................................................................ 441 Introduction to ODBC ......................................................................................... 442 Building ODBC applications ............................................................................... 444 ODBC samples .................................................................................................. 449 ODBC handles ................................................................................................... 450 Choosing an ODBC connection function ........................................................... 453 SQL Anywhere connection attributes ................................................................ 456