Django

Code

Show
Ignore:
Timestamp:
06/11/07 10:53:42 (2 years ago)
Author:
bouldersprinters
Message:

boulder-oracle-sprint: Merged to [5462]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/boulder-oracle-sprint/django/db/backends/postgresql/base.py

    r5307 r5463  
    239239    output = [] 
    240240    for model in model_list: 
     241        # Use `coalesce` to set the sequence for each model to the max pk value if there are records, 
     242        # or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true 
     243        # if there are records (as the max pk value is already in use), otherwise set it to false. 
    241244        for f in model._meta.fields: 
    242245            if isinstance(f, models.AutoField): 
    243                 output.append("%s setval('%s', (%s max(%s) %s %s));" % \ 
     246                output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 
    244247                    (style.SQL_KEYWORD('SELECT'), 
    245248                    style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 
    246                     style.SQL_KEYWORD('SELECT'), 
    247249                    style.SQL_FIELD(quote_name(f.column)), 
     250                    style.SQL_FIELD(quote_name(f.column)), 
     251                    style.SQL_KEYWORD('IS NOT'), 
    248252                    style.SQL_KEYWORD('FROM'), 
    249253                    style.SQL_TABLE(quote_name(model._meta.db_table)))) 
    250254                break # Only one AutoField is allowed per model, so don't bother continuing. 
    251255        for f in model._meta.many_to_many: 
    252             output.append("%s setval('%s', (%s max(%s) %s %s));" % \ 
     256            output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 
    253257                (style.SQL_KEYWORD('SELECT'), 
    254258                style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 
    255                 style.SQL_KEYWORD('SELECT'), 
    256259                style.SQL_FIELD(quote_name('id')), 
     260                style.SQL_FIELD(quote_name('id')), 
     261                style.SQL_KEYWORD('IS NOT'), 
    257262                style.SQL_KEYWORD('FROM'), 
    258263                style.SQL_TABLE(f.m2m_db_table()))) 
  • django/branches/boulder-oracle-sprint/django/db/backends/postgresql_psycopg2/base.py

    r5235 r5463  
    196196    output = [] 
    197197    for model in model_list: 
     198        # Use `coalesce` to set the sequence for each model to the max pk value if there are records, 
     199        # or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true 
     200        # if there are records (as the max pk value is already in use), otherwise set it to false. 
    198201        for f in model._meta.fields: 
    199202            if isinstance(f, models.AutoField): 
    200                 output.append("%s setval('%s', (%s max(%s) %s %s));" % \ 
     203                output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 
    201204                    (style.SQL_KEYWORD('SELECT'), 
    202205                    style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 
    203                     style.SQL_KEYWORD('SELECT'), 
    204206                    style.SQL_FIELD(quote_name(f.column)), 
     207                    style.SQL_FIELD(quote_name(f.column)), 
     208                    style.SQL_KEYWORD('IS NOT'), 
    205209                    style.SQL_KEYWORD('FROM'), 
    206210                    style.SQL_TABLE(quote_name(model._meta.db_table)))) 
    207211                break # Only one AutoField is allowed per model, so don't bother continuing. 
    208212        for f in model._meta.many_to_many: 
    209             output.append("%s setval('%s', (%s max(%s) %s %s));" % \ 
     213            output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 
    210214                (style.SQL_KEYWORD('SELECT'), 
    211215                style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 
    212                 style.SQL_KEYWORD('SELECT'), 
    213216                style.SQL_FIELD(quote_name('id')), 
     217                style.SQL_FIELD(quote_name('id')), 
     218                style.SQL_KEYWORD('IS NOT'), 
    214219                style.SQL_KEYWORD('FROM'), 
    215220                style.SQL_TABLE(f.m2m_db_table()))) 
  • django/branches/boulder-oracle-sprint/django/db/backends/util.py

    r5307 r5463  
    9393 
    9494def typecast_decimal(s): 
    95     if s is None
     95    if s is None or s == ''
    9696        return None 
    9797    return decimal.Decimal(s)