﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
490	[patch] incorrect handling of cursor.rowcount	eugene@…	Adrian Holovaty	"According to http://www.python.org/peps/pep-0249.html cursor.rowcount can be -1:

{{{
The attribute is -1 in case no executeXXX() has been
performed on the cursor or the rowcount of the last
operation is not determinable by the interface. [7]
}}}

E.g., SQLite3 returns -1 (hardcoded?).

This patch should fix it:

{{{
Index: management.py
===================================================================
--- management.py	(revision 635)
+++ management.py	(working copy)
@@ -218,7 +218,12 @@
 
     # Check that the package exists in the database.
     cursor.execute(""SELECT 1 FROM packages WHERE label = %s"", [app_label])
-    if cursor.rowcount < 1:
+    if cursor.rowcount < 0:
+        # can be -1 (==undetermined) according to http://www.python.org/peps/pep-0249.html
+        flag = cursor.fetchone() is None
+    else:
+        flag = cursor.rowcount < 1
+    if flag:
 #         sys.stderr.write(""The '%s' package isn't installed.\n"" % app_label)
         print _get_packages_insert(app_label)
 
@@ -232,11 +237,21 @@
         contenttypes_seen[opts.module_name] = 1
         for codename, name in perms:
             cursor.execute(""SELECT 1 FROM auth_permissions WHERE package = %s AND codename = %s"", (app_label, codename))
-            if cursor.rowcount < 1:
+            if cursor.rowcount < 0:
+                # can be -1 (==undetermined) according to http://www.python.org/peps/pep-0249.html
+                flag = cursor.fetchone() is None
+            else:
+                flag = cursor.rowcount < 1
+            if flag:
 #                 sys.stderr.write(""The '%s.%s' permission doesn't exist.\n"" % (app_label, codename))
                 print _get_permission_insert(name, codename, opts)
         cursor.execute(""SELECT 1 FROM content_types WHERE package = %s AND python_module_name = %s"", (app_label, opts.module_name))
-        if cursor.rowcount < 1:
+        if cursor.rowcount < 0:
+            # can be -1 (==undetermined) according to http://www.python.org/peps/pep-0249.html
+            flag = cursor.fetchone() is None
+        else:
+            flag = cursor.rowcount < 1
+        if flag:
 #             sys.stderr.write(""The '%s.%s' content type doesn't exist.\n"" % (app_label, opts.module_name))
             print _get_contenttype_insert(opts)
}}}"	defect	closed	Core (Management commands)		normal	fixed			Ready for checkin	1	0	0	0	0	0
