0001-reuse-older-id-for-open-item-fields-fixes-25982.patch
wcs_olap/feeder.py | ||
---|---|---|
611 | 611 |
vars=(u'evolution des demandes %s' % self.formdef.schema.name,)) |
612 | 612 | |
613 | 613 |
def insert_item_value(self, field, value): |
614 |
'''Generate a new id for the value of an open item field, or user the |
|
615 |
older one from an existing table in the previous schema.''' |
|
614 | 616 |
table_name = self.hash_table_name('{formdata_table}_field_%s' % field.varname) |
617 | ||
618 |
try: |
|
619 |
self.ex('SELECT label FROM {schema}.{item_table} WHERE label = %s', vars=[value], |
|
620 |
ctx={'item_table': table_name}) |
|
621 |
except psycopg2.Error: |
|
622 |
pass |
|
623 |
else: |
|
624 |
# value found in an existing table |
|
625 |
try: |
|
626 |
old_id = self.cur.fetchone()[0] |
|
627 |
self.ex('INSERT INTO {item_table} (id, label) VALUES (%s, %s)', vars=[old_id, value], |
|
628 |
ctx={'item_table': table_name}) |
|
629 |
sequence_name = table_name[:63 - len('_id_seq')] + '_id_seq' |
|
630 |
selx.ex('SELECT SETVAL(%s, (SELECT MAX(id) from {item_table}))', vars=[sequence_name], |
|
631 |
ctx={'item_table': table_name}) |
|
632 |
return old_id |
|
633 |
except IndexError: |
|
634 |
pass |
|
635 |
# value is unknown, regular case |
|
615 | 636 |
self.ex('INSERT INTO {item_table} (label) VALUES (%s) RETURNING (id)', vars=[value], |
616 | 637 |
ctx={'item_table': table_name}) |
617 | 638 |
return self.cur.fetchone()[0] |
618 |
- |