O
BJECT
S
TUDIO
Database User's Guide
Release information for this manual
ObjectStudio Database User's Guide, P40-3203-03, is dated November 1, 2003. This document supports Release 6.9 of ObjectStudio.
Cincom Technical Support for ObjectStudio
All customers Web: http://supportweb.cincom.com
USA customers Phone: 1-800-727-3525 Fax: (513) 612-2000
Attn: ObjectStudio Support Mail: Cincom Systems, Inc.
Attn: ObjectStudio Support 55 Merchant Street
Cincinnati, OH 45246-3732 USA
Outside of USA All: Visit the support links at
http://www.cincom.com to find contact information for your nearest Customer Service Center.
Using this document
This guide is for database application developers. It discusses Smalltalk classes and methods used in ObjectStudio® to support database access. It also
describes the tools in the ObjectStudio development environment that are relevant to creating database access.
As a prerequisite, you should be familiar with relational database theory, the object-oriented approach to software development, and the ObjectStudio Smalltalk development environment.
Document organization
The information in this guide is organized as follows: Chapter 1—Overview of database support
Contains an overview of how ObjectStudio supports access to many types of database management systems (DBMSs).
Chapter 2—How ObjectStudio implements database support
Describes the databases and the classes that ObjectStudio supports. Chapter 3—Working with databases
Provides information about techniques to use when you work with databases.
Chapter 4—ODBC
Discusses topics specific to ODBC. Chapter 5—DB2
Discusses topics specific to DB2®. Chapter 6—Informix
Discusses topics specific to Informix®. Chapter 7—SUPRA SQL
Chapter 8—UniSQL Server
Discusses topics specific to UniSQL Server. Chapter 9—Other databases
Discusses topics specific to Oracle®, Oracle OCI, ADABAS®, SQL Server, and SYBASE® OpenClient.
Chapter 10—Database Notebook
Describes the Database Notebook, which provides access to all internal and external databases.
Chapter 11—SQL tools
Describes tools in ObjectStudio that allow you to create SQL statements. Chapter 12—Report Editor
Describes the Report Editor and how to use it. Appendix A—Cross-platform development
Discusses Windows® character set conversion. Index
Contents
Overview of database support... 12
How ObjectStudio supports databases... 12
Database classifications ... 12
Database object framework ... 13
Database objects ... 13
Table objects ... 14
Query objects ... 14
Cursor objects ... 14
Database tools ... 15
How ObjectStudio implements database support ... 16
Introduction ... 16
Supported databases... 17
ODBC database... 17
Oracle database ... 18
ADABAS database ... 19
IBM DB2 database... 19
Microsoft SQL Server database ... 20
SYBASE OpenClient database ... 20
Informix database ... 20
SUPRA SQL database ... 21
UniSQL Server database ... 21
Internal Database ... 21
Database classes... 22
Database class hierarchy ... 22
Database class ... 23
ExternalDatabase class ... 24
ODBCDatabase class... 24
OracleDatabase class ... 25
AdabasDatabase class... 25
ESDatabase class ... 25
SQLServerDatabase class ... 26
SybaseDatabase class ... 26
INFDatabase class ... 26
SupraDatabase class ... 26
Database User's Guide, P40-3203-03 5
ORDBDatabase class... 27
LocalDatabase class ... 27
InternalDatabase class... 27
Table classes ... 28
Table class hierarchy ... 29
Table class... 29
ExternalTable class ... 30
VectorTable class... 30
Cursor classes ... 31
Cursor class hierarchy ... 32
Cursor class... 33
Nonscrollable cursors ... 33
Scrollable cursors... 34
LocalCursor class ... 35
Query classes... 36
Query class ... 37
SqlDirect class ... 37
SqlParse class ... 37
SQL Query classes ... 38
SqlSelect class ... 39
SqlSubSelect class ... 39
SqlUpdate class ... 39
Working with databases... 40
Introduction ... 40
Loading external database support... 40
Connecting to a DBMS ... 42
Connecting options... 42
Database-specific connection information ... 43
Accessing a database ... 45
accessName: ... 45
directory ... 45
visibleTablesAt:put:... 46
Performing transactions... 48
Using SQL to query databases ... 49
Methods for executing SQL statements ... 49
Creating strings containing SQL code ... 51
Using SQL versus using cursors ... 52
Executing SQL with a local database... 52
Database User's Guide, P40-3203-03 6
Working with cursors ... 53
Data format returned... 53
Cursor messages ... 53
Methods for cursor support ... 54
Types of cursors ... 55
Using cursors with ODBC ... 55
Using cursors with SQL Server ... 55
Using cursors with Informix ... 55
Selecting multiple tables to create a cursor, in all databases except UniSQL ... 56
Selecting multiple tables to create a cursor, in UniSQL ... 57
Working with tables... 58
Linking to cursors and tables ... 59
Types of links ... 59
Creating a normal link... 60
Creating an update link ... 61
Enhancing performance ... 62
Handling errors ... 62
Packaging applications ... 63
Including login controllers in the image ... 63
Delaying initialization of the DLL ... 64
Delaying a database login... 65
ODBC ... 66
Introduction ... 66
ODBC elements ... 66
ODBC conformance levels... 67
API conformance levels... 67
ODBC SQL grammar conformance levels... 68
ObjectStudio supports all ODBC conformance levels ... 68
ObjectStudio ODBCDatabase and driver conformance-level dependencies ... 68
Low-level ODBC support... 69
Additional ODBC classes... 70
Typical session... 71
Data type mapping ... 73
System catalog access ... 74
Example of using stored procedures ... 75
Parametric SQL statements... 76
Cursors and scrollable cursors... 80
Working with Binary Large Objects (BLOBs) ... 82
Enabling ODBC Support ... 82
Using chunks ... 82
Handling errors ... 85
Database User's Guide, P40-3203-03 7
DB2 ... 86
Introduction ... 86
Extended services ... 86
Cursors ... 86
ORDER BY clause and Extended Services database cursors ... 86
Support for DB2 and Cursors with Hold ... 86
Manually binding the DB2 files ... 87
Descriptions of the bind file pairs to use in manual binding ... 87
Performing the manual binding ... 89
Granting database access to users other than yourself ... 90
Cataloging databases ... 91
Uncataloging databases ... 92
Executing stored procedures ... 92
Methods to execute DB2 procedures ... 93
Considerations for parameters used by stored procedures ... 94
Examples of DB2 stored procedures ... 94
Informix ... 95
Introduction ... 95
Looking for Informix databases ... 95
Connecting to Informix databases ... 95
Transaction processing: commit and rollback ... 95
Executing stored procedures ... 96
SUPRA SQL ... 97
Introduction ... 97
Working with SUPRA SQL string columns ... 98
ASCII/EBCDIC/BYTE designations and SUPRA SQL character columns... 98
FLOAT precision in SUPRA SQL ... 98
Avoiding COMMIT WORK RELEASE and ROLLBACK WORK RELEASE ... 98
Using multiple SUPRA SQL sessions ... 98
SUPRA SQL class reference ... 99
Introduction ... 99
SupraDatabase class ...100
SupraDatabaseCursor class...114
SupraLogonController class ...119
SupraScrollableCursor class...126
SupraStringColumn class ...131
SupraTable class...136
Database User's Guide, P40-3203-03 8
UniSQL Server... 145
Introduction ...145
Using the lock_timeout_in_secs_parameter ...146
Report editor considerations ...146
UniSQL Server class reference ...147
Introduction ...147
ORDBDatabase class...148
ORDBDatabaseCursor class...162
ORDBLogonController class ...168
ORDBScrollableCursor class ...174
ORDBTable class ...179
Other databases ... 186
Introduction ...186
Oracle and Oracle OCI support...187
Oracle support ...187
Oracle OCI support ...192
ADABAS support...196
SQL Server support...196
Logging on using Windows Authentication ...196
Looking for SQL Server databases ...196
Message and error blocks ...197
MicroDecisionware access...199
Microsoft SQL Server wrapper sets local host name ...199
SYBASE OpenClient support...200
Message and error blocks ...200
Database Notebook ... 202
Introduction ...202
Using the Database Notebook ...203
Database Notebook pop-up menu...203
Creating a new database...204
Creating and modifying a table ...206
Saving changes to the Internal Database ...210
Entering data ...211
Accessing the default data entry form...211
Customizing the Data Entry dialog box ...213
Managing data ...214
Opening the default Data Manager ...214
Customizing the Data Manager Form ...216
Creating a SQL query ...217
Using the SQL tools...217
Using the SQL Browser...218
Database User's Guide, P40-3203-03 9
SQL tools ... 220
Introduction ...220
SQL Editor ...220
Creating an SQL statement ...221
Using the Selection dialog box ...224
Executing a statement...233
Defining a WHERE clause...234
Defining a JOIN clause...236
Defining a GROUP BY clause ...238
Defining a HAVING clause ...238
Defining an ORDER BY clause...239
Creating parametric SQL statements...240
Committing changes ...242
Rolling back changes...242
Importing and exporting statements ...243
Creating a report for the statement ...243
SQL Window ...244
File menu ...244
Actions menu...244
Creating an SQL statement ...245
Loading an ASCII text file into the SQL Window ...245
Report Editor... 246
Using the Report Editor ...246
Creating a report ...247
Saving reports...249
Working with report sections...250
Level breaks...250
Adding or removing sections...251
Formatting sections ...251
Using level breaks ...252
Working with report items ...256
Adding report items...257
Resizing report items ...258
Deleting report items ...258
Copying or moving report items...259
Formatting report items ...260
Formatting multi-line string items...262
Formatting graphic items ...263
Formatting lines and topic boxes ...264
Creating and formatting bitmapped images ...265
Registering a graphics file ...267
Database User's Guide, P40-3203-03 10
Defining and formatting graphs and graph legends ...268
Placing a graphics field...268
Defining a graphics field ...269
Formatting graphics fields ...269
Formatting graphics legends...271
Formatting, previewing, and printing a report ...272
Formatting report pages ...272
Previewing a report ...274
Printing from the Report Preview ...274
Setting the report timer...275
Setting output options...277
Printing or previewing a report ...278
Cross-platform development... 279
Windows character set conversion ...279
Index ... 280
Database User's Guide, P40-3203-03 11
1
Overview of database support
How ObjectStudio supports databases
Support for each database is a loadable application (or package, if using the Repository) containing class and method definitions that allow you to work with that specific database.
Features of ObjectStudio database support include:
♦ Easy porting of an application from one database to another.
♦ The ability to access more than one database simultaneously, whether of the same type or of different types.
Database classifications
ObjectStudio classifies databases as either:
♦ Local. There is one local database (the Internal Database) for prototyping. The Internal Database allows you to design and test an application without consuming valuable server resources. The Internal Database is limited in size by the amount of memory in your system.
♦ External. There are a number of external databases supported by
ObjectStudio.
Database User's Guide, P40-3203-03 12
Chapter: Overview of database support Section: How ObjectStudio supports databases
Database object framework
ObjectStudio implements the following classes to support database connections:
♦ Database ♦ Table ♦ Query ♦ Cursor
This structure matches typical relational database objects and provides a common frame of reference for working with databases.
For each supported database, ObjectStudio provides subclasses of each of these classes. Use these classes to define the access layer of an application. For more information, see “Database classes” on page 22.
Database objects
Each database that ObjectStudio supports is represented as a subclass of class
Database. When you open a connection to a specific database, ObjectStudio creates an instance of the appropriate Database subclass.
You can send messages to Database objects to open cursors, execute SQL statements, and begin and end transactions. Database objects also maintain information regarding the differences between database types.
Database User's Guide, P40-3203-03 13
Chapter: Overview of database support Section: Database object framework
Table objects
Databases contain Table objects that represent the structure of each table within a database. A Table object describes a database table’s columns and the data type of each column, but it does not contain the actual data.
You can query a Table object for its attributes, including column information and records. You can add, remove, and modify records directly through the Table object, or you can perform these functions using a combination of SQL statements and cursors.
For external databases, using SQL statements can be more efficient than working with Table objects.
Query objects
Query objects allow you to save SQL queries as objects. You can create a link to a query, either visually using the Designer, or with a method-based Model View Controller (MVC) interface. You can pass a Query object to a database for execution, or you can use a Query object to open a cursor. Queries can include parameters. Associated with each parameter is a block of Smalltalk code that is executed dynamically to get the parameter value when the query is performed.
Cursor objects
Cursor objects are used to process a result set, which is the set of records obtained by executing a query. When you work with cursors, the DBMS keeps the result set. This allows ObjectStudio to work with one record at a time. Cursors are useful when you are working with a large result set, enabling you to read, update, and delete individual records.
Database User's Guide, P40-3203-03 14
Chapter: Overview of database support Section: Database object framework
Database tools
ObjectStudio provides database tools for data definition and data
manipulation. Use these tools to work with application data after you define the data access layer of an ObjectStudio application.
The database tools include:
♦ Database Notebook. Data management facility that builds a default form
for any Table or Query. Use the default form to perform data manipulation and data entry. You can customize the form for inclusion into an end-user application.
♦ SQL Editor. Graphical query builder that allows you to construct Query
objects. You can include the Query objects within an application framework.
♦ Report Editor. Facility for creating database reports.
Database User's Guide, P40-3203-03 15
Chapter: Overview of database support Section: Database tools
2
How ObjectStudio implements
database support
Introduction
This chapter describes the databases and the classes that ObjectStudio supports. If you are using a database that is no longer supported by the database vendor (for example, DB2 Database Version 2.1 or Sybase OpenClient Version 10), refer to the ObjectStudio Release Notes, P40-3208.
Database User's Guide, P40-3203-03 16
Chapter: How ObjectStudio implements database support Section: Introduction
Supported databases
This section provides a brief overview of each database that ObjectStudio supports. Specifications are supplied for each database, including:
♦ Loadable application (Package, if using the Repository)
♦ Subclass of Database ♦ Subclass of Table ♦ Subclass of Cursor
ObjectStudio uses a common object model to support DBMS and database connections. The model implements abstract classes to support Databases,
Tables, Cursors, and Queries. Use these classes to create the database access layer of an application.
Support for each database is implemented as a loadable application (or package, if using the Repository). For more information on loading databases, see “Loading external database support” on page 40.
ODBC database
Loadable
application/Package:
ODBC
Subclass of Database: ODBCDatabase
Subclass of Table: ODBCTable
Subclass of Cursor: ODBCCursor
ODBCScrollableCursor
Database User's Guide, P40-3203-03 17
Chapter: How ObjectStudio implements database support Section: Supported databases
Oracle database
Loadable
application/Package:
Oracle Database Client 8.1.5
Oracle Database Client 8.1.5 (ORACLE Mode) Oracle Database Client 9.2
Oracle Database Client 9.2 (ORACLE Mode) Oracle Database Client (OCI)
Subclass of Database: OracleDatabase
Subclass of Table: OracleTable
Subclass of Cursor: OracleDatabaseCursor OracleScrollableCursor
ANSI and Oracle Mode database wrappers. See “ANSI and Oracle Mode loadable applications” on page 187 for information on:
♦ Oracle Database Client 8.1.5 loadable application vs. Oracle Database Client 8.1.5 (ORACLE Mode) loadable application
♦ Oracle Database Client 9.2 loadable application vs. Oracle Database Client 9.2 (ORACLE Mode) loadable application
Oracle Database Client (OCI). For more information, see “Oracle OCI support” on page 192. Version Note: Oracle 8.1.5 is the first Oracle release with which the Oracle OCI database wrapper will work. However, the Oracle OCI database wrapper should work with subsequent releases of Oracle.
Unsupported Oracle database wrappers that are still available as goodies.
Cincom has removed the following loadable applications from ObjectStudio’s loadable application list:
♦ Oracle Database Client 7.3
♦ Oracle Database Client 7.3 (ORACLE Mode)
♦ Oracle Database Client 8.0
♦ Oracle Database Client 8.0 (ORACLE Mode)
Cincom no longer supports the databases wrappers loaded by these
applications. However, these loadable applications are still available in the Goodies folder.
Database User's Guide, P40-3203-03 18
Chapter: How ObjectStudio implements database support Section: Supported databases
ADABAS database
Loadable
application/Package:
Adabas Database
Subclass of Database: AdabasDatabase
Subclass of Table: AdabasTable
Subclass of Cursor: AdabasDatabaseCursor AdabasScrollableCursor
IBM DB2 database
Loadable
application/Package:
DB2 Database Version 6.1
DB2 Database Version 6.1 (Cursor with Hold) DB2 Database Version 7.2
DB2 Database Version 7.2 (Cursor with Hold)
Subclass of Database: ESDatabase
Subclass of Table: ESTable
Subclass of Cursor: ESDatabaseCursor ESScrollableCursor
“Cursor with Hold” loadable applications. According to the ANSI standard, a
database must close and destroy a Cursor when you perform a commit on the database. However, when you use a “Cursor with Hold” loadable application for DB2 6.1 or 7.2, DB2 can both keep open and update a database Cursor when you perform a commit. When DB2 does this, you may see a performance improvement over the ANSI standard behavior.
Unsupported DB2 database wrapper that is still available as a goody.
Cincom has removed the DB2 Database Version 5.0 loadable application from ObjectStudio’s loadable application list. Although Cincom no longer supports the database wrapper loaded by this application, this loadable application is still available in the Goodies folder.
Database User's Guide, P40-3203-03 19
Chapter: How ObjectStudio implements database support Section: Supported databases
Microsoft SQL Server database
Loadable
application/Package: MS SQL Server Database
Subclass of Database: SQLServerDatabase
Subclass of Table: SQLServerTable
Subclass of Cursor: SQLServerDatabaseCursor SQLServerScrollableCursor
You can use the “MS SQL Server Database” wrapper with SQL Server 6.5, 7.0, or 2000. However, this wrapper supports SQL Server 7.0 and 2000 only at the SQL Server 6.5 level. Cincom has not enhanced the Microsoft library, used by ObjectStudio, for SQL Server 7.0 and 2000.
SYBASE OpenClient database
Loadable
application/Package:
SYBASE OpenClient Version 11.5 SYBASE OpenClient Version 12.5
Subclass of Database: SybaseDatabase
Subclass of Table: SybaseTable
Subclass of Cursor: SybaseDatabaseCursor SybaseScrollableCursor
Informix database
Loadable
application/Package:
Informix Client Version 7.12 Informix Client Version 7.3
Subclass of Database: INFDatabase
Subclass of Table: INFTable
Subclass of Cursor: INFDatabaseCursor INFScrollableCursor
Database User's Guide, P40-3203-03 20
Chapter: How ObjectStudio implements database support Section: Supported databases
SUPRA SQL database
Loadable
application/Package:
SUPRA SQL 2720 SUPRA SQL 2800 SUPRA SQL 2900
Subclass of Database: SupraDatabase
Subclass of Table: SupraTable
Subclass of Cursor: SupraDatabaseCursor SupraScrollableCursor
UniSQL Server database
Loadable
application/Package:
UniSQL 3.5.3
Subclass of Database: ORDBDatabase
Subclass of Table: ORDBTable
Subclass of Cursor: ORDBDatabaseCursor ORDBScrollableCursor
Internal Database
Loadable
application/Package:
None (already loaded)
Subclass of Database: InternalDatabase
Subclass of Table: Not applicable
Subclass of Cursor: Not applicable
Database User's Guide, P40-3203-03 21
Chapter: How ObjectStudio implements database support Section: Supported databases
Database classes
The database classes have the following features:
♦ They implement methods that open cursors, execute SQL statements, and begin and end transactions.
♦ They contain Table objects that represent each table within a database. You can retrieve and manipulate these tables within ObjectStudio.
Database class hierarchy
The Database class hierarchy is:
Database (Abstract)
ExternalDatabase (Abstract)
ODBCDatabase OracleDatabase AdabasDatabase ESDatabase
SQLServerDatabase SybaseDatabase INFDatabase SupraDatabase ORDBDatabase LocalDatabase (Abstract)
InternalDatabase
The remainder of this section describes the classes in the Database class hierarchy.
Database User's Guide, P40-3203-03 22
Chapter: How ObjectStudio implements database support Section: Database classes
Database class
The Database class is an abstract class, which defines the basic functions for its subclasses. All subclasses of Database inherit the following features from Database:
♦ Ability to track all accessible databases
♦ Logon and Logoff functions (if they are needed)
♦ Ability to track the database types that are loaded in ObjectStudio An instance of the Database class:
♦ Contains instances of subclasses of classTable that represent each table in the physical database.
♦ Executes an SQL string.
♦ Creates a cursor as part of executing an SQL SELECT statement (optionally). The cursor, which is a direct connection to the result set, allows the user to update the database.
Database User's Guide, P40-3203-03 23
Chapter: How ObjectStudio implements database support Section: Database classes
ExternalDatabase class
The ExternalDatabase class is an abstract class that implements features specific to external databases. All external database classes are subclasses of this class.
The main difference between the ExternalDatabase and LocalDatabase classes is that ExternalDatabase passes SQL statements directly to the physical database. The LocalDatabase class includes a query evaluator.
The ExternalDatabase class adds itself to the StartStopAnnouncementList global variable when the class is loaded. If you then save this image with active databases, ObjectStudio will try to reconnect to those databases on startup. For details about how this is implemented, refer to the start and stop class methods in the ExternalDatabase class. For more information about how StartStopAnnouncementList can be used in ObjectStudio, refer to the ObjectStudio User’s Guide, P40-3201.
Class ExternalDatabase uses the variable DataLoadLimit to restrict the number of rows returned by an SQL query. The default maximum number of rows is 500. To change the value, send the setDataLoadLimitTo: class message. ExternalDatabase allows you to use the Visible Tables feature to tell ObjectStudio with which tables you want to work. You can use this feature when the database has a large number of tables to prevent ObjectStudio from querying the physical database to determine the name of each table. For more information on this feature, see “Enhancing performance” on page 62.
ODBCDatabase class
The ODBCDatabase class implements the access layer for the complete Microsoft ODBC Version 2.5 Application Programming Interface (API). It provides you with easy access to the X/Open-compliant Call Level Interface (CLI) to SQL databases and to Microsoft extensions to this standard, as specified in the ODBC Version 2.5 specification document.
From ObjectStudio, you can use either high-level support or low-level support for ODBC. High-level support works with the ODBCDatabase class. You may want to use high-level support if you have already implemented database code in ObjectStudio.
With low-level support, you program directly to the SQL Access Group (SAG) CLI. For more information on low-level support, see “Low-level ODBC support” on page 69.
Database User's Guide, P40-3203-03 24
Chapter: How ObjectStudio implements database support Section: Database classes
OracleDatabase class
The OracleDatabase class implements the access layer for Oracle databases. In addition to the features it inherits, this class supports:
♦ Execution of PL/SQL blocks, stored procedures, and functions
♦ Ability to set the number of records retrieved using arrayFetch with
execSql: and loadSql:
♦ Ability to set the maximum number of characters returned for a LONG column
♦ Logon methods and the name of an ObjectStudio Controller to use for logging in to the database
♦ Ability to gain access to an instance of OracleDatabase on login
AdabasDatabase class
The AdabasDatabase class implements the access layer for ADABAS databases using the Oracle API. See the preceding “OracleDatabase class” section for access layer information.
ESDatabase class
The ESDatabase class implements the access layer for the IBM DB2 database. In addition to the features it inherits, this class supports:
♦ Ability to execute stored procedures.
♦ Inserting the user ID and password in the class so that you can log in to the database without using a login window. For NT servers, you must include the user ID and password.
Database User's Guide, P40-3203-03 25
Chapter: How ObjectStudio implements database support Section: Database classes
SQLServerDatabase class
The SQLServerDatabase class implements the access layer for the Microsoft SQL Server database. In addition to the features it inherits, this class supports:
♦ Ability to execute stored procedures and retrieve multiple result sets.
♦ Logon methods and the name of an ObjectStudio Controller to use for logging in to the database.
With Microsoft SQL Server, you log in to a server rather than to a particular database. All databases on that server become available through
ObjectStudio as instances of this class.
♦ A getServers method to return all known SQL Servers on the network. Each of these servers is queried for their available databases. This method is used primarily by the logon Controller.
SybaseDatabase class
The SybaseDatabase class implements the access layer for the SYBASE
OpenClient database. In addition to the features it inherits, this class supports:
♦ Ability to execute stored procedures and retrieve multiple result sets.
♦ Logon methods and the name of an ObjectStudio controller to use for logging in to the database.
With SYBASE OpenClient databases, you log in to a server rather than to a particular database. All databases on that server become available through ObjectStudio as instances of this class.
INFDatabase class
The INFDatabase class implements the access layer for the Informix database. In addition to the features it inherits, this class supports the ability to execute stored procedures.
SupraDatabase class
The SupraDatabase class implements the access layer for the SUPRA SQL
database.
Database User's Guide, P40-3203-03 26
Chapter: How ObjectStudio implements database support Section: Database classes
ORDBDatabase class
The ORDBDatabase class implements the access layer for the UniSQL Server
database.
LocalDatabase class
The LocalDatabase class is an abstract class that implements features specific to databases that require their own SQL query evaluator. LocalDatabase implements the query evaluator as instance methods, which are inherited by all its subclasses.
InternalDatabase class
The InternalDatabase class provides a mechanism for treating objects as if they were tables. The Internal Database is extremely useful for prototyping when you are developing an application. You can also use the Internal Database to work with data that resides in more than one database.
The Internal Database, however, does not have the features of a real DBMS, such as locking, facilities for multiple users, and transaction control. It also does not save its data to files on disk. To interact with the Internal Database, use the Database Notebook, as described in “Using the Database Notebook” on page 203.
The InternalDatabase class supports a collection of instances of classTable. In every ObjectStudio environment, there is a single instance of the
InternalDatabase class, called EnfinInternalDb. If an instance of class Table is a member of this database, it can be included in SQL queries against the Internal Database.
The InternalDatabase class implements the tableLocations variable. When an instance of the InternalDatabase class is asked for a particular table, it first looks to see if the table exists. If the table does not exist, it looks in
tableLocations to see if the table is referenced there. If it exists, it uses the tableLocations variable to load a class that recreates the table. This variable allows internal tables to be loaded on demand. ObjectStudio supplies several example tables that work with the Internal Database and are handled this way.
Database User's Guide, P40-3203-03 27
Chapter: How ObjectStudio implements database support Section: Database classes
Table classes
There is a Table subclass for each type of supported database. For all
databases, each Table class maintains information about the external column types supported by the database and can map the column types into
ObjectStudio objects. The Table instances for the Internal Databasealso contain each table’s data.
The Table classes implement:
♦ The dbTablesAt: method, which retrieves a Table instance from its associated database
♦ Methods that query for attributes, including column information and records
♦ Methods that add, remove, and modify records directly
♦ Methods that handle SQL statements and cursors
Table classes allow you to link to tables using the Designer or using a programmatic Model View Controller (MVC) interface.
Database User's Guide, P40-3203-03 28
Chapter: How ObjectStudio implements database support Section: Table classes
Table class hierarchy
The Table class hierarchy is:
Table (ObjectStudio Internal Table)
ExternalTable (Abstract Class) ADABASTable
ESTable
INFTable
ODBCTable
OracleTable
ORDBTable
SQLServerTable
SupraTable
SybaseTable
VectorTable
The remainder of this section describes the classes in the Table class hierarchy.
Table class
The Table class is an internal ObjectStudio abstract class that supports a table structure. It provides methods for table creation and modification, record insertion, record deletion, and record modification. Tables can also be saved to and loaded from disk. Subclasses of Table inherit its methods.
To create a Table, send the execSQL: method to an instance of class
InternalDatabase or ExternalDatabase. The method returns an instance of Table.
Database User's Guide, P40-3203-03 29
Chapter: How ObjectStudio implements database support Section: Table classes
ExternalTable class
The ExternalTable class is an abstract class that provides the framework for tables associated with objects of class ExternalDatabase. It also allows you to manage cursors for use in all record access methods. To use the cursor methods, you first must send the startAccessForUpdate: message.
The following table lists the subclasses of ExternalTable and the databases to which they correlate:
Database Subclass of ExternalTable
ADABAS ADABASTable
DB2 ESTable
Informix INFTable
ODBC ODBCTable
Oracle OracleTable
SQL Server SQLServerTable
SUPRA SupraTable
SYBASE SybaseTable
UniSQL ORDBTable
VectorTable class
The VectorTable class is a special type of internal table class that stores table data by column rather than by row. VectorTable stores numeric columns as vectors and stores nonnumeric columns as arrays. This strategy saves space because numeric columns can be stored as single objects.
The interfaces to VectorTable and Table are nearly identical. Therefore, you can use the two classes interchangeably. At times, using VectorTable is more efficient because accessing data by row can be slower than accessing a Table object. This is because the rows must be constructed as needed.
One way to create an instance of VectorTable is to use the return value (a VectorTable) of loadSql: (a message that you send to an instance of Database).
Database User's Guide, P40-3203-03 30
Chapter: How ObjectStudio implements database support Section: Table classes
Cursor classes
A cursor is a common DBMS mechanism that returns rows of a result set one row at a time. The result set of a cursor exists on the DBMS. The ObjectStudio Cursor classes allow the control of the cursor object (the result set) that resides on the DBMS.
Usually, the cursor mechanism is vendor-specific. ObjectStudio Cursor classes for different DBMSs operate in basically the same manner.
You open a cursor by sending a variation of the openCursor message to a database and by providing an SQL SELECT statement. Once a cursor is open, you can use it to position the current row in the result set, to update column values for the current row, and to delete the current row.
For more information on using cursors, see “Working with cursors” on page 53.
Database User's Guide, P40-3203-03 31
Chapter: How ObjectStudio implements database support Section: Cursor classes
Cursor class hierarchy
The Cursor class hierarchy is:
Cursor (Abstract Class)
ExternalDatabaseCursor (Abstract Class)
AdabasDatabaseCursor ESDatabaseCursor
ExtDbScrollableCursor (Abstract Class) ADABASScrollableCursor ESScrollableCursor
INFScrollableCursor
ODBCScrollableCursor
OracleScrollableCursor ORDBScrollableCursor
SQLServerScrollableCursor SupraScrollableCursor SybaseScrollableCursor INFDatabaseCursor
ODBCCursor
OracleDatabaseCursor ORDBDatabaseCursor SQLServerDatabaseCursor SupraDatabaseCursor SybaseDatabaseCursor
LocalCursor (Abstract Class)
The remainder of this section describes the classes in the Cursor class hierarchy.
Database User's Guide, P40-3203-03 32
Chapter: How ObjectStudio implements database support Section: Cursor classes
Cursor class
The Cursor class is an abstract class that provides basic features for all database cursors. The class keeps track of the query that created the cursor, including its field names, types, and formats. It maintains a current position in the result set, and it contains the necessary machinery for ObjectStudio DesignerMVC links.
Nonscrollable cursors
This section describes classes that implement nonscrollable cursors. ExternalDatabaseCursor class
The ExternalDatabaseCursor class is an abstract class that implements features for external database nonscrollable cursors. In addition to the features it inherits, it implements features that:
♦ Add records
♦ Perform positioned updates and deletes
♦ Move the record pointer forward to the next record Other nonscrollable cursor subclasses
The following table lists the subclasses of ExternalDatabaseCursor and the databases to which they correlate. Each of these subclasses represents a nonscrollable cursor.
Database Subclass of ExternalDatabaseCursor
ADABAS AdabasDatabaseCursor
DB2 ESDatabaseCursor
Informix INFDatabaseCursor
ODBC ODBCCursor
Oracle OracleDatabaseCursor
SQL Server SQLServerDatabaseCursor
SUPRA SupraDatabaseCursor
SYBASE SybaseDatabaseCursor
UniSQL ORDBDatabaseCursor
Database User's Guide, P40-3203-03 33
Chapter: How ObjectStudio implements database support Section: Cursor classes
Scrollable cursors
This section describes classes that implement scrollable cursors. ExtDbScrollableCursor class
The ExtDbScrollableCursor class is an abstract class that implements features for external database scrollable cursors. In addition to the features it inherits, it implements features that:
♦ Add records
♦ Perform positioned updates and deletes
♦ Ask for the size of the result set
♦ Move the record pointer to any position in the result set ODBCScrollableCursor class
The ODBCScrollableCursor class uses native scrollable cursors (that is, cursors that are supplied by the database driver) if the data source offers the following features:
♦ ODBC API call SQLExtendedFetch
♦ Two fetch options:
- SQL_FD_FETCH_NEXT - SQL_FD_FETCH_PREV
♦ At least one of the following scroll options: - SQL_SO_KEYSET_DRIVEN
- SQL_SO_DYNAMIC - SQL_SO_MIXED
Otherwise, ObjectStudio provides a simulated scrollable cursor, which is based on native fetch-forward-only cursors. To determine whether the database driver complies with the features described in the previous list, send the message nativeScrollableCursors to class ODBCDatabase.
Database User's Guide, P40-3203-03 34
Chapter: How ObjectStudio implements database support Section: Cursor classes
Other scrollable cursor subclasses
The following table lists the subclasses of ExtDbScrollableCursor and the databases to which they correlate. Each of these subclasses represents a scrollable cursor.
Database Subclass of ExtDbScrollableCursor
ADABAS ADABASScrollableCursor
DB2 ESScrollableCursor
Informix INFScrollableCursor
ODBC ODBCScrollableCursor
Oracle OracleScrollableCursor
SQL Server SQLServerScrollableCursor
SUPRA SupraScrollableCursor
SYBASE SybaseScrollableCursor
UniSQL ORDBScrollableCursor
LocalCursor class
The LocalCursor class is an abstract class that implements cursors for local database cursors. The class implements methods that:
♦ Add records
♦ Perform positioned updates and deletes
♦ Move the record pointer to any position in the result set
Database User's Guide, P40-3203-03 35
Chapter: How ObjectStudio implements database support Section: Cursor classes
Query classes
The Query classes provide a mechanism for saving SQL queries and linking to them. You can implement the links either visually, by using the Designer, or programmatically, by working with the MVC interface. You can pass a query object to a database for execution or to open a cursor.
The Query class hierarchy is:
Query (Abstract Class)
SqlDirect
SqlParse (Abstract Class) SqlDelete
SqlInsert SqlSelect
SqlSubSelect SqlUpdate
The remainder of this section describes the classes in the Query class hierarchy.
Database User's Guide, P40-3203-03 36
Chapter: How ObjectStudio implements database support Section: Query classes
Query class
The Query class is an abstract class that implements the basic features of queries. Primarily, it keeps track of all instances of its subclasses.
SqlDirect class
The SqlDirect class provides the ability to create an SQL object for a string that cannot be parsed by ObjectStudio. This includes all non-ANSI-standard SQL statements such as stored procedure access for SQL Server and PL/SQL for Oracle. SqlDirect implements a creation routine, the new: class method, which takes the SQL string as a parameter.
SqlParse class
The SqlParse class is an abstract class that provides features for all query types that can be parsed by ObjectStudio. The class includes the query parser and some default behavior.
To create an instance of SqlParse (or one of its subclasses), send the
parseString: class method. This method takes an SQL string and, depending on the type of SQL statement, either generates an error or an instance of one of the SqlParse subclasses.
Database User's Guide, P40-3203-03 37
Chapter: How ObjectStudio implements database support Section: Query classes
SQL Query classes
The following table lists the SQL Query classes and the SQL queries that they represent:
Query class Query type
SqlDelete SQL DELETE
SqlInsert SQL INSERT
SqlSelect SQL SELECT
SqlSubSelect SQL SUBSELECT
SqlUpdate SQL UPDATE
Note the following about SQL Query classes:
♦ The easiest way to create an instance of each of these classes is to use the SQL Editor, which is described in “SQL Editor” on page 220.
♦ You can create an SQL object by sending the parseString: message to the Query class or to one of its subclasses. The parameter is an SQL string.
♦ To execute an SQL query, send execute to an instance of the Query class or one of its subclasses.
Database User's Guide, P40-3203-03 38
Chapter: How ObjectStudio implements database support Section: Query classes
SqlSelect class
In addition to using the execute message, you can use one of the
“openCursor…” or “openScrollableCursor…” messages to pass an SQL SELECT statement to a DBMS. You can also use the Designer to link to an SqlSelect object.
You can associate a cursor with an SqlSelect instance. The first time the startAccessForUpdate:scrollable: message is sent to an SqlSelect object, a cursor is opened and returned. You can specify that a cursor is updateable or scrollable in the original startAccess method, or you can change the cursor in subsequent sends. The cursor is shared with all callers of the
startAccessForUpdate:scrollable: message.
Add dependencies to the cursor rather than to the SqlSelect object. This ensures that all objects using the query are using a common cursor and that updates to the cursor are reflected in all objects using it. A refresh message is also supported by SqlSelect objects; it rebuilds the associated cursor and updates all its dependencies.
SqlSubSelect class
Instances of the SqlSubSelect class provide for subselects within SQL
statements. Generally, they are used internally only within other SQL objects.
SqlUpdate class
Instances of the SqlUpdate class provide for the SQL INSERT statement. Use the
execSql: message to pass an SqlUpdate query to a database.
Database User's Guide, P40-3203-03 39
Chapter: How ObjectStudio implements database support Section: Query classes
3
Working with databases
Introduction
This chapter provides information on techniques to use when you work with databases. These techniques apply to all database platforms. Where appropriate, there is additional information necessary for working with a specific database.
Loading external database support
Before you can work with an external database, you must load an application that supports access to a specific DBMS into the ObjectStudio environment. The Internal Databaseis already loaded into the ObjectStudio environment. For more information on the Internal Database, see “Internal Database” on page 21 and “InternalDatabase class” on page 27.
After loading the application that supports your underlying database, you have complete access to the databases and tables associated with your database management system (to the limits defined by your database administrator). For a complete list of supported databases and gateways, see “Supported databases” on page 17.
Database User's Guide, P40-3203-03 40
Chapter: Working with databases Section: Introduction
To load a database application:
1. Ensure the external database is available, either locally or through a network connection. (See your network administrator if you need help.) 2. Load the database application:
A. Display the Repository Explorer window by selecting Repository ⇒ Explore from the Desktop menu.
B. From the Package pull-down list box, select the name of the package that corresponds to the DBMS with which you want to work.
C. Select a version in the Versions area of the Repository Explorer window.
D. Press mouse button 2 and select Load ⇒ Selected Version.
A. Display the Application dialog box by selecting File ⇒ Load application from the Desktop menu.
B. From the Applications dialog box, select the name of the loadable application that corresponds to the DBMS with which you want to work. C. Click Load.
As the application loads, ObjectStudio:
♦ Creates the subclasses of Database, Table, Cursor, and Query for the DBMS with which you are working
♦ Links to the dynamic link libraries (DLLs) that provide client support for the DBMS
♦ Initiates the login procedure, if applicable, to the database
3. If a database logon interface appears, enter the requested information. If your underlying database requires you to log on, ObjectStudio creates a logon interface on the work area of the Desktop. The logon interface opens automatically if you attempt to access the database without logging on. To access your external database every time you start ObjectStudio, save an image file after loading the application. For more information on saving the ObjectStudio image, refer to the ObjectStudio User’s Guide, P40-3201.
Database User's Guide, P40-3203-03 41
Chapter: Working with databases
Connecting to a DBMS
This section describes how to log in to a DBMS from ObjectStudio. Logging in involves identifying the server on which the database is installed and
initializing communications to that server.
Each database has its own login procedure. ObjectStudio provides methods that you can use with most of the databases that ObjectStudio supports.
After you log in to a database, select the specific database that you want to access. For a description of this process, see “Accessing a database” on page 45.
You do not need to log in to the Internal Database. For more information on the Internal Database, see “Internal Database” on page 21 and
“InternalDatabase class” on page 27.
Connecting options
There are two ways in which you can connect to a database:
♦ Programmatically ♦ With a controller
Connecting programmatically
You can log in to a database programmatically, without using the ObjectStudio-supplied login controller. To do so, use the Class Browser to search for the login messages for the database you are using.
Connecting with a controller
For most DBMSs, you can display a login controller (a user interface) that prompts for a user name, a password, and a server name.
ObjectStudio provides the following Database class methods that allow you to work with a login controller for the DBMS with which you are working:
♦ hasLogonView. Returns a Boolean value indicating whether the database
has a controller for logging in associated with it.
♦ logonView. Returns the controller that allows a user to log in to a
database. Include this controller in the image that you create for the application.
♦ initialize. Opens the login controller for the database. When the user
clicks OK on the controller, ObjectStudio logs the user in to the database.
Database User's Guide, P40-3203-03 42
Chapter: Working with databases Section: Connecting to a DBMS
Database-specific connection information
Each database has a specific login procedure:
♦ Oracle. When you log in to an Oracle database, type an SQL*Net connect
string in the server entry field. If you do not provide an SQL*Net string, a local connection is assumed.
♦ ADABAS. When you log in to an ADABAS database, type an SQL*Net
connect string in the server entry field. If you do not provide an SQL*Net string, a local connection is assumed.
♦ IBM DB2. When you send the directory message to the ESDatabaseclass, it returns an instance of the class ESDatabase for each database that has been cataloged on the workstation. Only one of these databases can be active at a time.
♦ SQL Server. The SQLServerDatabase class provides a getServers method that returns a list of all SQL Servers available on the network. The login controller uses this method to display a list of available servers. The login controller provides a list of SQL Servers found only on Windows. For more information, see “Looking for SQL Server databases” on page 196.
♦ SYBASE OpenClient. When you log in to a SYBASE OpenClient database,
enter the name of the SYBASE Server in the server entry field. You also need to enter a user name and a password. The database name will be case-sensitive.
♦ Informix. Informix-Online Workgroup Server must be installed either on
your computer or on another computer to which your computer is
connected over a network. Informix automatically verifies your user ID and password. It uses the information you selected in the Informix client software program SetNet32. After the Informix application is loaded, use the ExternalDatabase>>accessName: method to establish a connection. Here is an example that will connect to the ‘stores7’ database on server ‘demo’:
INFDatabase accessName: #'stores7@demo'.
If a connection fails, verify that the user ID and the password are defined to the Informix Online Workgroup server with the required privileges.
Database User's Guide, P40-3203-03 43
Chapter: Working with databases Section: Connecting to a DBMS
♦ SUPRA SQL. With SUPRA SQL database wrapper support, you can log on up to eight databases concurrently. Each logon records the user name,
password, lock mode, and timeout values, which are used when
SupraDatabase objects are created (a connection to SUPRA SQL is established when a SupraDatabase object is created). You can access multiple databases by creating multiple SupraDatabase objects and specifying a different database name for each SupraDatabase object. Logging on to SUPRA SQL does not establish a connection to a SUPRA SQL database. The logon only saves the user name, password, lock mode, and timeout values for later use when a SupraDatabase object is created. If multiple databases are used, a logon may be required before each SupraDatabase object is created in order to specify these values for each SUPRA SQL database.
The SUPRA SQL logon window allows the user name, password, lock mode, and timeout values to be entered. Refer to the CONNECT statement section in the SUPRA Server SQL Commands Reference Manual, P26-2420, for more information on each of these variables.
♦ UniSQL Server. Consider the following:
- With UniSQL Server database wrapper support, you log in to one database server at a time. This login records the user name and password, which are used later when you access the database. If you do not enter a user name and password, the UniSQL Server default user name and a password are used.
- From the UniSQL Server Logon window, you can reset the user name and password back to the UniSQL Server default by pressing the OK button without specifying a user name and password.
- Sending the “directory” message to the ORDBDatabase class provides a list of available databases you can access.
- The database name will be case-sensitive.
♦ Internal Database. You do not need to log in to the Internal Database.
Database User's Guide, P40-3203-03 44
Chapter: Working with databases Section: Connecting to a DBMS
Accessing a database
This section describes how to select the specific database with which to work. This process is also called making a database active. In programmatic terms, when you access a database, ObjectStudio creates an instance of the
appropriate subclass of Database.
ObjectStudio allows you to access one database of a given type at a time. However, you can access more than one database type at a time. For example, you can access only one ODBC database at a time, but you can access an ODBC database and an Oracle database simultaneously.
The subclasses of Database support the following class methods that help you access a database.
accessName:
The parameter is an instance of class Symbol that represents the name of the database you want to access. On success, the method returns an instance of the appropriate subclass of Database. If the method is unsuccessful, it returns an instance of Message, which contains an error message.
The accessName: method can place locks on data. After performing an accessName:, you may want to perform the commit method to release those locks. For more information on the commit method, see “Performing
transactions” on page 48.
directory
Returns an array of symbols representing names of available databases.
Usually, you develop an application that uses a specific database, so you do not need to use this method. The Database Notebook is an example of an
application that uses this method.
Database User's Guide, P40-3203-03 45
Chapter: Working with databases Section: Accessing a database
visibleTablesAt:put:
This method is implemented in ExternalDatabase and its subclasses.
Use this method when the application is working with a large database but only needs to use some of the data. Perform this method before performing the
accessName: method to restrict the tables of a database with which
ObjectStudio interacts. You can also perform the method at any time to change the visible tables for the database.
For example:
ExternalDatabase visibleTablesAt: databaseName put: array
where:
databaseName is an instance of class Symbol that represents the database with which you are working.
array is an array of instances of class Symbol that represent qualified or unqualified table names. If the table names are not qualified, the current user is assumed to own the table. If they are qualified, they should be in the form:
#'owner.tablename'
Database User's Guide, P40-3203-03 46
Chapter: Working with databases Section: Accessing a database
The following table lists variations on the array parameter: Variation Use
Array of symbols
Prevents catalog access to the database. It limits tables to those listed in the array. Use this option before accessing the database to set initial table access, or at any time to change table access.
If the array includes an invalid table name, ObjectStudio creates an empty table with the invalid name. If the Database Notebookdisplays a table with no column names, or if you attempt to access a table and receive a “Table not found” message, check that all table names are specified or are qualified correctly.
nil Performs catalog access of the database. Instructs the system to ignore the visible tables list.
{ } (empty array)
Prevents catalog access and sets visibleTables to none. Use this option when no Table objects are needed.
If you are using execSql:, loadSql:, and cursors, exclusively, you do not need access to Table objects. Table objects are necessary only when you are linking to them, referring to them in code, or using the ObjectStudio Table tools (for example, the Database Notebook).
Database User's Guide, P40-3203-03 47
Chapter: Working with databases Section: Accessing a database
Performing transactions
ObjectStudio supports database transactions, which are units of work that the database can either save or undo. Traditionally, a transaction is performed this way:
1. Begin the transaction. 2. Perform the unit of work.
3. End the transaction (either save it or undo it). Ending a transaction can release data locks.
Transactions in ObjectStudio have the following features and restrictions:
♦ You do not have to declare the beginning of a transaction. The exception to this is SQL Server and SYBASE OpenClient support.
♦ You can perform several steps before you end the transaction.
♦ You cannot nest transactions.
Most database servers (except SQL Server and SYBASE OpenClient) do not require that transactions be started explicitly.
ObjectStudio provides the following instance methods in class Database to support transactions.
♦ beginTran. Begins a transaction. This method is required for SQL Server
and SYBASE OpenClient databases. It is implemented for other database platforms but does nothing.
♦ commit. Ends a transaction by saving the work you did since the last
commit or rollback.
The accessName: and dbTablesAt: methods can place locks on data. After performing these methods, you may want to perform the commit method to release those locks.
♦ rollback. Ends a transaction by undoing the work you did since the last
commit or rollback.
Local databases and transactions. Local databases do not perform
transactions. For local databases, the transaction methods beginTran, commit, and rollback are implemented but do nothing; they are provided for
compatibility with external databases.
Database User's Guide, P40-3203-03 48
Chapter: Working with databases Section: Performing transactions
Using SQL to query databases
This section describes how to interact directly with a database through its SQL interface.
Methods for executing SQL statements
ObjectStudio provides the following instance methods in subclasses of Database
that allow you to execute SQL statements on the DBMS:
♦ execSql: aString. Executes an SQL statement. The aString parameter is an
SQL string. The string can contain any statements that the target accepts. For more information on creating an SQL string, see “Creating strings containing SQL code” on page 51.
If the SQL statement is an INSERT statement, the method returns a small integer representing the return code.
If the SQL statement is a SELECT statement, the result of the method is an instance of Table. On some database platforms, an SQL statement can contain multiple clauses. The return value of a multiple-clause statement is an array of tables.
You can treat the resulting table like any other Table objectin the ObjectStudio environment. You can perform the following tasks with it: - Use the Table method interface.
- Add the table to the Internal Database and perform subsequent SQL statements on it. When you use this technique, subsequent SQL statements are performed in memory and do not require additional fetches from the original database.
- Link to the table using ObjectStudio TableLinks.
The instance of Table has an instance variable, dbRecords, which is an array. Each element of the array is also an array and represents a record in the table:
{ {Row 1 elements} {Row 2 elements} ... }
Database User's Guide, P40-3203-03 49
Chapter: Working with databases Section: Using SQL to query databases
♦ execSql: aString onError: aBlock. Executes an SQL statement in the same
manner as execSql: but also allows you to specify a 1-parameter block. If an error occurs during the execution of the SQL statement, ObjectStudio passes the error code to the block and performs the code in the block.
♦ execSql: aString vars: vars. Executes an SQL statement (which cannot, in
this case, be a select statement) in the same manner as execSql: but also allows you to specify parameters. These parameters must be bound for execution. The vars array contains the string values to be bound to the SQL statement.
Subclasses of ExternalDatabase that support execSql:vars:. Only two
subclasses of ExternalDatabase, ESDatabase and OracleDatabase, really support execSql:vars:. Calling this method from other subclasses of ExternalDatabase will result in an error.
♦ loadSql: aString. Executes an SQL SELECT statement in the same manner
as execSql: and returns an instance of the class VectorTable. VectorTable is a special type of internal table that stores table data by column rather than by row. The dbRecords instance variable has the following format:
{ {Column 1 elements} {Column 2 elements} ... }
VectorTable provides an interface that is almost identical to that of internal tables, so that you can use the two interchangeably. The advantage of using a VectorTable is that it stores numeric columns as vectors, rather than as arrays. VectorTable is efficient for dealing with numeric data, because a numeric column is one object.
However, VectorTable is slower than regular Tables for working with individual rows. To work with a row in a VectorTable, ObjectStudio must select one element from each column array or vector.
♦ loadSql: aString onError: aBlock. Executes an SQL SELECT statement in
the same manner as loadSql: and returns an instance of the class
VectorTable. It also allows you to specify a 1-parameter block. If an error occurs during the execution of the SQL statement, ObjectStudio passes the error code to the block and performs the code in the block.
♦ setDataLoadLimitTo:. Sets the maximum number of rows to return from
an SQL SELECT statement by assigning a value to the variable dataLoadLimit. The default value is 500.
This method is for subclasses of ExternalDatabase only.
Database User's Guide, P40-3203-03 50
Chapter: Working with databases Section: Using SQL to query databases
Creating strings containing SQL code
The first parameter to the execSql: or loadSql: methods is a string containing SQL code. This section provides information about creating an SQL string. Using standard SQL
Recall that some database platforms allow variations in SQL code. If you are writing SQL code that you may want to use on more than one database platform, remember to write SQL code that is standard across platforms. Creating the string
An SQL string is a standard Smalltalk string that you create by using standard string-construction methods, for example:
str := 'EXEC SQL' + ' SELECT *'
Specifying parameters
Database platforms can have different requirements for specifying certain types of data. For example, the format for specifying a date within an SQL statement is different for each database platform.
Use the method asDBStringFor: to format data into SQL strings for each supported database. When you use this method, you ensure platform independence in the application you are creating. You also ensure that the format of data is acceptable to the database.
Use the asDBStringFor: method to format each parameter of an SQL statement. For example, the following code creates and executes an SQL SELECT
statement with a date that is formatted correctly for a specific database:
result := db execSql:
'select * from Employees where bDate =' + (myDateObj asDBStringFor: db).
Database User's Guide, P40-3203-03 51
Chapter: Working with databases Section: Using SQL to query databases