~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to django/db/backends/mysql/creation.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This dictionary maps Field objects to their associated MySQL column
2
 
# types, as strings. Column-type strings can contain format strings; they'll
3
 
# be interpolated against the values of Field.__dict__ before being output.
4
 
# If a column type is set to None, it won't be included in the output.
5
 
DATA_TYPES = {
6
 
    'AutoField':         'integer AUTO_INCREMENT',
7
 
    'BooleanField':      'bool',
8
 
    'CharField':         'varchar(%(maxlength)s)',
9
 
    'CommaSeparatedIntegerField': 'varchar(%(maxlength)s)',
10
 
    'DateField':         'date',
11
 
    'DateTimeField':     'datetime',
12
 
    'FileField':         'varchar(100)',
13
 
    'FilePathField':     'varchar(100)',
14
 
    'FloatField':        'numeric(%(max_digits)s, %(decimal_places)s)',
15
 
    'ImageField':        'varchar(100)',
16
 
    'IntegerField':      'integer',
17
 
    'IPAddressField':    'char(15)',
18
 
    'ManyToManyField':   None,
19
 
    'NullBooleanField':  'bool',
20
 
    'OneToOneField':     'integer',
21
 
    'PhoneNumberField':  'varchar(20)',
22
 
    'PositiveIntegerField': 'integer UNSIGNED',
23
 
    'PositiveSmallIntegerField': 'smallint UNSIGNED',
24
 
    'SlugField':         'varchar(%(maxlength)s)',
25
 
    'SmallIntegerField': 'smallint',
26
 
    'TextField':         'longtext',
27
 
    'TimeField':         'time',
28
 
    'USStateField':      'varchar(2)',
29
 
}
 
1
from django.conf import settings
 
2
from django.db.backends.creation import BaseDatabaseCreation
 
3
 
 
4
class DatabaseCreation(BaseDatabaseCreation):
 
5
    # This dictionary maps Field objects to their associated MySQL column
 
6
    # types, as strings. Column-type strings can contain format strings; they'll
 
7
    # be interpolated against the values of Field.__dict__ before being output.
 
8
    # If a column type is set to None, it won't be included in the output.
 
9
    data_types = {
 
10
        'AutoField':         'integer AUTO_INCREMENT',
 
11
        'BooleanField':      'bool',
 
12
        'CharField':         'varchar(%(max_length)s)',
 
13
        'CommaSeparatedIntegerField': 'varchar(%(max_length)s)',
 
14
        'DateField':         'date',
 
15
        'DateTimeField':     'datetime',
 
16
        'DecimalField':      'numeric(%(max_digits)s, %(decimal_places)s)',
 
17
        'FileField':         'varchar(%(max_length)s)',
 
18
        'FilePathField':     'varchar(%(max_length)s)',
 
19
        'FloatField':        'double precision',
 
20
        'IntegerField':      'integer',
 
21
        'IPAddressField':    'char(15)',
 
22
        'NullBooleanField':  'bool',
 
23
        'OneToOneField':     'integer',
 
24
        'PositiveIntegerField': 'integer UNSIGNED',
 
25
        'PositiveSmallIntegerField': 'smallint UNSIGNED',
 
26
        'SlugField':         'varchar(%(max_length)s)',
 
27
        'SmallIntegerField': 'smallint',
 
28
        'TextField':         'longtext',
 
29
        'TimeField':         'time',
 
30
    }
 
31
 
 
32
    def sql_table_creation_suffix(self):
 
33
        suffix = []
 
34
        if settings.TEST_DATABASE_CHARSET:
 
35
            suffix.append('CHARACTER SET %s' % settings.TEST_DATABASE_CHARSET)
 
36
        if settings.TEST_DATABASE_COLLATION:
 
37
            suffix.append('COLLATE %s' % settings.TEST_DATABASE_COLLATION)
 
38
        return ' '.join(suffix)
 
39
 
 
40
    def sql_for_inline_foreign_key_references(self, field, known_models, style):
 
41
        "All inline references are pending under MySQL"
 
42
        return [], True
 
43
        
 
44
    def sql_for_inline_many_to_many_references(self, model, field, style):
 
45
        from django.db import models
 
46
        opts = model._meta
 
47
        qn = self.connection.ops.quote_name
 
48
        
 
49
        table_output = [
 
50
            '    %s %s %s,' %
 
51
                (style.SQL_FIELD(qn(field.m2m_column_name())),
 
52
                style.SQL_COLTYPE(models.ForeignKey(model).db_type()),
 
53
                style.SQL_KEYWORD('NOT NULL')),
 
54
            '    %s %s %s,' %
 
55
            (style.SQL_FIELD(qn(field.m2m_reverse_name())),
 
56
            style.SQL_COLTYPE(models.ForeignKey(field.rel.to).db_type()),
 
57
            style.SQL_KEYWORD('NOT NULL'))
 
58
        ]
 
59
        deferred = [
 
60
            (field.m2m_db_table(), field.m2m_column_name(), opts.db_table,
 
61
                opts.pk.column),
 
62
            (field.m2m_db_table(), field.m2m_reverse_name(),
 
63
                field.rel.to._meta.db_table, field.rel.to._meta.pk.column)
 
64
            ]
 
65
        return table_output, deferred
 
66
        
 
 
b'\\ No newline at end of file'