Database: Poll From DB Input Adapter

The Poll From Database adapter reads information from a table on an external database server.

The adapter reads the table repeatedly, at intervals specified by the polling interval property. You can choose to read the entire table each time, or read only the rows that have been added since the last time that you read the table.

This adapter is an in-process adapter. The server starts it automatically when necessary. You attach this adapter to a stream by using commands inside Sybase CEP Studio, and properties for this adapter are set using Sybase CEP Studio. Alternatively, you may use the ATTACH ADAPTER statement to attach the adapter to a stream and specify the values of the adapter properties.

The adapter properties are listed in the table below:

Property Name (screen)

Property Name (Attach Adapter)

Type

Description

Query

Query

String

Required. This is the SQL query (for example, SELECT statement) that you want to run on the external database server. The order of fields that you retrieve should match the order of the fields in the stream to which you are writing. For example, the first field in the SELECT list of the SQL query should correspond to the first field in the schema of the stream.

DBName

DBName

String

Required. This indicates which database to execute the query on. This is the name of a service that is defined in the c8-services.xml file, not the name of the database. The service information will include information about how to connect to the external database server and the name of the database to connect to.

Poll Interval

PollInterval

Interval

Required. This indicates how frequently Sybase CEP Server should check the external database server for changes. The value can be a number of microseconds, or you can use standard INTERVAL values such as 100 milliseconds or 1 hour.

Counter field

CounterField

Integer or Long

This is the name of the counter/sequence number field. In the Sybase CEP schema, this is not the name of the field in the external table. The column's data type should be compatible with Sybase CEP's INTEGER or LONG data type.

Counter field initial value

CounterFieldInitValue

Integer or Long

If this field is set, then the first time that the query is executed, the adapter retrieves only records whose counter field contain values greater than the value specified in this Initial Value field. Data values equal to the Initial Value are not retrieved.) The initial value of the Counter Field may be either a LONG or an INTEGER, depending on the data type of the Counter Field.

Timestamp Field

TimestampField

String

This is the name of the timestamp/datetime column. In the Sybase CEP schema, this is not the name of the field in the external table. The column's data type should be compatible with Sybase CEP's TIMESTAMP data type. See Datatype Mappings for tables that show which database data types correspond to Sybase CEP's TIMESTAMP data type. The actual data type may have a resolution less than or equal to TIMESTAMP. If the resolution is greater than TIMESTAMP (for example, nanosecond vs. microsecond), you may get occasional cases of missing or duplicate records.

Timestamp field initial value

TimestampFieldInitValue

Timestamp

If this field is set, then the first time the query is executed, the adapter retrieves only records whose timestamp field contains values greater than the value specified in this Initial Value field. Data values equal to the Initial Value are not retrieved.

Note: Each input stream has a property (see the stream's Properties tab in Studio) that can specify whether to use the current server timestamp value instead of the row timestamp set by the adapter. If this stream property is set to true, it overrides any row timestamp set by the adapter

The query is usually a SELECT statement that will read values from the external database server.

For example, the query might look like:

SELECT col2 FROM StockTable WHERE col1 = 'IBM';

The query can also contain a statement other than SELECT. For example, you can call a stored procedure that returns values.

The Database Name property indicates which database to connect to. Despite the fact that we call this property the "Database Name", it is actually the name of a service which must be configured in the c8-services.xml file. The service name is not necessarily identical to the name of the database. Each service has information about how to connect to the external database server and the name of the database on that server. For more information about configuring a service to provide access to a database on an external database server, please see the Sybase CEP Installation Guide .

The poll interval specifies how frequently to read data from the external database server. You can set property values to specify whether you want the entire table re-read each time, or whether you want to read only the records added since the last time the table was read.

To read the entire table each time, leave the Counter Field, Counter Field Initial Value, Timestamp Field, and Timestamp Field Initial Value empty. This causes the adapter to read the entire external table at an interval specified by the Poll Interval property.

To read just the records that were added since the last time the table was read, please read the section below.