Django

Code

Changeset 1483

Show
Ignore:
Timestamp:
11/28/05 19:04:28 (3 years ago)
Author:
adrian
Message:

Fixed #490 -- Fixed incorrect handling of cursor.rowcount in yet-unused database_check functionality. Thanks, Eugene

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/management.py

    r1474 r1483  
    264264get_sql_all.args = APP_ARGS 
    265265 
     266def has_no_records(cursor): 
     267    "Returns True if the cursor, having executed a query, returned no records." 
     268    # This is necessary due to an inconsistency in the DB-API spec. 
     269    # cursor.rowcount can be -1 (undetermined), according to 
     270    # http://www.python.org/peps/pep-0249.html 
     271    if cursor.rowcount < 0: 
     272        return cursor.fetchone() is None 
     273    return cursor.rowcount < 1 
     274 
    266275def database_check(mod): 
    267276    "Checks that everything is properly installed in the database for the given module." 
     
    273282    cursor.execute("SELECT 1 FROM %s WHERE %s = %%s" % \ 
    274283        (db.db.quote_name('packages'), db.db.quote_name('label')), [app_label]) 
    275     if cursor.rowcount < 1
     284    if has_no_records(cursor)
    276285#         sys.stderr.write("The '%s' package isn't installed.\n" % app_label) 
    277286        print _get_packages_insert(app_label) 
     
    289298                (db.db.quote_name('auth_permissions'), db.db.quote_name('package'), 
    290299                db.db.quote_name('codename')), (app_label, codename)) 
    291             if cursor.rowcount < 1
     300            if has_no_records(cursor)
    292301#                 sys.stderr.write("The '%s.%s' permission doesn't exist.\n" % (app_label, codename)) 
    293302                print _get_permission_insert(name, codename, opts) 
     
    295304            (db.db.quote_name('content_types'), db.db.quote_name('package'), 
    296305            db.db.quote_name('python_module_name')), (app_label, opts.module_name)) 
    297         if cursor.rowcount < 1
     306        if has_no_records(cursor)
    298307#             sys.stderr.write("The '%s.%s' content type doesn't exist.\n" % (app_label, opts.module_name)) 
    299308            print _get_contenttype_insert(opts)