Changeset 5463 for django/branches/boulder-oracle-sprint/django/db
- Timestamp:
- 06/11/07 10:53:42 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/boulder-oracle-sprint/django/db/backends/postgresql/base.py
r5307 r5463 239 239 output = [] 240 240 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. 241 244 for f in model._meta.fields: 242 245 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;" % \ 244 247 (style.SQL_KEYWORD('SELECT'), 245 248 style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 246 style.SQL_KEYWORD('SELECT'),247 249 style.SQL_FIELD(quote_name(f.column)), 250 style.SQL_FIELD(quote_name(f.column)), 251 style.SQL_KEYWORD('IS NOT'), 248 252 style.SQL_KEYWORD('FROM'), 249 253 style.SQL_TABLE(quote_name(model._meta.db_table)))) 250 254 break # Only one AutoField is allowed per model, so don't bother continuing. 251 255 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;" % \ 253 257 (style.SQL_KEYWORD('SELECT'), 254 258 style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 255 style.SQL_KEYWORD('SELECT'),256 259 style.SQL_FIELD(quote_name('id')), 260 style.SQL_FIELD(quote_name('id')), 261 style.SQL_KEYWORD('IS NOT'), 257 262 style.SQL_KEYWORD('FROM'), 258 263 style.SQL_TABLE(f.m2m_db_table()))) django/branches/boulder-oracle-sprint/django/db/backends/postgresql_psycopg2/base.py
r5235 r5463 196 196 output = [] 197 197 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. 198 201 for f in model._meta.fields: 199 202 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;" % \ 201 204 (style.SQL_KEYWORD('SELECT'), 202 205 style.SQL_FIELD(quote_name('%s_%s_seq' % (model._meta.db_table, f.column))), 203 style.SQL_KEYWORD('SELECT'),204 206 style.SQL_FIELD(quote_name(f.column)), 207 style.SQL_FIELD(quote_name(f.column)), 208 style.SQL_KEYWORD('IS NOT'), 205 209 style.SQL_KEYWORD('FROM'), 206 210 style.SQL_TABLE(quote_name(model._meta.db_table)))) 207 211 break # Only one AutoField is allowed per model, so don't bother continuing. 208 212 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;" % \ 210 214 (style.SQL_KEYWORD('SELECT'), 211 215 style.SQL_FIELD(quote_name('%s_id_seq' % f.m2m_db_table())), 212 style.SQL_KEYWORD('SELECT'),213 216 style.SQL_FIELD(quote_name('id')), 217 style.SQL_FIELD(quote_name('id')), 218 style.SQL_KEYWORD('IS NOT'), 214 219 style.SQL_KEYWORD('FROM'), 215 220 style.SQL_TABLE(f.m2m_db_table()))) django/branches/boulder-oracle-sprint/django/db/backends/util.py
r5307 r5463 93 93 94 94 def typecast_decimal(s): 95 if s is None :95 if s is None or s == '': 96 96 return None 97 97 return decimal.Decimal(s)
