Database: Write to DB Output Adapter

The Write to Database adapter writes information to an external database server.

This adapter is an in-process adapter. The Server starts it automatically when necessary. Attach this adapter to a stream by using commands inside Sybase CEP Studio. Properties for this adapter are set using Sybase CEP Studio.

The adapter properties are listed in the table below.

Property Name (screen)

Property Name (Attach Adapter)

Type

Description

Query

Query

String

Required. The query (for example, INSERT statement) that you want to run on the external database server. This statement must be written in the language (for example, SQL) of the external database server, not in CCL. For example, do not use a CCL Database Statement ("EXECUTE STATEMENT DATABASE...") as the query.

DBName

DBName

String

Required. Database name. This must be the name of a service defined in the c8-services.xml file. The service information includes information about how to connect to the external database server and the name of the database to connect to.

Commit frequency

CommitFrequency

Integer

Optional. If this field is left empty or is set to 0, Sybase CEP Server sends a commit for each row sent to the external database server. If you want to commit every N rows (for example, every 3rd row) rather than every row, then enter the desired value of N (for example, 3) into this field. See more information about Commit Frequency below.

The query is usually an INSERT statement that inserts values into the external database server. The INSERT statement typically contains placeholders for values; when a new row arrives in the stream associated with this output adapter, values in that stream are substituted for the placeholders in the INSERT statement.

For example, the query might look like:

INSERT INTO table1 (col1, col2)
VALUES (?streamColA, ?streamColB);

If the Write To DB output adapter is on a stream named StockStream, then when a new row arrives in StockStream, the values from streamColA and StreamColB in StockStream will be substituted for the query properties "?streamColA" and "?streamColB", and the query will be sent to the external database server and executed there.

You can use statements other than INSERT. For example, you can use UPDATE or DELETE. You can also call stored procedures or other statements on the external database server. You could even use a SELECT statement as the query; however, since this is an output adapter, no values from the external server are returned, and thus a SELECT statement probably would not do anything useful. Similarly, calling a function whose sole effect is to return a value probably would not do anything useful, either.

The database name property must be the name of a service configured in the c8-services.xml file. For more information about configuring a service to provide access to a database on an external database server, see the Sybase CEP Installation Guide .

See Datatype Mappings for tables that show which database data types correspond to Sybase CEP's data types.

More Information about Commit Frequency

If you set the commit frequency to a value larger than 0, then the adapter performs commit operations either when the specified number of rows have been sent, or when the queue of rows to write to the database is empty. This prevents ready-to-be-committed rows from having to wait indefinitely until the number of rows to be committed reaches N.

Warning!  

Uncommitted rows are not committed when a project is stopped. For example, suppose that you set the commit frequency to 5 minutes. As the project runs, it writes to the database every five minutes. However, when the project is stopped, a final commit is not executed. If the project stops two minutes after the most recent commit, then the most recent two minutes of database writes are not committed.