Skip to content

Commit

Permalink
better collation support
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Dec 31, 2014
1 parent f38786d commit 9113387
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
16 changes: 14 additions & 2 deletions data/src/entity_manager/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -4418,6 +4418,18 @@ def _lock_query_f(self, entity_class, options, query_buffer):
if allow_for_update: query_buffer.write(" for update")
else: self.lock(entity_class)

def _process_collate(self, query_buffer):
# verifies if a valid provider of (case) insensitive collation
# exists for the current data source engine if that's not the
# case returns the control flow immediately (no collate)
if not hasattr(self.engine, "get_insensitive_collate"): return
collation = self.engine.get_insensitive_collate()
if not collation: return

# creates the extra collate operation for the current buffer
# taking into account the collation for the current engine
query_buffer.write(" collate %s" % collation)

def _process_filter(self, entity_class, table_name, filter, query_buffer, is_first = True):
# in case the is first flag
# is set, need to write the initial
Expand Down Expand Up @@ -4829,9 +4841,9 @@ def _process_filter_like(
# query buffer
query_buffer.write("'")

# in case the collate flat is enable the case insensitive collation
# in case the collate flat is set, the case insensitive collation
# mode is enabled so that a more broad search is enabled
if collate: query_buffer.write(" collate utf8_general_ci")
if collate: self._process_collate(query_buffer)

def _process_filter_rlike(self, entity_class, table_name, filter, query_buffer):
self._process_filter_like(entity_class, table_name, filter, query_buffer, left = False)
Expand Down
6 changes: 6 additions & 0 deletions data/src/entity_mysql/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ def get_database_encoding(self):
encoding = _connection.get_database_encoding()
return encoding

def get_insensitive_collate(self):
return "utf8_general_ci"

def apply_types(self, types_map):
types_map["text"] = "longtext"
types_map["data"] = "longtext"
Expand Down Expand Up @@ -516,6 +519,9 @@ def _database_size_result(self, cursor):
# size from the data source
return datbase_size

def _collate_query(self):
return "collate utf8_general_ci"

def _index_query(self, entity_class, attribute_name, index_type = "hash"):
# retrieves the associated table name
# as the "name" of the entity class
Expand Down
3 changes: 3 additions & 0 deletions data/src/entity_sqlite/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ def get_database_size(self):
def get_database_encoding(self):
return "utf-8"

def get_insensitive_collate(self):
return "nocase"

def connect(self, connection, parameters = {}):
file_path = parameters.get("file_path", None)
cache_size = parameters.get("cache_size", 200000)
Expand Down

0 comments on commit 9113387

Please sign in to comment.