diff options
| author | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2006-11-04 20:18:55 +0000 |
|---|---|---|
| committer | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2006-11-04 20:18:55 +0000 |
| commit | 6ab11188d5714a0330bb9ad5011fd5dfbbf1ff54 (patch) | |
| tree | 30ced881b27ef915138660179db5c162ec78bb87 | |
| parent | 23246ebd0975f55319148e7ddcbad6e43b2842ba (diff) | |
Add a truncate_name method to shorten DB identifiers for Oracle
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@3972 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/db/backends/util.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/django/db/backends/util.py b/django/db/backends/util.py index 3ec1b41485..961e50e91b 100644 --- a/django/db/backends/util.py +++ b/django/db/backends/util.py @@ -1,4 +1,5 @@ import datetime +import md5 from time import time class CursorDebugWrapper(object): @@ -92,6 +93,16 @@ def typecast_boolean(s): def rev_typecast_boolean(obj, d): return obj and '1' or '0' +def truncate_name(name, length=None): + """Shortens a string to a repeatable mangled version with the given length. + """ + if length is None or len(name) <= length: + return name + + hash = md5.md5(name).hexdigest()[:4] + + return '%s%s' % (name[:length-4], hash) + ################################################################################## # Helper functions for dictfetch* for databases that don't natively support them # ################################################################################## |
