adamv avatar adamv committed 6c11113

Migrating to queryset-refactor:
* REGEX support now in DatabaseOperations instead of a django patch.

Comments (0)

Files changed (4)

django-patches/6826-enable-regex.patch

-Index: django/db/models/query.py
-===================================================================
---- django/db/models/query.py	(revision 6826)
-+++ django/db/models/query.py	(working copy)
-@@ -824,6 +824,13 @@
-             else:
-                 match_option = 'i'
-             return "REGEXP_LIKE(%s, %s, '%s')" % (field_sql, cast_sql, match_option)
-+        elif settings.DATABASE_ENGINE == 'sqlserver_ado' and \
-+                hasattr(settings, 'DATABASE_MSSQL_REGEX') and settings.DATABASE_MSSQL_REGEX:
-+            if lookup_type == 'regex':
-+                match_option = 1
-+            else:
-+                match_option = 0
-+            return "dbo.REGEXP_LIKE(%s, %s, %s)=1" % (field_sql, cast_sql, match_option)
-         else:
-             raise NotImplementedError
-     raise TypeError, "Got invalid lookup_type: %s" % repr(lookup_type)

django-patches/README.txt

+This folder contains any patches needed against Django itself.
+
+There are currently no patches needed for this backend, as the 
+queryset-refactor branch has landed on djano-trunk, and much of 
+the custom hacks previously required can now be supported directly
+as backend customizations.

src/sqlserver_ado/adodb_django.py

 class DataError(DatabaseError): pass
 class NotSupportedError(DatabaseError): pass
 
-
 class DBAPITypeObject:
   def __init__(self,valuesTuple):
     self.values = valuesTuple
 
     return -1
 
-
 def _logger(message, log_level=1):
 	if verbose and verbose>=log_level: print message
 
 	"""Formats a collection of ADO Command Parameters"""
 	desc = list()
 	for param in parameters:
-		desc.append("Name: %s, Type: %s, Size: %s" % (param.Name, adTypeNames.get(param.Type, str(param.Type)+'(unknown type)'), param.Size))
+		desc.append("Name: %s, Type: %s, Size: %s" % \
+			(param.Name, adTypeNames.get(param.Type, str(param.Type)+'(unknown type)'), param.Size))
 		
 	return '[' + ', '.join(desc) + ']'
 
             self.adoConn.BeginTrans() #Disables autocommit
 
         if verbose:
-            print 'adodbapi New connection at %X' % id(self)
+            print 'adodbapi - New connection at %X' % id(self)
             
     def _determineTransactionSupport(self):
         self.supportsTransactions = False
             self.adoConn.RollbackTrans()
         self.adoConn.Close()
         if verbose:
-            print 'adodbapi Closed connection at %X' % id(self)
+            print 'adodbapi - Closed connection at %X' % id(self)
 
     def close(self):
         """Close the connection now (rather than whenever __del__ is called).
         self.description = None
         self.errorhandler = connection.errorhandler
         if verbose:
-            print 'adodbapi New cursor at %X on conn %X' % (id(self),id(self.conn))
+            print 'adodbapi - New cursor at %X on conn %X' % (id(self),id(self.conn))
 
     def __iter__(self):
         return iter(self.fetchone, None)
                             s = rx_datetime.findall(s)[0]
                         except: pass
                         p.Value = s
-                        # Don't set size to 0, even for empty strings.
-                        p.Size = max(len(s), 1)
-                        
+                        p.Size = len(s)
+                                                
                     elif isinstance(elem, basestring):
                         s = elem
                         # Hack to trim microseconds on iso dates down to 3 decimals
                             s = rx_datetime.findall(s)[0]
                         except: pass
                         p.Value = s
-                        p.Size = max(len(s), 1)
+                        p.Size = len(s)
 
                     elif isinstance(elem, buffer):
-                        p.Size = max(len(elem), 1)
+                        p.Size = len(elem)
                         p.AppendChunk(elem)
                         
                     else: p.Value = elem
+                    
+                    # Use -1 instead of 0 for empty strings and similar.
+                    if p.Size == 0: p.Size = -1
 
                     if verbose > 2:
                         print 'Parameter %d type %s stored as: %s' % (parmIndx,adTypeNames.get(p.Type, 'unknown'),repr(p.Value))
                                               sys.exc_traceback,
                                               8))
             tb=string.join(tblist)
-            tracebackhistory = tbk + tb + u'\n-- on command: "%s"\n-- with parameters: %s \n-- supplied values: %s' %(operation, format_parameters(self.cmd.Parameters), parameters)
+            tracebackhistory = tbk + tb + u'\n-- on command: "%s"\n-- with parameters: %s \n-- supplied values: %s' %\
+            	(operation, format_parameters(self.cmd.Parameters), parameters)
             self._raiseCursorError(DatabaseError,tracebackhistory)
             return
 

src/sqlserver_ado/base.py

 
     def tablespace_sql(self, tablespace, inline=False):
         return "ON %s" % self.quote_name(tablespace)
+        
+    def regex_lookup(self, lookup_type):
+		if settings.DATABASE_ENGINE == 'sqlserver_ado' and \
+				hasattr(settings, 'DATABASE_MSSQL_REGEX') and \
+				settings.DATABASE_MSSQL_REGEX:
+			
+			# Case sensitivity
+			match_option = 0
+			if lookup_type == 'regex':
+				match_option = 1
+				
+			return "dbo.REGEXP_LIKE(%s, %s, %s)=1" % (field_sql, cast_sql, match_option)
+		else:
+			raise NotImplementedError
+
 
 # IP Address recognizer taken from:
 # http://mail.python.org/pipermail/python-list/2006-March/375505.html
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.