Django

Code

Changeset 2289

Show
Ignore:
Timestamp:
02/07/06 12:47:32 (3 years ago)
Author:
lukeplant
Message:

magic-removal: Fixed use of return value of cursor.execute() in m2m add() and added a test to make sure

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/fields/related.py

    r2287 r2289  
    124124    new_ids = set([obj._get_pk_val() for obj in objs]) 
    125125    cursor = connection.cursor() 
    126     rowcount = cursor.execute("SELECT %s FROM %s WHERE %s = %%s AND %s IN (%s)" % \ 
     126    cursor.execute("SELECT %s FROM %s WHERE %s = %%s AND %s IN (%s)" % \ 
    127127        (rel_col_name, join_table, this_col_name, 
    128128        rel_col_name, ",".join(['%s'] * len(new_ids))),  
    129129        [this_pk_val] + list(new_ids)) 
    130     existing_ids = set([row[0] for row in cursor.fetchmany(rowcount)]) 
     130    if cursor.rowcount is not None and cursor.rowcount > 0: 
     131        existing_ids = set([row[0] for row in cursor.fetchmany(cursor.rowcount)]) 
     132    else: 
     133        existing_ids = set() 
    131134 
    132135    # Add the ones that aren't there already 
  • django/branches/magic-removal/tests/modeltests/many_to_many/models.py

    r2275 r2289  
    4343>>> a2.save() 
    4444>>> a2.publications.add(p1, p2) 
     45>>> a2.publications.add(p3) 
     46 
     47# Adding a second time is OK 
    4548>>> a2.publications.add(p3) 
    4649