ufoss-org / kotysa

The idiomatic way to write type-safe SQL in Kotlin
The Unlicense
117 stars 1 forks source link

Wrong parameter order using subquery #138

Closed guitcastro closed 1 year ago

guitcastro commented 1 year ago

I have the following query:

  (client selectFrom CitySchema where  CitySchema.countryId eq
          { this select CountrySchema.id from CountrySchema where CountrySchema.code eq countryCode })
          and CitySchema.name contains cityName 

Which generate this query:

SELECT cities.id, cities.country_id, cities.state_id, cities.name 
FROM cities 
WHERE (cities.country_id = (SELECT countries.id FROM countries  WHERE (countries.iso2 = $1)    ))
AND (cities.name LIKE $2)    

However it was nor working, After debugging and found out that the tuple arguments where in the wrong order.

Tuple[0] = "cityName" Tuple[1] = "countryCode"

As a workaround, I've rewrote the query and now it's working:

  (client selectFrom CitySchema where CitySchema.name contains cityName and
          CitySchema.countryId eq
          { this select CountrySchema.id from CountrySchema where CountrySchema.code eq countryCode })
pull-vert commented 1 year ago

Hi @guitcastro , I will fix this in the next release ! Thanks for reporting this :heart:

pull-vert commented 1 year ago

@guitcastro Kotysa 3.0.2 was just released with this fix