DBInputTable

Available in Community Designer

Short Description
Ports
Metadata
DBInputTable Attributes
Details
Examples
Best Practices
See also

Short Description

DBInputTable unloads data from database using JDBC driver.

Component Data source Input ports Output ports Each to all outputs Different to different outputs Transformation Transf. req. Java CTL Auto-propagated metadata
DBInputTabledatabase0-11-n
yes
no
no
no
no
no
no

Icon

Ports

Port typeNumberRequiredDescriptionMetadata
Input0-1
no
Incoming queries to be used in the SQL query attribute. When the input port is connected, Query URL should be specified as e.g. port:$0.fieldName:discrete. See Reading from Input Port.
Output0
yes
for correct data recordsequal metadata
1-n
no
for correct data records

Metadata

DBInputTable does not propagate metadata.

DBInputTable has no metadata templates.

Output metadata can use Autofilling Functions

DBInputTable Attributes

AttributeReqDescriptionPossible values
Basic
DB connection
yes
ID of the database connection to be used to access the database 
SQL query[ 1] The SQL query defined in the graph. See SQL Query Editor for detailed information.  
Query URL [ 1] The name of an external file, including the path, defining SQL query. 
Query source charset 

Encoding of an external file defining the SQL query.

The default encoding depends on DEFAULT_CHARSET_DECODER in defaultProperties.

UTF-8 | <other encodings>
Data policy  Determines what should be done when an error occurs. See Data Policy for more information. Strict (default) | Controlled [ 2] | Lenient
Print statement The SQL statements will be written to the log, if the option is enabled. false (default) | true
Advanced
Fetch size Specifies the number of records that should be fetched from the database at once.20 | 1-N
Incremental file[ 3]The name of the file storing the incremental key, including the path. See Incremental Reading. 
Incremental key[ 3]The Variable storing the position of the last read record. See Incremental Reading. 
Auto commit By default, your SQL queries are committed immediately. If you need to perform more operations inside one transaction, switch this attribute to false. true (default) | false

[ 1] At least one of these attributes must be specified. If both are defined, only Query URL is applied.

[ 2] Controlled data policy in DBInputTable does not send error records to the edge. Errors are written into the log.

[ 3] Either both or neither of these attributes must be specified.

Details

DBInputTable unloads data from a database table using an SQL query or by specifying a database table and defining a mapping of database columns to Clover fields. It can send unloaded records to all connected output ports.

Defining Query Attributes

  • Query Statement without Mapping

    When the order of CloverETL metadata fields and database columns in select statement is the same and data types are compatible, implicit mapping can be used which performs positional mapping. A standard SQL query syntax should be used:

    • select * from table [where dbfieldJ = ? and dbfieldK = somevalue]

    • select column3, column1, column2, ... from table [where dbfieldJ = ? and dbfieldK = somevalue]

    See SQL Query Editor for information about how the SQL query can be defined.

  • Query Statement with Mapping

    If you want to map database fields to clover fields even for multiple tables, the query will look like this:

    select $cloverfieldA:=table1.dbfieldP, $cloverfieldC:=table1.dbfieldS, ... , $cloverfieldM:=table2.dbfieldU, $cloverfieldM:=table3.dbfieldV from table1, table2, table3 [where table1.dbfieldJ = ? and table2.dbfieldU = somevalue]

    See SQL Query Editor for information about how SQL query can be defined.

Dollar Sign in DB Table Name

  • A single dollar sign in a table name must be escaped by another dollar sign; therefore every dollar sign in a database table name will be transformed to double dollar signs in the generated query. Meaning that each query must contain an even number of dollar signs in the DB table (consisting of adjacent pairs of dollars).

[Important]Important

When connecting to MS SQL Server, it is recommended to use jTDS driver . It is an open source 100% pure Java JDBC driver for Microsoft SQL Server and Sybase. It is faster than Microsoft's driver.

SQL Query Editor

For defining the SQL query attribute, SQL query editor can be used.

The editor opens after clicking the SQL query attribute row:

On the left side, there is the Database schema pane containing information about schemas, tables, columns, and data types of these columns.

Displayed schemas, tables, and columns can be filtered using the values in the ALL combo, the Filter in view textarea, the Filter, and Reset buttons, etc.

You can select any columns by expanding schemas, tables and clicking Ctrl+Click on desired columns.

Adjacent columns can also be selected by clicking Shift+Click on the first and the last item.

Then you need to click Generate after which a query will appear in the Query pane.

Generated Query with Question Marks

Figure 53.7. Generated Query with Question Marks


The query may contain question marks if any db columns differ from output metadata fields. Output metadata are visible in the Output metadata pane on the right side.

Drag and drop the fields from the Output metadata pane to the corresponding places in the Query pane and then manually remove the "$?:=" characters. See following figure:

Generated Query with Output Fields

Figure 53.8. Generated Query with Output Fields


You can also type a where statement to the query.

The buttons underneath allow you to validate the query (Validate) or view data in the table (View).

Examples

Read Records from Database
Read Query from Input Port

Read Records from Database

By generating a query in DBInputTable, read the name, location and height in feet of mountains from the MountainsDB database.

Solution

Use the DB connection and SQL query attributes.

AttributeValue
DB connectionSee Creating Internal Database Connections.
SQL queryUse Generate query button in SQL query editor.

In the output metadata, create the name, location and heightft fields. Set their data types to string, string and integer respectively.

Click on the SQL query property and open the SQL query editor. Select the MountainDB database in the Database schema pane.

Select the mountain, location and heightft fields and click the Generate query button.

[Note]Note

If the output metadata fields have different names and/or data types, the generated query will contain question mark(s). See SQL Query Editor.

[Tip]Tip

You can modify the generated query by adding other keywords, e.g. ASC, DESC, etc.

You can validate the generated query and view the results by clicking the respective buttons in the lower left side of the SQL query editor.

Set the File URL path of the FlatFileWriter to the external file.

Read Query from Input Port

A query is automatically generated into an external file. Read the query from the file and write the results into another file.

Solution

Use the DB connection and Query URL attributes.

AttributeValue
DB connectionSee Creating Internal Database Connections.
Query URLport:$0.field1:discrete

Set the File URL path of the FlatFileReader to the external file containing the query.

According to the table above, set the DB connection and Query URL attributes of the DBInputTable.

Set the File URL path of the FlatFileWriter to the external source of the query.

Input metadata should contain one field in which the query will be written.

Output metadata should contain a number of fields equivalent to columns selected in the query.

[Tip]Tip

Make sure that the EOF as delimiter property in the input metadata is set to true.

[Note]Note

DBInputTable can only read one query per source file.

Best Practices

If Query URL attribute is used, we recommend users to explicitly specify Query source charset.

See also

DBOutputTable
DBExecute
Common Properties of Components
Specific Attribute Types
Common Properties of Readers
Readers Comparison
Database Connections