diff --git a/README.md b/README.md index 3d91dae..3decdfb 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,9 @@ The following options are available: `emitColumns` : When `true`, the column names in the `SELECT` statement are emitted as the first tuple in the resulting channel. +`trailingSemicolon` +: When `true`, append a semicolon `;` to the end of the SQL query if it is not present (default: `true`). + ### sqlInsert The `sqlInsert` operator collects the items in a source channel and inserts them into a SQL database. For example: diff --git a/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy b/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy index b9791f8..87b0bdb 100644 --- a/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy +++ b/plugins/nf-sqldb/src/main/nextflow/sql/ChannelSqlExtension.groovy @@ -47,7 +47,8 @@ class ChannelSqlExtension extends PluginExtensionPoint { db: CharSequence, emitColumns: Boolean, batchSize: Integer, - batchDelay: Integer + batchDelay: Integer, + trailingSemicolon: Boolean ] private static final Map INSERT_PARAMS = [ diff --git a/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy b/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy index d7ea945..8a26255 100644 --- a/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy +++ b/plugins/nf-sqldb/src/main/nextflow/sql/QueryHandler.groovy @@ -70,6 +70,7 @@ class QueryHandler implements QueryOp { private boolean emitColumns = false private Integer batchSize private long batchDelayMillis = 100 + private boolean trailingSemicolon = true private int queryCount @Override @@ -97,6 +98,8 @@ class QueryHandler implements QueryOp { this.batchSize = opts.batchSize as Integer if( opts.batchDelay ) this.batchDelayMillis = opts.batchDelay as long + if( opts.trailingSemicolon ) + this.trailingSemicolon = opts.trailingSemicolon as boolean return this } @@ -127,7 +130,7 @@ class QueryHandler implements QueryOp { if( !q ) throw new IllegalArgumentException("Missing query argument") def result = q.trim() - if( !result.endsWith(';') ) + if( trailingSemicolon && !result.endsWith(';') ) result += ';' return result }