mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
[soc2010/query-refactor] Merged up to trunk r13366.
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2010/query-refactor@13367 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
72c6a43403
commit
dd5e718296
1
AUTHORS
1
AUTHORS
@ -220,6 +220,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Kieran Holland <http://www.kieranholland.com>
|
Kieran Holland <http://www.kieranholland.com>
|
||||||
Sung-Jin Hong <serialx.net@gmail.com>
|
Sung-Jin Hong <serialx.net@gmail.com>
|
||||||
Leo "hylje" Honkanen <sealage@gmail.com>
|
Leo "hylje" Honkanen <sealage@gmail.com>
|
||||||
|
Matt Hoskins <skaffenuk@googlemail.com>
|
||||||
Tareque Hossain <http://www.codexn.com>
|
Tareque Hossain <http://www.codexn.com>
|
||||||
Richard House <Richard.House@i-logue.com>
|
Richard House <Richard.House@i-logue.com>
|
||||||
Robert Rock Howard <http://djangomojo.com/>
|
Robert Rock Howard <http://djangomojo.com/>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
VERSION = (1, 2, 1, 'final', 0)
|
VERSION = (1, 3, 0, 'alpha', 0)
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
version = '%s.%s' % (VERSION[0], VERSION[1])
|
version = '%s.%s' % (VERSION[0], VERSION[1])
|
||||||
|
@ -22,7 +22,7 @@ Paragraph 2 with "quotes" and @code@"""
|
|||||||
t = Template("{{ textile_content|textile }}")
|
t = Template("{{ textile_content|textile }}")
|
||||||
rendered = t.render(Context(locals())).strip()
|
rendered = t.render(Context(locals())).strip()
|
||||||
if textile:
|
if textile:
|
||||||
self.assertEqual(rendered, """<p>Paragraph 1</p>
|
self.assertEqual(rendered.replace('\t', ''), """<p>Paragraph 1</p>
|
||||||
|
|
||||||
<p>Paragraph 2 with “quotes” and <code>code</code></p>""")
|
<p>Paragraph 2 with “quotes” and <code>code</code></p>""")
|
||||||
else:
|
else:
|
||||||
|
@ -4,6 +4,8 @@ from optparse import make_option
|
|||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
option_list = BaseCommand.option_list + (
|
option_list = BaseCommand.option_list + (
|
||||||
|
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
||||||
|
help='Tells Django to NOT prompt the user for input of any kind.'),
|
||||||
make_option('--addrport', action='store', dest='addrport',
|
make_option('--addrport', action='store', dest='addrport',
|
||||||
type='string', default='',
|
type='string', default='',
|
||||||
help='port number or ipaddr:port to run the server on'),
|
help='port number or ipaddr:port to run the server on'),
|
||||||
@ -18,10 +20,11 @@ class Command(BaseCommand):
|
|||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
verbosity = int(options.get('verbosity', 1))
|
verbosity = int(options.get('verbosity', 1))
|
||||||
|
interactive = options.get('interactive', True)
|
||||||
addrport = options.get('addrport')
|
addrport = options.get('addrport')
|
||||||
|
|
||||||
# Create a test database.
|
# Create a test database.
|
||||||
db_name = connection.creation.create_test_db(verbosity=verbosity)
|
db_name = connection.creation.create_test_db(verbosity=verbosity, autoclobber=not interactive)
|
||||||
|
|
||||||
# Import the fixture data into the test database.
|
# Import the fixture data into the test database.
|
||||||
call_command('loaddata', *fixture_labels, **{'verbosity': verbosity})
|
call_command('loaddata', *fixture_labels, **{'verbosity': verbosity})
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from django.db.backends.creation import BaseDatabaseCreation
|
from django.db.backends.creation import BaseDatabaseCreation
|
||||||
|
from django.db.backends.util import truncate_name
|
||||||
|
|
||||||
class DatabaseCreation(BaseDatabaseCreation):
|
class DatabaseCreation(BaseDatabaseCreation):
|
||||||
# This dictionary maps Field objects to their associated PostgreSQL column
|
# This dictionary maps Field objects to their associated PostgreSQL column
|
||||||
@ -51,7 +52,7 @@ class DatabaseCreation(BaseDatabaseCreation):
|
|||||||
|
|
||||||
def get_index_sql(index_name, opclass=''):
|
def get_index_sql(index_name, opclass=''):
|
||||||
return (style.SQL_KEYWORD('CREATE INDEX') + ' ' +
|
return (style.SQL_KEYWORD('CREATE INDEX') + ' ' +
|
||||||
style.SQL_TABLE(qn(index_name)) + ' ' +
|
style.SQL_TABLE(qn(truncate_name(index_name,self.connection.ops.max_name_length()))) + ' ' +
|
||||||
style.SQL_KEYWORD('ON') + ' ' +
|
style.SQL_KEYWORD('ON') + ' ' +
|
||||||
style.SQL_TABLE(qn(db_table)) + ' ' +
|
style.SQL_TABLE(qn(db_table)) + ' ' +
|
||||||
"(%s%s)" % (style.SQL_FIELD(qn(f.column)), opclass) +
|
"(%s%s)" % (style.SQL_FIELD(qn(f.column)), opclass) +
|
||||||
|
@ -54,7 +54,9 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
return '%s'
|
return '%s'
|
||||||
|
|
||||||
def last_insert_id(self, cursor, table_name, pk_name):
|
def last_insert_id(self, cursor, table_name, pk_name):
|
||||||
cursor.execute("SELECT CURRVAL('\"%s_%s_seq\"')" % (table_name, pk_name))
|
# Use pg_get_serial_sequence to get the underlying sequence name
|
||||||
|
# from the table name and column name (available since PostgreSQL 8)
|
||||||
|
cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (table_name, pk_name))
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
|
||||||
def no_limit_value(self):
|
def no_limit_value(self):
|
||||||
@ -90,13 +92,14 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
for sequence_info in sequences:
|
for sequence_info in sequences:
|
||||||
table_name = sequence_info['table']
|
table_name = sequence_info['table']
|
||||||
column_name = sequence_info['column']
|
column_name = sequence_info['column']
|
||||||
if column_name and len(column_name) > 0:
|
if not (column_name and len(column_name) > 0):
|
||||||
sequence_name = '%s_%s_seq' % (table_name, column_name)
|
# This will be the case if it's an m2m using an autogenerated
|
||||||
else:
|
# intermediate table (see BaseDatabaseIntrospection.sequence_list)
|
||||||
sequence_name = '%s_id_seq' % table_name
|
column_name = 'id'
|
||||||
sql.append("%s setval('%s', 1, false);" % \
|
sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD(self.quote_name(sequence_name)))
|
style.SQL_TABLE(table_name),
|
||||||
|
style.SQL_FIELD(column_name))
|
||||||
)
|
)
|
||||||
return sql
|
return sql
|
||||||
else:
|
else:
|
||||||
@ -110,11 +113,15 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
# Use `coalesce` to set the sequence for each model to the max pk value if there are records,
|
# Use `coalesce` to set the sequence for each model to the max pk value if there are records,
|
||||||
# or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true
|
# or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true
|
||||||
# if there are records (as the max pk value is already in use), otherwise set it to false.
|
# if there are records (as the max pk value is already in use), otherwise set it to false.
|
||||||
|
# Use pg_get_serial_sequence to get the underlying sequence name from the table name
|
||||||
|
# and column name (available since PostgreSQL 8)
|
||||||
|
|
||||||
for f in model._meta.local_fields:
|
for f in model._meta.local_fields:
|
||||||
if isinstance(f, models.AutoField):
|
if isinstance(f, models.AutoField):
|
||||||
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD(qn('%s_%s_seq' % (model._meta.db_table, f.column))),
|
style.SQL_TABLE(model._meta.db_table),
|
||||||
|
style.SQL_FIELD(f.column),
|
||||||
style.SQL_FIELD(qn(f.column)),
|
style.SQL_FIELD(qn(f.column)),
|
||||||
style.SQL_FIELD(qn(f.column)),
|
style.SQL_FIELD(qn(f.column)),
|
||||||
style.SQL_KEYWORD('IS NOT'),
|
style.SQL_KEYWORD('IS NOT'),
|
||||||
@ -123,9 +130,10 @@ class DatabaseOperations(BaseDatabaseOperations):
|
|||||||
break # Only one AutoField is allowed per model, so don't bother continuing.
|
break # Only one AutoField is allowed per model, so don't bother continuing.
|
||||||
for f in model._meta.many_to_many:
|
for f in model._meta.many_to_many:
|
||||||
if not f.rel.through:
|
if not f.rel.through:
|
||||||
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
output.append("%s setval(pg_get_serial_sequence('%s','%s'), coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())),
|
style.SQL_TABLE(model._meta.db_table),
|
||||||
|
style.SQL_FIELD('id'),
|
||||||
style.SQL_FIELD(qn('id')),
|
style.SQL_FIELD(qn('id')),
|
||||||
style.SQL_FIELD(qn('id')),
|
style.SQL_FIELD(qn('id')),
|
||||||
style.SQL_KEYWORD('IS NOT'),
|
style.SQL_KEYWORD('IS NOT'),
|
||||||
|
@ -18,6 +18,22 @@ documentation or reference manuals.
|
|||||||
PostgreSQL notes
|
PostgreSQL notes
|
||||||
================
|
================
|
||||||
|
|
||||||
|
.. versionchanged:: 1.3
|
||||||
|
|
||||||
|
Django supports PostgreSQL 8.0 and higher. If you want to use
|
||||||
|
:ref:`database-level autocommit <postgresql-autocommit-mode>`, a
|
||||||
|
minimum version of PostgreSQL 8.2 is required.
|
||||||
|
|
||||||
|
.. admonition:: Improvements in recent PostgreSQL versions
|
||||||
|
|
||||||
|
PostgreSQL 8.0 and 8.1 `will soon reach end-of-life`_; there have
|
||||||
|
also been a number of significant performance improvements added
|
||||||
|
in recent PostgreSQL versions. Although PostgreSQL 8.0 is the minimum
|
||||||
|
supported version, you would be well advised to use a more recent
|
||||||
|
version if at all possible.
|
||||||
|
|
||||||
|
.. _will soon reach end-of-life: http://wiki.postgresql.org/wiki/PostgreSQL_Release_Support_Policy
|
||||||
|
|
||||||
PostgreSQL 8.2 to 8.2.4
|
PostgreSQL 8.2 to 8.2.4
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
@ -39,6 +55,8 @@ database connection is first used and commits the result at the end of the
|
|||||||
request/response handling. The PostgreSQL backends normally operate the same
|
request/response handling. The PostgreSQL backends normally operate the same
|
||||||
as any other Django backend in this respect.
|
as any other Django backend in this respect.
|
||||||
|
|
||||||
|
.. _postgresql-autocommit-mode:
|
||||||
|
|
||||||
Autocommit mode
|
Autocommit mode
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
@ -84,6 +102,7 @@ protection for multi-call operations.
|
|||||||
|
|
||||||
Indexes for ``varchar`` and ``text`` columns
|
Indexes for ``varchar`` and ``text`` columns
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
.. versionadded:: 1.1.2
|
.. versionadded:: 1.1.2
|
||||||
|
|
||||||
When specifying ``db_index=True`` on your model fields, Django typically
|
When specifying ``db_index=True`` on your model fields, Django typically
|
||||||
|
@ -804,8 +804,6 @@ with an appropriate extension (e.g. ``json`` or ``xml``). See the
|
|||||||
documentation for ``loaddata`` for details on the specification of fixture
|
documentation for ``loaddata`` for details on the specification of fixture
|
||||||
data files.
|
data files.
|
||||||
|
|
||||||
--noinput
|
|
||||||
~~~~~~~~~
|
|
||||||
The :djadminopt:`--noinput` option may be provided to suppress all user
|
The :djadminopt:`--noinput` option may be provided to suppress all user
|
||||||
prompts.
|
prompts.
|
||||||
|
|
||||||
@ -889,6 +887,11 @@ To run on 1.2.3.4:7000 with a ``test`` fixture::
|
|||||||
|
|
||||||
django-admin.py testserver --addrport 1.2.3.4:7000 test
|
django-admin.py testserver --addrport 1.2.3.4:7000 test
|
||||||
|
|
||||||
|
.. versionadded:: 1.3
|
||||||
|
|
||||||
|
The :djadminopt:`--noinput` option may be provided to suppress all user
|
||||||
|
prompts.
|
||||||
|
|
||||||
validate
|
validate
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ of to a specific field. You can access these errors with ``NON_FIELD_ERRORS``::
|
|||||||
|
|
||||||
from django.core.validators import ValidationError, NON_FIELD_ERRORS
|
from django.core.validators import ValidationError, NON_FIELD_ERRORS
|
||||||
try:
|
try:
|
||||||
article.full_clean():
|
article.full_clean()
|
||||||
except ValidationError, e:
|
except ValidationError, e:
|
||||||
non_field_errors = e.message_dict[NON_FIELD_ERRORS]
|
non_field_errors = e.message_dict[NON_FIELD_ERRORS]
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ a subclass of dictionary. Exceptions are outlined here:
|
|||||||
.. method:: QueryDict.setdefault(key, default)
|
.. method:: QueryDict.setdefault(key, default)
|
||||||
|
|
||||||
Just like the standard dictionary ``setdefault()`` method, except it uses
|
Just like the standard dictionary ``setdefault()`` method, except it uses
|
||||||
``__setitem__`` internally.
|
``__setitem__()`` internally.
|
||||||
|
|
||||||
.. method:: QueryDict.update(other_dict)
|
.. method:: QueryDict.update(other_dict)
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ a subclass of dictionary. Exceptions are outlined here:
|
|||||||
.. method:: QueryDict.items()
|
.. method:: QueryDict.items()
|
||||||
|
|
||||||
Just like the standard dictionary ``items()`` method, except this uses the
|
Just like the standard dictionary ``items()`` method, except this uses the
|
||||||
same last-value logic as ``__getitem()__``. For example::
|
same last-value logic as ``__getitem__()``. For example::
|
||||||
|
|
||||||
>>> q = QueryDict('a=1&a=2&a=3')
|
>>> q = QueryDict('a=1&a=2&a=3')
|
||||||
>>> q.items()
|
>>> q.items()
|
||||||
@ -315,7 +315,7 @@ a subclass of dictionary. Exceptions are outlined here:
|
|||||||
|
|
||||||
Just like the standard dictionary ``iteritems()`` method. Like
|
Just like the standard dictionary ``iteritems()`` method. Like
|
||||||
:meth:`QueryDict.items()` this uses the same last-value logic as
|
:meth:`QueryDict.items()` this uses the same last-value logic as
|
||||||
:meth:`QueryDict.__getitem()__`.
|
:meth:`QueryDict.__getitem__()`.
|
||||||
|
|
||||||
.. method:: QueryDict.iterlists()
|
.. method:: QueryDict.iterlists()
|
||||||
|
|
||||||
@ -325,7 +325,7 @@ a subclass of dictionary. Exceptions are outlined here:
|
|||||||
.. method:: QueryDict.values()
|
.. method:: QueryDict.values()
|
||||||
|
|
||||||
Just like the standard dictionary ``values()`` method, except this uses the
|
Just like the standard dictionary ``values()`` method, except this uses the
|
||||||
same last-value logic as ``__getitem()__``. For example::
|
same last-value logic as ``__getitem__()``. For example::
|
||||||
|
|
||||||
>>> q = QueryDict('a=1&a=2&a=3')
|
>>> q = QueryDict('a=1&a=2&a=3')
|
||||||
>>> q.values()
|
>>> q.values()
|
||||||
|
31
docs/releases/1.3.txt
Normal file
31
docs/releases/1.3.txt
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
.. _releases-1.3:
|
||||||
|
|
||||||
|
============================================
|
||||||
|
Django 1.3 release notes - UNDER DEVELOPMENT
|
||||||
|
============================================
|
||||||
|
|
||||||
|
This page documents release notes for the as-yet-unreleased Django
|
||||||
|
1.3. As such, it's tentative and subject to change. It provides
|
||||||
|
up-to-date information for those who are following trunk.
|
||||||
|
|
||||||
|
Django 1.3 includes a number of nifty `new features`_, lots of bug
|
||||||
|
fixes and an easy upgrade path from Django 1.2.
|
||||||
|
|
||||||
|
.. _new features: `What's new in Django 1.3`_
|
||||||
|
|
||||||
|
.. _backwards-incompatible-changes-1.3:
|
||||||
|
|
||||||
|
Backwards-incompatible changes in 1.3
|
||||||
|
=====================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Features deprecated in 1.3
|
||||||
|
==========================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
What's new in Django 1.3
|
||||||
|
========================
|
||||||
|
|
||||||
|
|
@ -16,6 +16,13 @@ up to and including the new version.
|
|||||||
Final releases
|
Final releases
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
1.3 release
|
||||||
|
-----------
|
||||||
|
.. toctree::
|
||||||
|
:maxdepth: 1
|
||||||
|
|
||||||
|
1.3
|
||||||
|
|
||||||
1.2 release
|
1.2 release
|
||||||
-----------
|
-----------
|
||||||
.. toctree::
|
.. toctree::
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db import connection
|
from django.db import connection, DEFAULT_DB_ALIAS
|
||||||
|
|
||||||
|
|
||||||
class Square(models.Model):
|
class Square(models.Model):
|
||||||
root = models.IntegerField()
|
root = models.IntegerField()
|
||||||
@ -8,6 +10,7 @@ class Square(models.Model):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "%s ** 2 == %s" % (self.root, self.square)
|
return "%s ** 2 == %s" % (self.root, self.square)
|
||||||
|
|
||||||
|
|
||||||
class Person(models.Model):
|
class Person(models.Model):
|
||||||
first_name = models.CharField(max_length=20)
|
first_name = models.CharField(max_length=20)
|
||||||
last_name = models.CharField(max_length=20)
|
last_name = models.CharField(max_length=20)
|
||||||
@ -15,11 +18,25 @@ class Person(models.Model):
|
|||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'%s %s' % (self.first_name, self.last_name)
|
return u'%s %s' % (self.first_name, self.last_name)
|
||||||
|
|
||||||
|
|
||||||
class SchoolClass(models.Model):
|
class SchoolClass(models.Model):
|
||||||
year = models.PositiveIntegerField()
|
year = models.PositiveIntegerField()
|
||||||
day = models.CharField(max_length=9, blank=True)
|
day = models.CharField(max_length=9, blank=True)
|
||||||
last_updated = models.DateTimeField()
|
last_updated = models.DateTimeField()
|
||||||
|
|
||||||
|
# Unfortunately, the following model breaks MySQL hard.
|
||||||
|
# Until #13711 is fixed, this test can't be run under MySQL.
|
||||||
|
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':
|
||||||
|
class VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ(models.Model):
|
||||||
|
class Meta:
|
||||||
|
# We need to use a short actual table name or
|
||||||
|
# we hit issue #8548 which we're not testing!
|
||||||
|
verbose_name = 'model_with_long_table_name'
|
||||||
|
primary_key_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.AutoField(primary_key=True)
|
||||||
|
charfield_is_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.CharField(max_length=100)
|
||||||
|
m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz = models.ManyToManyField(Person,blank=True)
|
||||||
|
|
||||||
|
|
||||||
qn = connection.ops.quote_name
|
qn = connection.ops.quote_name
|
||||||
|
|
||||||
__test__ = {'API_TESTS': """
|
__test__ = {'API_TESTS': """
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Unit and doctests for specific database backends.
|
# Unit and doctests for specific database backends.
|
||||||
import datetime
|
import datetime
|
||||||
import models
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core import management
|
||||||
|
from django.core.management.color import no_style
|
||||||
from django.db import backend, connection, DEFAULT_DB_ALIAS
|
from django.db import backend, connection, DEFAULT_DB_ALIAS
|
||||||
from django.db.backends.signals import connection_created
|
from django.db.backends.signals import connection_created
|
||||||
from django.conf import settings
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
from regressiontests.backends import models
|
||||||
|
|
||||||
class Callproc(unittest.TestCase):
|
class Callproc(unittest.TestCase):
|
||||||
|
|
||||||
def test_dbms_session(self):
|
def test_dbms_session(self):
|
||||||
@ -76,6 +80,7 @@ class DateQuotingTest(TestCase):
|
|||||||
classes = models.SchoolClass.objects.filter(last_updated__day=20)
|
classes = models.SchoolClass.objects.filter(last_updated__day=20)
|
||||||
self.assertEqual(len(classes), 1)
|
self.assertEqual(len(classes), 1)
|
||||||
|
|
||||||
|
|
||||||
class ParameterHandlingTest(TestCase):
|
class ParameterHandlingTest(TestCase):
|
||||||
def test_bad_parameter_count(self):
|
def test_bad_parameter_count(self):
|
||||||
"An executemany call with too many/not enough parameters will raise an exception (Refs #12612)"
|
"An executemany call with too many/not enough parameters will raise an exception (Refs #12612)"
|
||||||
@ -88,6 +93,50 @@ class ParameterHandlingTest(TestCase):
|
|||||||
self.assertRaises(Exception, cursor.executemany, query, [(1,2,3),])
|
self.assertRaises(Exception, cursor.executemany, query, [(1,2,3),])
|
||||||
self.assertRaises(Exception, cursor.executemany, query, [(1,),])
|
self.assertRaises(Exception, cursor.executemany, query, [(1,),])
|
||||||
|
|
||||||
|
# Unfortunately, the following tests would be a good test to run on all
|
||||||
|
# backends, but it breaks MySQL hard. Until #13711 is fixed, it can't be run
|
||||||
|
# everywhere (although it would be an effective test of #13711).
|
||||||
|
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] != 'django.db.backends.mysql':
|
||||||
|
class LongNameTest(TestCase):
|
||||||
|
"""Long primary keys and model names can result in a sequence name
|
||||||
|
that exceeds the database limits, which will result in truncation
|
||||||
|
on certain databases (e.g., Postgres). The backend needs to use
|
||||||
|
the correct sequence name in last_insert_id and other places, so
|
||||||
|
check it is. Refs #8901.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_sequence_name_length_limits_create(self):
|
||||||
|
"""Test creation of model with long name and long pk name doesn't error. Ref #8901"""
|
||||||
|
models.VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ.objects.create()
|
||||||
|
|
||||||
|
def test_sequence_name_length_limits_m2m(self):
|
||||||
|
"""Test an m2m save of a model with a long name and a long m2m field name doesn't error as on Django >=1.2 this now uses object saves. Ref #8901"""
|
||||||
|
obj = models.VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ.objects.create()
|
||||||
|
rel_obj = models.Person.objects.create(first_name='Django', last_name='Reinhardt')
|
||||||
|
obj.m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.add(rel_obj)
|
||||||
|
|
||||||
|
def test_sequence_name_length_limits_flush(self):
|
||||||
|
"""Test that sequence resetting as part of a flush with model with long name and long pk name doesn't error. Ref #8901"""
|
||||||
|
# A full flush is expensive to the full test, so we dig into the
|
||||||
|
# internals to generate the likely offending SQL and run it manually
|
||||||
|
|
||||||
|
# Some convenience aliases
|
||||||
|
VLM = models.VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
|
||||||
|
VLM_m2m = VLM.m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz.through
|
||||||
|
tables = [
|
||||||
|
VLM._meta.db_table,
|
||||||
|
VLM_m2m._meta.db_table,
|
||||||
|
]
|
||||||
|
sequences = [
|
||||||
|
{
|
||||||
|
'column': VLM._meta.pk.column,
|
||||||
|
'table': VLM._meta.db_table
|
||||||
|
},
|
||||||
|
]
|
||||||
|
cursor = connection.cursor()
|
||||||
|
for statement in connection.ops.sql_flush(no_style(), tables, sequences):
|
||||||
|
cursor.execute(statement)
|
||||||
|
|
||||||
|
|
||||||
def connection_created_test(sender, **kwargs):
|
def connection_created_test(sender, **kwargs):
|
||||||
print 'connection_created signal'
|
print 'connection_created signal'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user