Index: tests/modeltests/custom_methods/models.py
===================================================================
--- tests/modeltests/custom_methods/models.py	(revision 7507)
+++ tests/modeltests/custom_methods/models.py	(working copy)
@@ -27,15 +27,16 @@
         """
         from django.db import connection
         cursor = connection.cursor()
+        # Some backends really really need quotes!
         cursor.execute("""
-            SELECT id, headline, pub_date
-            FROM custom_methods_article
-            WHERE pub_date = %s
-                AND id != %s""", [str(self.pub_date), self.id])
+            SELECT "id", "headline", "pub_date"
+            FROM "custom_methods_article"
+            WHERE "pub_date" = %s
+                AND "id" != %s""", [str(self.pub_date), self.id])
         # The asterisk in "(*row)" tells Python to expand the list into
         # positional arguments to Article().
         return [self.__class__(*row) for row in cursor.fetchall()]
-
+    
 __test__ = {'API_TESTS':"""
 # Create a couple of Articles.
 >>> from datetime import date
Index: tests/modeltests/lookup/models.py
===================================================================
--- tests/modeltests/lookup/models.py	(revision 7507)
+++ tests/modeltests/lookup/models.py	(working copy)
@@ -303,7 +303,34 @@
 >>> a4.save()
 >>> a5 = Article(pub_date=now, headline='hey-Foo')
 >>> a5.save()
+"""}
 
+# Firebird support 'magic values'
+if settings.DATABASE_ENGINE in ('firebird',):
+    __test__['API_TESTS'] += r"""
+# and yet more:
+>>> a10 = Article(pub_date='today', headline='foobar')
+>>> a10.save()
+>>> a11 = Article(pub_date='tomorrow', headline='foobaz')
+>>> a11.save()
+>>> a12 = Article(pub_date='yesterday', headline='ooF')
+>>> a12.save()
+>>> a13 = Article(pub_date='now', headline='foobarbaz')
+>>> a13.save()
+>>> a14 = Article(pub_date='today', headline='zoocarfaz')
+>>> a14.save()
+>>> a15 = Article(pub_date='today', headline='barfoobaz')
+>>> a15.save()
+>>> a16 = Article(pub_date='today', headline='bazbaRFOO')
+>>> a16.save()
+>>> Article.objects.filter(pub_date__exact='yesterday')
+[<Article: ooF>]
+"""
+
+
+# Firebird doesn't support regular expression lookups
+if settings.DATABASE_ENGINE not in ('firebird',):
+    __test__['API_TESTS'] += r"""
 # zero-or-more
 >>> Article.objects.filter(headline__regex=r'fo*')
 [<Article: f>, <Article: fo>, <Article: foo>, <Article: fooo>]
@@ -377,10 +404,10 @@
 [<Article: barfoobaz>, <Article: baz>, <Article: bazbaRFOO>, <Article: foobarbaz>, <Article: foobaz>]
 >>> Article.objects.filter(headline__iregex=r'b.*ar')
 [<Article: bar>, <Article: barfoobaz>, <Article: bazbaRFOO>, <Article: foobar>, <Article: foobarbaz>]
-"""}
+"""
 
 
-if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old'):
+if settings.DATABASE_ENGINE not in ('mysql', 'mysql_old', 'firebird'):
     __test__['API_TESTS'] += r"""
 # grouping and backreferences
 >>> Article.objects.filter(headline__regex=r'b(.).*b\1')
Index: tests/modeltests/many_to_one/models.py
===================================================================
--- tests/modeltests/many_to_one/models.py	(revision 7507)
+++ tests/modeltests/many_to_one/models.py	(working copy)
@@ -5,6 +5,7 @@
 """
 
 from django.db import models
+from django.conf import settings
 
 class Reporter(models.Model):
     first_name = models.CharField(max_length=30)
@@ -149,8 +150,23 @@
 >>> sql = queryset.query.as_sql()[0]
 >>> sql.count('INNER JOIN')
 1
+"""
+}
 
+if settings.DATABASE_ENGINE == 'firebird':
+    __test__['API_TESTS'] += """
 # The automatically joined table has a predictable name.
+>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["\\"many_to_one_reporter\\".\\"last_name\\"='Smith'"])
+[<Article: John's second story>, <Article: This is a test>]
+
+# And should work fine with the unicode that comes out of
+# newforms.Form.cleaned_data
+>>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["\\"many_to_one_reporter\\".\\"last_name\\"='%s'" % u'Smith'])
+[<Article: John's second story>, <Article: This is a test>]
+"""
+else:
+    __test__['API_TESTS'] += """\
+# The automatically joined table has a predictable name.
 >>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_reporter.last_name='Smith'"])
 [<Article: John's second story>, <Article: This is a test>]
 
@@ -158,7 +174,10 @@
 # newforms.Form.cleaned_data
 >>> Article.objects.filter(reporter__first_name__exact='John').extra(where=["many_to_one_reporter.last_name='%s'" % u'Smith'])
 [<Article: John's second story>, <Article: This is a test>]
+"""
 
+
+__test__['API_TESTS'] += """
 # Find all Articles for the Reporter whose ID is 1.
 # Use direct ID check, pk check, and object comparison
 >>> Article.objects.filter(reporter__id__exact=1)
@@ -286,4 +305,4 @@
 [datetime.datetime(1980, 4, 1, 0, 0)]
 >>> Article.objects.select_related().dates('pub_date', 'year')
 [datetime.datetime(1980, 1, 1, 0, 0)]
-"""}
+"""
Index: tests/regressiontests/serializers_regress/tests.py
===================================================================
--- tests/regressiontests/serializers_regress/tests.py	(revision 7507)
+++ tests/regressiontests/serializers_regress/tests.py	(working copy)
@@ -22,6 +22,10 @@
     import decimal
 except ImportError:
     from django.utils import _decimal as decimal
+try:
+    set
+except NameError:
+    from sets import Set as set   # Python 2.3 fallback 
 
 # A set of functions that can be used to recreate
 # test data objects of various kinds.
@@ -83,8 +87,9 @@
     testcase.assertEqual(data, instance.data_id)
 
 def m2m_compare(testcase, pk, klass, data):
+    # Use sets to ignore order of data
     instance = klass.objects.get(id=pk)
-    testcase.assertEqual(data, [obj.id for obj in instance.data.all()])
+    testcase.assertEqual(set(data), set([obj.id for obj in instance.data.all()]))
 
 def o2o_compare(testcase, pk, klass, data):
     instance = klass.objects.get(data=data)
Index: tests/regressiontests/backends/models.py
===================================================================
--- tests/regressiontests/backends/models.py	(revision 7507)
+++ tests/regressiontests/backends/models.py	(working copy)
@@ -29,7 +29,7 @@
 >>> opts = Square._meta
 >>> f1, f2 = opts.get_field('root'), opts.get_field('square')
 >>> query = ('INSERT INTO %s (%s, %s) VALUES (%%s, %%s)'
-...         % (t_convert(opts.db_table), qn(f1.column), qn(f2.column)))
+...         % ((qn(t_convert(opts.db_table)), qn(f1.column), qn(f2.column))))
 >>> cursor.executemany(query, [(i, i**2) for i in range(-5, 6)]) and None or None
 >>> Square.objects.order_by('root')
 [<Square: -5 ** 2 == 25>, <Square: -4 ** 2 == 16>, <Square: -3 ** 2 == 9>, <Square: -2 ** 2 == 4>, <Square: -1 ** 2 == 1>, <Square: 0 ** 2 == 0>, <Square: 1 ** 2 == 1>, <Square: 2 ** 2 == 4>, <Square: 3 ** 2 == 9>, <Square: 4 ** 2 == 16>, <Square: 5 ** 2 == 25>]
@@ -48,7 +48,7 @@
 >>> opts2 = Person._meta
 >>> f3, f4 = opts2.get_field('first_name'), opts2.get_field('last_name')
 >>> query2 = ('SELECT %s, %s FROM %s ORDER BY %s'
-...          % (qn(f3.column), qn(f4.column), t_convert(opts2.db_table),
+...          % (qn(f3.column), qn(f4.column), qn(t_convert(opts2.db_table)),
 ...             qn(f3.column)))
 >>> cursor.execute(query2) and None or None
 >>> cursor.fetchone()
