Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The "Database Feature", which is not part of the default Odysseus, must be installed before. See also How to install a new feature

There are two possibilities how to use a database connection. For the one hand, you can create a persistent connection and reuse this connection in other queries. On the other hand, you can directly create a connection for each query. First, we show how to create and drop persistent connections and show how to use them in PQL and StreamSQL(CQL). Afterwards, we show how to directly setup a connection using PQL.

Open and drop persistent database connections

...

There are different drivers for different DBMS (at the moment for MySQL, Postgres and Oracle) that can be used with a more confortable syntax. For example, the following query creates a connection with the name con1 to a MySQL server on localhost (this is an implicit setting of the driver) with a database called test:

Code Block
#PARSER CQL
#TRANSCFG Standard
#QUERY
CREATE DATABASE CONNECTION con1 AS mysql TO test

...

Code Block
DROP DATABASE CONNECTION conname

 

Using a connection in PQL

Reading from a database

If you want to read from a database, you may use the DATABASESOURCE operator. For an existing connection called "con1" we can read from the table called "main":

Code Block
datastream := DATABASESOURCE({connection='con1', table='main'})

To reuse

Using a connection in StreamSQL (CQL)