solidDB Help : Programming : Transaction Logreader : Reading log data with the Logreader
  
Reading log data with the Logreader
The solidDB transaction log can be read by using SELECT statements.
The transaction log can be read by multiple concurrently active SELECT statements at the same time. Each log read can be started from a different log position, independently from any others.
Note The solidDB package contains a sample application that demonstrates the use of Logreader interface, see Logreader sample.
You can retrieve and output log data in a readable format by completing the following steps:
1 Read log data from the SYS_LOG table by using a SELECT statement with the following structure:.
SELECT RECID, RELID, FLAGS, LOGADDR, DATA FROM SYS_LOG WHERE LOGADDR > ?;
The WHERE condition is allowed only for the LOGADDR field, and the only constraint that is allowed is greater than (>).
You can start the log read from a specified log position that is defined with the LOGADDR field by doing the following steps:
a Retrieve the current LOGADDR value by using the following SELECT statement:
SELECT LOGADDR FROM SYS_LOG LIMIT 1;
The LOGADDR value is displayed, for example:
LOGADDR
-------
0000000000000001FFFFFFFF0000029500000295
1 rows fetched.
b Define the LOGADDR in the SELECT statement. For example:
SELECT RECID,RELID,FLAGS,LOGADDR,DATA FROM SYS_LOG WHERE LOGADDR > '0000000000000001FFFFFFFF0000029500000295';
When a read is started, the fetch calls start returning rows. The user data for the log record is included in the DATA column in binary format.
When no data is available, the server returns empty data in one second intervals. In such a case, you can execute a new fetch call to see if new data is available.
For more details on the DATA column and other columns in the SYS_LOG table, see SYS_LOG.
2 Reconstruct the user data from the rows that are returned by Logreader.
Note The exact steps for handling the log records depends on the application design. The following steps are the basic steps that are needed to output the user data in a format that can be used to process the log records further.
a Get metadata for the column by querying the solidDB system tables.
For example, in Java environments, the column metadata can be read from the solidDB system tables by using the ResultSet.getMetaData() call.
b Use the metadata to parse the data in the DATA column and produce output in the format of your choice.
For example, in the sample application, the log records are converted to plain text SQL statements, see Logreader sample.
Go up to
Transaction Logreader