0

I use of following query in ormlite with Mysql:

String _textSearch="%اعصاب%";
Where<QuestionEntity, Long> _where= getDao().queryBuilder()).where();

List<QuestionEntity> _lst= _where.or(_where.like("title",_textSearch ),
    _where.like("questiontext", _textSearch)).query();

but generate following query:

SELECT * FROM `question`
    WHERE (`title` LIKE '%?????%' OR `questiontext` LIKE '%?????%' )

why ?

Gray
  • 115,027
  • 24
  • 293
  • 354
or123456
  • 2,091
  • 8
  • 28
  • 50

1 Answers1

0
SELECT * FROM `question`
    WHERE (`title` LIKE '%?????%' OR `questiontext` LIKE '%?????%' )

Hrm, I'm not sure what the problem is here. I've added the this UTF8 query-build test to the ormlite-core project and it passes fine.

Foo foo = new Foo();
foo.stringField = "اعصاب";
dao.create(foo);
List<Foo> results = dao.queryBuilder().where()
   .like(Foo.STRING_COLUMN_NAME, foo.stringField).query();
assertEquals(foo.stringField, results.get(0).stringField);

This generates the following log output:

SELECT * FROM `foo` WHERE `string` LIKE 'اعصاب' 

This also works with a SelectArg which is how ORMLite does ? args.

statement arguments: [اعصاب]
SELECT * FROM `foo` WHERE `string` LIKE ?

I initially thought that this was a problem with MySQL. Maybe you got the queries out of the server log? If you got the '?????' from a local log then I'm not sure what the issue is. Maybe the default character encoding for your application?

The tests are using H2 which is a native Java DB so can easily handle Java's strings. Maybe take a look at these MySQL questions/answers for help:

There is some talk about later versions of the MySQL connector fixing a problem with detecting the character type of the database.

Community
  • 1
  • 1
Gray
  • 115,027
  • 24
  • 293
  • 354