diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c13793..45f9f60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Changed + +- **Unsupported Query Expressions Raise** - An expression the adapter cannot translate now raises `Ecto.QueryError` ("unsupported expression ...") instead of being rendered as a `?` placeholder, which bound the wrong parameter in its place and silently changed the query. + ## [0.9.1] - 2026-05-07 ### Fixed diff --git a/lib/ecto/adapters/libsql/connection.ex b/lib/ecto/adapters/libsql/connection.ex index 72da826..9728059 100644 --- a/lib/ecto/adapters/libsql/connection.ex +++ b/lib/ecto/adapters/libsql/connection.ex @@ -1384,9 +1384,12 @@ defmodule Ecto.Adapters.LibSql.Connection do defp expr(false, _sources, _query), do: "0" defp expr(nil, _sources, _query), do: "NULL" - # Default fallback for unsupported expressions - defp expr(_expr, _sources, _query) do - "?" + # Unsupported expressions raise: rendering them as a placeholder would bind + # the next parameter in their place and silently change the query. + defp expr(expr, _sources, query) do + raise Ecto.QueryError, + query: query, + message: "unsupported expression #{inspect(expr)}" end defp combination(%{combinations: []}, _as_prefix), do: [] diff --git a/test/in_expression_comprehensive_test.exs b/test/in_expression_comprehensive_test.exs index d78e4ad..ab10578 100644 --- a/test/in_expression_comprehensive_test.exs +++ b/test/in_expression_comprehensive_test.exs @@ -507,4 +507,14 @@ defmodule EctoLibSql.InExpressionComprehensiveTest do assert "item3" in result end end + + describe "unsupported expressions" do + test "raise instead of being rendered as a \"?\" placeholder" do + query = from(t in "test_items", where: ilike(t.name, "job%"), select: t.name) + + assert_raise Ecto.QueryError, ~r/unsupported expression/, fn -> + Ecto.Adapters.SQL.to_sql(:all, TestRepo, query) + end + end + end end