PK
W,Aoa, mimetypeapplication/epub+zipPK W,A iTunesMetadata.plistZ
This section summarizes new features and functionality of Oracle TimesTen In-Memory Database 11g Release 2 (11.2.2) that are documented in this guide, providing links into the guide for more information.
LOB support
TimesTen supports LOBs (large objects). This includes CLOBs (character LOBs), NCLOBs (national character LOBs), and BLOBs (binary LOBs).
For details of support in TTClasses, refer to "Working with LOBs".
Deprecation of non-persistent XLA
Features for XLA non-persistent mode have been deprecated and removed from the documentation. Use utilities and APIs for persistent XLA only.
This chapter provides information to help you get started with your TTClasses development environment.
TTClasses comes compiled and preconfigured during TimesTen installation. If you have a different C++ runtime than what TTClasses was compiled with, recompile the library using the make
(UNIX) or nmake
(Microsoft Windows) utility.
The information here includes a discussion of environment variables and compilation for TTClasses itself, information for compiling and linking your TTClasses applications, and an introduction to the Quick Start demo applications for TTClasses. The following topics are covered:
This section discusses how to set up TTClasses, covering the following topics:
This section covers the following topics for setting up TTClasses in a UNIX environment:
To use TTClasses, ensure that your shell environment variables are set correctly. You can optionally use one of the following scripts or add a line to use one of these scripts in your login initialization script (for example, .profile
or .cshrc
), where install_dir
is your TimesTen installation directory.
install_dir/bin/ttenv.sh (sh/ksh/bash) install_dir/bin/ttenv.csh (csh/tcsh)
If you have application linking problems, which can be caused by using a different C++ runtime than what TTClasses was compiled with, recompile the library using the make
utility.
To recompile TTClasses, change to the ttclasses
directory, where install_dir
is your TimesTen installation directory:
$ cd install_dir/ttclasses
Run make clean
for a fresh start:
$ make clean
Recompile TTClasses for direct connections as follows:
$ make
To recompile TTClasses for client/server connections, use the MakefileCS
Makefile:
$ make -f MakefileCS
The following make
target options are available when you compile TTClasses in a UNIX environment:
all
: Build a shared optimized library or libraries (default). Use this with Makefile
for direct connections, or with MakefileCS
for client/server connections.
shared_opt
: Build a shared optimized library. Currently this has the same effect as all
.
To specify a make
target, use the name of the make
target on the command line.
For example, to build a shared debug version of TTClasses:
$ make clean shared_debug
This section covers the following topics for setting up TTClasses in a Windows environment:
Note: On Windows, the TTClasses library is automatically installed after compilation. |
Before recompiling, ensure that the PATH
, INCLUDE
, and LIB
environment variables point to the correct Visual Studio directories. Execute the applicable Visual Studio C++ batch file (for example, VCVARS32.BAT
or VSVARS32.BAT
) to accomplish this.
Then set environment variables for TimesTen (if they were not already set during installation) by running the following:
install_dir\bin\ttenv.bat
If you have application linking problems, which can be caused by using a different C++ runtime than what TTClasses was compiled with, recompile the library using the nmake
utility.
To recompile TTClasses, change to the ttclasses
directory, where install_dir
is your TimesTen installation directory:
install_dir\ttclasses
Run nmake clean
for a fresh start:
install_dir\ttclasses> nmake clean
Then recompile. By default this is for both direct and client/server connections:
install_dir\ttclasses> nmake
The following make
target options are available when you compile TTClasses in a Windows environment.
all
: Build shared optimized libraries for direct and client/server connections (default).
client
: Build shared optimized library for client/server only.
msdm
: Build shared optimized library for Microsoft driver manager.
To specify a make
target, use the name of the make
target on the command line.
For example, to build only the client/server TTClasses library:
install_dir\ttclasses> nmake clean client
When necessary, you can modify the TTClasses Makefile manually to add flags for the TTClasses compiler macros. For UNIX, add -D
flagname
. For Windows, add /D
flagname
.
This section includes information about the following compiler macros:
TTC_USE_STRINGSTREAM, USE_OLD_CPP_STREAMS: For C++ I/O streams
TTDEBUG: Generate additional debugging and error checking logic
Compile TTClasses, as well as your applications, with the -DTTEXCEPT
flag to make TTClasses throw C++ exceptions. (TTClasses is compiled this way by default.) Put {try/catch}
blocks around all TTClasses function calls and catch exceptions of type TTStatus
.
An alternative, although discouraged, mode of operation is to compile TTClasses and your application without TTEXCEPT
enabled. In this mode, error handling is accomplished using older method versions with an explicit TTStatus&
parameter, as in earlier TimesTen releases.
See "TTStatus".
There are multiple types of C++ streams and they are not compatible with each other. TimesTen provides two related flags. Which streams you use in your application determines which flag to set, or whether you should set neither, as follows (from newer stream types to older):
For streams where you are including <iostream>
and using the ostringstream
class, set the TTC_USE_STRINGSTREAM
flag.
For streams where you are including <iostream>
and using the ostrstream
class, set neither flag. This is the default for most platforms and compilers.
For streams where you are including <iostream.h>
and using the ostrstream
class, set the USE_OLD_CPP_STREAMS
flag. This is the default for some older platforms and compilers.
Check your TTClasses Makefile. If the flags are not set properly, then update the Makefile as appropriate, recompile TTClasses, and replace the previous TTClasses library file with the recompiled one.
Also see the subsections that follow.
This compiler flag is for use with C++ compilers that reliably support C++ stream types utilizing the ostringstream
class. If your program uses C++ stream code and you include <iostream>
and use the ostringstream
class, then TTClasses must be compiled with the -DTTC_USE_STRINGSTREAM
setting.
Also note that in this case, the USE_OLD_CPP_STREAMS
flag must not be set.
Note: Withgcc version 3.2 and higher, the TTC_USE_STRINGSTREAM flag is set by default in the file install_dir /include/ttclasses/TTIostream.h . |
If your program uses C++ stream code and you include <iostream>
and use the ostrstream
class, neither the TTC_USE_STRINGSTREAM
flag nor the USE_OLD_CPP_STREAMS
flag should be set.
This compiler flag is for older C++ compilers that do not support <iostream>
. If your program uses old C++ stream code and you include <iostream.h>
and use the ostrstream
class, then TTClasses must be compiled with the -DUSE_OLD_CPP_STREAMS
setting.
Also note that in this case, the TTC_USE_STRINGSTREAM
flag must not be set.
Compile TTClasses with -DTTDEBUG
to generate extra debugging information. This extra information reduces performance somewhat, so use this flag only in development (not production) systems.
Compile TTClasses with -DTT_64BIT
if you are writing a 64-bit TimesTen application.
The following compiler macros are specific to a particular platform or compiler combination. You should not have to specify these compiler macros manually. Their use is determined by the Makefile chosen by the configure
program.
gcc
: Compile TTClasses with the -DGCC
flag when using gcc
on any platform.
This section discusses how to compile and link your TTClasses applications on UNIX and Windows, including a section on considerations when using the ODBC driver manager on Windows.
You can also refer to the following sections in Oracle TimesTen In-Memory Database C Developer's Guide for related information:
"Linking options" for general information about TimesTen linking options, such as using the direct driver versus the client driver or, on Windows, whether to use a driver manager
For compiling your applications, include the TTClasses header files that are in the install_dir
/include/ttclasses
directory. You can accomplish this simply by including TTInclude.h
from that directory, as follows.
Use the following compile command:
-Iinstall_dir/include
And use the following line in your code:
#include <ttclasses/TTInclude.h>
TTClasses XLA programs must also include the following:
#include <ttclasses/TTXla.h>
The following table summarizes the TTClasses libraries available for linking your applications on UNIX platforms.
Usage | Library |
---|---|
TimesTen direct connections | libttclasses.so |
TimesTen client/server connections | libttclassesCS.so |
The -L
option tells the linker to search the TimesTen lib
directory for library files. The -lttclassesCS
option links in the driver.
On Solaris, the default TimesTen ODBC client driver was compiled with Studio 11. The library enables you to link an application compiled with the Sun Studio 11 C/C++ compiler directly with the TimesTen client.
On AIX, when linking applications with the TimesTen ODBC client driver, the C++ runtime library must be included in the link command (because the client driver is written in C++ and AIX does not link it automatically) and must follow the client driver:
-Linstall_dir/lib -lttclassesCS -lC_r
You can use the Makefile in the quickstart/sample_code/ttclasses
directory to guide you in creating your own Makefile.
For compiling your applications, include the TTClasses header files that are in the install_dir
\include\ttclasses
directory. You can accomplish this simply by including TTInclude.h
from that directory, as follows.
Use the following compile command:
/Iinstall_dir\include
And use the following line in your code:
#include <ttclasses/TTInclude.h>
TTClasses XLA programs must also include the following:
#include <ttclasses/TTXla.h>
The following table summarizes the TTClasses libraries available for linking your applications on Windows platforms.
Usage | Library |
---|---|
TimesTen direct connections | ttclasses1122.lib |
TimesTen client/server connections | ttclasses1122CS.lib |
Microsoft ODBC driver manager | ttclasses1122DM.lib
See the next section, "Considerations when using an ODBC driver manager (Windows)". |
Add the appropriate library, for example install_dir
\lib\ttclasses1122.lib
, to your link command.
You can use the Makefile in the quickstart\sample_code\ttclasses
directory to guide you in creating your own Makefile.
Be aware of the following limitations in TTClasses when you use the ODBC driver manager on Windows. (These restrictions do not apply to the demo ttdm
driver manager supplied with the TimesTen Quick Start.)
XLA functionality is not supported.
REF CURSOR functionality is not supported.
The driver manager does not support LOB locator APIs or LOB data types, which are not part of the ODBC standard. However, you can use the LOB simple data interface as documented in "Working with LOBs".
In addition, the driver manager does not support the ODBC C types SQL_C_BIGINT
and SQL_C_TINYINT
when used with TimesTen. When using the driver manager, you cannot call methods that use either of these data types in their signatures, such as the applicable overloaded versions of any of the following TTCmd
methods: getColumn()
, getColumnNullable()
, getNextColumn()
, getNextColumnNullable()
, setParam()
, getParam()
, and BindParameter()
.
Note: TimesTen supplies a driver manager for both Windows and UNIX with the Quick Start sample applications. This driver manager is not fully supported. It is limited to support for the TimesTen direct driver and client driver only. It does not have the functionality or performance limitations described above. Applications that must concurrently use both direct connections and client/server connections can use this driver manager to achieve this with very little impact on performance. |
After you have configured your C++ environment, you can confirm that everything is set up correctly by compiling and running the TimesTen Quick Start demo applications. Refer to the Quick Start welcome page at install_dir
/quickstart.html
, especially the links under SAMPLE PROGRAMS, for information about the following.
Demo schema and setup: The build_sampledb
script (.sh
on UNIX or .bat
on Windows) creates a sample database and demo schema. You must use this before you start using the demos.
Demo environment and setup: The ttquickstartenv
script (.sh
or .csh
on UNIX or .bat
on Windows), a superset of the ttenv
script generally used for TimesTen setup, sets up the demo environment. You must use this each time you enter a session where you want to compile or run any of the demos.
Demos and setup: TimesTen provides demos for TTClasses and XLA in subdirectories under the install_dir
/quickstart/sample_code
directory. For instructions on compiling and running the demos, see the README files in the subdirectories.
What the demos do: A synopsis of each demo is provided when you click TTClasses (C++) under SAMPLE PROGRAMS.
This reference chapter contains descriptions of TTClasses external classes and their methods. It is divided into the following sections:
Note: Most methods documented in this chapter also support a signature with aTTStatus& parameter at the end of the calling sequence. This is for situations when you want to suppress exceptions for the method call and instead process the TTStatus object manually for errors. These signatures are not specifically documented, however, because this is not a recommended mode of use. For additional information and an example, see the "Usage" section under "TTStatus". |
This section discusses the following classes:
The TTGlobal
class provides a logging facility within TTClasses.
The TTGlobal
logging facility can be very useful for debugging problems inside a TTClasses program. Note, however, that the most verbose logging levels (TTLog::TTLOG_INFO
and TTLog::TTLOG_DEBUG
) can generate an extremely large amount of output. Use these logging levels during development or when trying to diagnose a bug. They are not appropriate for most production environments.
When logging from a multithreaded program, you may encounter a problem where log output from different program threads is intermingled when written to disk. To alleviate this problem, disable ostream
buffering with the ios_base::unitbuf
I/O stream manipulator, as in the following example, which sends TTClasses logging to the app_log.txt
file at logging level TTLog::TTLOG_ERR
.
ofstream log_file("app_log.txt"); log_file << std::ios_base::unitbuf; TTGlobal::setLogStream(log_file); TTGlobal::setLogLevel(TTLog::TTLOG_ERR);
See "Using TTClasses logging" for more information about using TTGlobal
.
Method | Description |
---|---|
disableLogging() | Disables TTClasses logging. |
setLogLevel() | Specifies the verbosity level of TTClasses logging. |
setLogStream() | Specifies where TTClasses logging information should be sent. |
sqlhenv() | Returns the underlying ODBC environment object (type SQLHENV ). |
static void disableLogging()
This method disables all TTClasses logging. Note that the following two statements are identical:
TTGlobal::disableLogging(); TTGlobal::setLogLevel(TTLog::TTLOG_NIL);
static void setLogLevel(TTLog::TTLOG_LEVEL level)
This method specifies the verbosity level of TTClasses logging. Table 3-1 describes TTClasses logging levels. The levels are cumulative.
Table 3-1 TTClasses logging levels
Logging level | Description |
---|---|
|
There is no logging. |
|
Logs fatal errors (serious misuse of TTClasses methods). |
|
Logs all errors, such as |
|
(Default) Also logs warnings and all calls to |
|
Also logs informational messages, such as calls to most methods on |
|
Also logs debugging information, such as all bound parameter values for each call to |
To set the logging level to TTLog::TTLOG_ERR
, for example, add the following line to your program:
TTGlobal::setLogLevel(TTLog::TTLOG_ERR);
static void setLogStream(ostream& stream)
Specifies where TTClasses logging information should be sent. By default, if TTClasses logging is enabled, logging is to stderr
. Using this method, an application can specify logging to a file (or any other ostream&
), such as in the following example that sets logging to app_log.txt
:
ofstream log_file("app_log.txt"); TTGlobal::setLogStream(log_file);
The TTStatus
class is used by other classes in the TTClasses library to catch error and warning exceptions. You can think of TTStatus
as a value-added C++ wrapper around the SQLError
ODBC function.
The preferred mode for TTClasses error handling is for a TTStatus
object to be thrown as an exception whenever an error or warning occurs. To accomplish this, the TTClasses library, as well as your applications, must be compiled with the TTEXCEPT
preprocessor variable enabled. (TTClasses is compiled this way by default.) This allows C++ applications to use {try/catch}
blocks to detect and recover from failure.
Example 3-1 shows typical use of TTStatus
. Also see Example 3-3.
Example 3-1 Exception handling
... TTCmd myCmd; try { myCmd.ExecuteImmediate(&conn, "create table dummy (c1 int)"); } catch (TTStatus st) { cerr << "Error creating table: " << st << endl; // Rollback, exit(), throw -- whatever is appropriate }
Another supported (but not typical) mode of use for TTStatus
, when TTEXCEPT
is enabled, is to selectively suppress exceptions and allow the application to manually check a TTStatus
object for error conditions. You can use this mode for a particular method call by initializing a TTStatus
object with the value TTStatus::DO_NOT_THROW
, then passing that object as the last parameter of a method call. Most TTClasses methods documented in this chapter also support a signature with this TTStatus&
parameter as the last parameter in the calling sequence.
Example 3-2 that follows shows this usage.
Example 3-2 Suppressing exceptions
... TTCmd myCmd; TTStatus myStat(TTStatus::DO_NOT_THROW); myCmd.ExecuteImmediate(&conn, "create table dummy (c1 int)", myStat); if (myStat.rc == SQL_ERROR) { // handle the error } ...
Another mode of operation, which is not recommended, is to compile TTClasses and your application without the TTEXCEPT
flag enabled. In this case, exceptions are not thrown, and the only way to process errors is through TTStatus&
parameters in your method calls. When you compile this way, the newer method signatures (without TTStatus&
parameters) are unavailable.
TTStatus
has the following subclasses:
TTError
is a subclass of TTStatus
and is used to encapsulate ODBC errors (return codes SQL_ERROR
and SQL_INVALID_HANDLE
).
TTWarning
is a subclass of TTStatus
and is used to encapsulate ODBC warnings (return code SQL_SUCCESS_WITH_INFO
).
ODBC warnings (the Return Receipt warning, for example) are usually not as serious as ODBC errors and should typically be handled with different logic. ODBC errors should be handled programmatically. There may be circumstances where handling ODBC warnings programmatically is warranted, but it is usually sufficient to simply log them.
Example 3-3 shows usage of the TTError
and TTWarning
subclasses.
Example 3-3 Exception handling, distinguishing between errors and warnings
This example shows the use of TTError
and TTWarning
. TTError
objects are thrown for ODBC errors. TTWarning
objects are thrown for ODBC warnings.
// catching TTError & TTWarning exceptions try { // some TTClasses method calls } catch (TTWarning warn) { cerr << "Warning encountered: " << warn << endl; } catch (TTError err) { // handle the error; this could be a serious problem }
Member | Description |
---|---|
rc | Return code from the failing ODBC call: SQL_SUCCESS , SQL_SUCCESS_WITH_INFO , SQL_ERROR , SQL_NO_DATA_FOUND , or SQL_INVALID_HANDLE |
native_error | TimesTen native error number (if any) for the failing ODBC call |
odbc_error | ODBC error state for the failing ODBC call |
err_msg | ASCII printable error message for the failing ODBC call |
TTSTATUS_ENUM | Enumeration for error status and error handling
Use the value |
Method | Description |
---|---|
isConnectionInvalid() | Indicates whether the database connection is invalid. |
ostream() | Prints errors to a stream. |
throwError() | Throws an error from the TTStatus object (not typical use). |
bool isConnectionInvalid() const
Returns TRUE
if the database connection is invalid, or FALSE
if it is valid. Specifically, "invalid" refers to situations when a TimesTen error 846 or 994 is encountered. See "Errors 0 - 999" in Oracle TimesTen In-Memory Database Error Messages and SNMP Traps for information about those errors.
friend ostream& operator<<(ostream&, TTStatus& stat)
This method prints the error to a stream.
void throwError()
This is an alternative, but not typical, way to throw an exception. In most cases the following two blocks of code are equivalent, but the former is more typical.
try { // ... if (/* something has gone wrong */) throw stat; } catch (TTStatus st) { cerr << "Caught exception: " << st << endl; }
Or:
try { // ... if (/* something has gone wrong */) stat.throwError(); } catch (TTStatus st) { cerr << "Caught exception: " << st << endl; }
The TTConnection
class encapsulates the concept of a connection to a database. You can think of TTConnection
as a value-added C++ wrapper around the ODBC connection handle (SQLHDBC
).
All applications that use TimesTen must create at least one TTConnection
object.
Multithreaded applications that use TimesTen from multiple threads simultaneously must create multiple TTConnection
objects. Use one of the following strategies:
Create one TTConnection
object for each thread when the thread is created.
Create a pool of TTConnection
objects when the application process starts. They are shared by the threads in the process. See "TTConnectionPool" for additional information about this option.
A TimesTen connection cannot be inherited from a parent process. If a process opens a database connection before creating (forking) a child process, the child cannot use the same connection. Any attempt by a child to use a database connection of a parent can cause application failure or a core dump.
Applications should not frequently make and then drop database connections, because connecting and disconnecting are both relatively expensive operations. In addition, short-lived connections eliminate the benefits of prepared statements. Instead, establish database connections at the beginning of the application process and reuse them for the life of the process.
Also see "Using TTCmd, TTConnection, and TTConnectionPool".
Note: If you must manipulate the underlying ODBC connection object directly, use theTTConnection::getHdbc() method. |
Privilege to connect to a database must be granted to users through the CREATE SESSION
privilege, either directly or through the PUBLIC
role. See "Access control for connections".
Member | Description |
---|---|
DRIVER_COMPLETION_ENUM | Specifies whether there will be a prompt for the database to connect to (also depending on whether a database is specified in the connect string).
Valid values are |
Method | Description |
---|---|
Commit() | Commits a transaction to the database. |
Connect() | Opens a new database connection. |
Disconnect() | Closes a database connection. |
DurableCommit() | Performs a durable commit operation on the database. |
getHdbc() | Returns the ODBC connection handle (type SQLHDBC ) associated with this connection. |
GetTTContext() | Returns the connection context value. |
isConnected() | Returns TRUE if the object is connected to TimesTen. |
Rollback() | Rolls back changes made to the database through this connection since the last call to Commit() or Rollback() . |
SetAutoCommitOff() | Disables autocommit for the connection. |
SetAutoCommitOn() | Enables autocommit for the connection. |
SetIsoReadCommitted() | Sets the transaction isolation level of the connection to be TXN_READ_COMMITTED . |
SetIsoSerializable() | Sets the transaction isolation level of the connection to be TXN_SERIALIZABLE . |
SetLockWait() | Sets the lock timeout interval for the connection by calling the ttLockWait TimesTen built-in procedure. |
SetPrefetchCloseOff() | Turns off the TT_PREFETCH_CLOSE connection option. |
SetPrefetchCloseOn() | Turns on the TT_PREFETCH_CLOSE connection option. This is useful for optimizing SELECT query performance for client/server connections to TimesTen. |
SetPrefetchCount() | Allows a user application to tune the number of rows that the TimesTen ODBC driver SQLFetch call will prefetch for a SELECT statement. |