On Thu, Jul 07, 2016 at 11:23:21PM -0500, Art Zemon wrote: > Hello, > > I have a column in a table that contains Hebrew text. I need to do a query > with a LIKE clause on the Hebrew text. The query works if I execute the SQL > directly, either in a SQL window of phpMyAdmin or in a command line mysql > client. But I cannot get it to work within Django. > > I tried Bible.objects.filter(hebrew_text__contains('דֶּשֶׁא') and I get > nothing back.
Here, one thing you might want to try is to use django-debug-toolbar's debugsqlshell, run the query inside that, and take a look at the actual SQL query generated for that; maybe it will reveal some oddity. > I tried a raw query in a custom manager: > > class BibleManager(models.Manager): > def contains_hebrew_word(self, word='דֶּשֶׁא'): > sql = """select sortkey, book, chapter, verse, hebrew_text > from bible_bible > where hebrew_text like '%%%s%%' """ > raw_query_set = self.raw(sql, [word]) > result_list = [] > for b in raw_query_set: > result_list.append(b) > return result_list > > but I get this error: > > django.db.utils.ProgrammingError: (1064, "You have an error in your SQL > syntax; check the manual that corresponds to your MySQL server version for > the right syntax to use near 'דֶּשֶׁא'%'' at line 3") I may be wrong, but it seems to me that you're using wrong quoting in that raw query; I think it should be:: select sortkey, book, chapter, verse, hebrew_text from bible_bible where hebrew_text like '%%' || %s || '%%' The DBAPI will already take care of the proper quoting for the string argument, you just need to properly concatenate it with percent signs on both sides. Good luck, Michal -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/20160708133324.GG22177%40koniiiik.org. For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: Digital signature