summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2005-11-14 01:44:35 +0000
committerAdrian Holovaty <adrian@holovaty.com>2005-11-14 01:44:35 +0000
commitf6bf41e59ac032c253e3b4e1b267010c6d456a26 (patch)
treea2b7755ee377b3cd99ff301154d9ae9a35991b1c /tests
parent6e40d8c29f2b6ed926cf764f5c9cdce07bc9a069 (diff)
Fixed #121 -- Django now quotes all names in SQL queries. Also added unit tests to confirm. Thanks, Robin Munn and Sune.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1224 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/testapp/models/__init__.py2
-rw-r--r--tests/testapp/models/reserved_names.py47
2 files changed, 48 insertions, 1 deletions
diff --git a/tests/testapp/models/__init__.py b/tests/testapp/models/__init__.py
index baa048d123..c0e39fae7d 100644
--- a/tests/testapp/models/__init__.py
+++ b/tests/testapp/models/__init__.py
@@ -1,4 +1,4 @@
__all__ = ['basic', 'repr', 'custom_methods', 'many_to_one', 'many_to_many',
'ordering', 'lookup', 'get_latest', 'm2m_intermediary', 'one_to_one',
'm2o_recursive', 'm2o_recursive2', 'save_delete_hooks', 'custom_pk',
- 'subclassing', 'many_to_one_null', 'custom_columns']
+ 'subclassing', 'many_to_one_null', 'custom_columns', 'reserved_names']
diff --git a/tests/testapp/models/reserved_names.py b/tests/testapp/models/reserved_names.py
new file mode 100644
index 0000000000..eabe41e5bd
--- /dev/null
+++ b/tests/testapp/models/reserved_names.py
@@ -0,0 +1,47 @@
+"""
+18. Using SQL reserved names
+
+Need to use a reserved SQL name as a column name or table name? Need to include
+a hyphen in a column or table name? No problem. Django quotes names
+appropriately behind the scenes, so your database won't complain about
+reserved-name usage.
+"""
+
+from django.core import meta
+
+class Thing(meta.Model):
+ when = meta.CharField(maxlength=1, primary_key=True)
+ join = meta.CharField(maxlength=1)
+ like = meta.CharField(maxlength=1)
+ drop = meta.CharField(maxlength=1)
+ alter = meta.CharField(maxlength=1)
+ having = meta.CharField(maxlength=1)
+ where = meta.CharField(maxlength=1)
+ has_hyphen = meta.CharField(maxlength=1, db_column='has-hyphen')
+ class META:
+ db_table = 'select'
+
+ def __repr__(self):
+ return self.when
+
+API_TESTS = """
+>>> t = things.Thing(when='a', join='b', like='c', drop='d', alter='e', having='f', where='g', has_hyphen='h')
+>>> t.save()
+>>> print t.when
+a
+
+>>> u = things.Thing(when='h', join='i', like='j', drop='k', alter='l', having='m', where='n')
+>>> u.save()
+>>> print u.when
+h
+
+>>> things.get_list(order_by=['when'])
+[a, h]
+>>> v = things.get_object(pk='a')
+>>> print v.join
+b
+>>> print v.where
+g
+>>> things.get_list(order_by=['select.when'])
+[a, h]
+"""