flag_combination = (boolean_mode, natural_language, query_expansion)
if flag_combination not in self.match_valid_flag_combinations:
- flags = {
- 'mysql_boolean_mode': boolean_mode,
- 'mysql_natural_language': natural_language,
- 'mysql_query_expansion': query_expansion,
- }
+ flags = (
+ 'mysql_boolean_mode=%s' % boolean_mode,
+ 'mysql_natural_language=%s' % natural_language,
+ 'mysql_query_expansion=%s' % query_expansion,
+ )
+
+ flags = ", ".join(flags)
+
raise exc.CompileError(
- "Flag combination does not make sence: %s." % flags
- )
+ "Flag combination does not make sence: %s" % flags
+ )
match_clause = self.process(binary.left, **kw)
against_clause = self.process(binary.right, **kw)
# coding: utf-8
+from finctools import partial
+
from sqlalchemy import BLOB
from sqlalchemy import BOOLEAN
from sqlalchemy import Boolean
literal_binds=True,
)
+ def test_match_compile_kw_mysql(self):
+ matchtable = table("matchtable", column("title", String))
+ self.assert_compile(
+ matchtable.c.title.match("somstr", mysql_boolean_mode=False),
+ "MATCH (matchtable.title) AGAINST (%s)",
+ )
+ self.assert_compile(
+ matchtable.c.title.match(
+ "somstr",
+ mysql_boolean_mode=False,
+ mysql_natural_language=True,
+ ),
+ "MATCH (matchtable.title) AGAINST (%s IN NATURAL LANGUAGE MODE)",
+ )
+ self.assert_compile(
+ matchtable.c.title.match(
+ "somstr",
+ mysql_boolean_mode=False,
+ mysql_query_expansion=True,
+ ),
+ "MATCH (matchtable.title) AGAINST (%s WITH QUERY EXPANSION)",
+ )
+ self.assert_compile(
+ matchtable.c.title.match(
+ "somstr",
+ mysql_boolean_mode=False,
+ mysql_natural_language=True,
+ mysql_query_expansion=True,
+ ),
+ "MATCH (matchtable.title) AGAINST "
+ "(%s IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION)",
+ )
+
+ assert_raises_message(
+ exc.CompileError,
+ "Flag combination does not make sence: "
+ "mysql_boolean_mode=True, "
+ "mysql_natural_language=True, "
+ "mysql_query_expansion=True",
+ partial(
+ matchtable.c.title.match,
+ "somstr",
+ mysql_natural_language=True,
+ mysql_query_expansion=True,
+ ),
+ dialect=mysql.dialect(),
+ )
+
+ assert_raises_message(
+ exc.CompileError,
+ "Flag combination does not make sence: "
+ "mysql_boolean_mode=True, "
+ "mysql_natural_language=False, "
+ "mysql_query_expansion=True",
+ partial(
+ matchtable.c.title.match,
+ "somstr",
+ mysql_query_expansion=True,
+ ),
+ dialect=mysql.dialect(),
+ )
+
+ assert_raises_message(
+ exc.CompileError,
+ "Flag combination does not make sence: "
+ "mysql_boolean_mode=True, "
+ "mysql_natural_language=True, "
+ "mysql_query_expansion=False",
+ partial(
+ matchtable.c.title.match,
+ "somstr",
+ mysql_natural_language=True,
+ ),
+ dialect=mysql.dialect(),
+ )
+
def test_concat_compile_kw(self):
expr = literal("x", type_=String) + literal("y", type_=String)
self.assert_compile(expr, "concat('x', 'y')", literal_binds=True)