diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f49ea1d..8154873 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,7 +40,7 @@ jobs: path: '*/target/**/*.jar' retention-days: 1 publish: - if: ${{ github.event_name != 'pull_request' }} && (github.repository == 'lucidsoftware/java-thread-context') }} + if: github.event_name != 'pull_request' && (github.repository == 'lucidsoftware/java-thread-context') needs: build runs-on: ubuntu-22.04 steps: @@ -60,7 +60,7 @@ jobs: SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} release: - if: ${{ startsWith(github.ref, 'refs/tags') && (github.repository == 'lucidsoftware/relate') }} + if: startsWith(github.ref, 'refs/tags') && (github.repository == 'lucidsoftware/relate') runs-on: ubuntu-latest needs: build steps: diff --git a/generate_sbt_opts.sh b/generate_sbt_opts.sh index 314d3e4..265a47b 100755 --- a/generate_sbt_opts.sh +++ b/generate_sbt_opts.sh @@ -4,4 +4,5 @@ if [[ $GITHUB_REF_TYPE = tag ]]; then else version="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}-SNAPSHOT" fi +version="${version//\//_}" echo "SBT_OPTS=-Dbuild.version=$version" >> $GITHUB_ENV diff --git a/relate/src/main/scala/com/lucidchart/relate/Parameters.scala b/relate/src/main/scala/com/lucidchart/relate/Parameters.scala index e1c2abe..c86354a 100644 --- a/relate/src/main/scala/com/lucidchart/relate/Parameters.scala +++ b/relate/src/main/scala/com/lucidchart/relate/Parameters.scala @@ -95,17 +95,13 @@ trait MultipleParameter extends Parameter { } class TupleParameter(val params: Iterable[SingleParameter]) extends MultipleParameter { - def appendPlaceholders(stringBuilder: StringBuilder) = { - val length = params.size - if(length > 0) { - stringBuilder.append("?") - var i = 1 - while (i < length) { - stringBuilder.append(",?") - i += 1 + def appendPlaceholders(stringBuilder: StringBuilder) = + params.zipWithIndex.foreach { case (param, index) => + if (0 < index) { + stringBuilder.append(",") } + param.appendPlaceholders(stringBuilder) } - } } object TupleParameter { diff --git a/relate/src/test/scala/ParameterizationTest.scala b/relate/src/test/scala/ParameterizationTest.scala index edd5fcb..1abdd3f 100644 --- a/relate/src/test/scala/ParameterizationTest.scala +++ b/relate/src/test/scala/ParameterizationTest.scala @@ -1,5 +1,6 @@ package com.lucidchart.relate +import java.sql.PreparedStatement import org.specs2.mutable._ class ParameterizationTest extends Specification { @@ -17,4 +18,15 @@ class ParameterizationTest extends Specification { querySql.toString mustEqual("INSERT INTO myTable (foo) VALUES (?,?,?)") } } + + "tuple paramater" should { + "use sub-parameter placeholders" in { + class CustomParameter(value: Int) extends SingleParameter { + protected[this] def set(statement: PreparedStatement, i: Int) = implicitly[Parameterizable[Int]].set(statement, i, value) + override def appendPlaceholders(stringBuilder: StringBuilder) = stringBuilder.append("?::smallint") + } + val querySql = sql"INSERT INTO myTable (foo, bar) VALUES (${(1, new CustomParameter(1))})" + querySql.toString mustEqual("INSERT INTO myTable (foo, bar) VALUES (?,?::smallint)") + } + } }