[Checkins] SVN: relstorage/ Implemented the database size query in MySQL, based on a patch from

Shane Hathaway shane at hathawaymix.org
Fri Dec 12 20:00:50 EST 2008


Log message for revision 94008:
  Implemented the database size query in MySQL, based on a patch from
  Kazuhiko Shiozaki.  Thanks!
  

Changed:
  U   relstorage/branches/1.1/CHANGES.txt
  U   relstorage/branches/1.1/relstorage/adapters/mysql.py
  U   relstorage/trunk/CHANGES.txt
  U   relstorage/trunk/relstorage/adapters/mysql.py

-=-
Modified: relstorage/branches/1.1/CHANGES.txt
===================================================================
--- relstorage/branches/1.1/CHANGES.txt	2008-12-12 22:57:01 UTC (rev 94007)
+++ relstorage/branches/1.1/CHANGES.txt	2008-12-13 01:00:50 UTC (rev 94008)
@@ -14,6 +14,10 @@
     replication slave at the exact same time(s) it exists on the
     master.
 
+- Implemented the database size query in MySQL, based on a patch from
+  Kazuhiko Shiozaki.  Thanks!
+
+
 RelStorage 1.1c1
 
 - Added optional memcache integration.  This is useful when the connection

Modified: relstorage/branches/1.1/relstorage/adapters/mysql.py
===================================================================
--- relstorage/branches/1.1/relstorage/adapters/mysql.py	2008-12-12 22:57:01 UTC (rev 94007)
+++ relstorage/branches/1.1/relstorage/adapters/mysql.py	2008-12-13 01:00:50 UTC (rev 94008)
@@ -277,8 +277,16 @@
 
     def get_db_size(self):
         """Returns the approximate size of the database in bytes"""
-        # do later
-        return 0
+        conn, cursor = self.open()
+        try:
+            cursor.execute("SHOW TABLE STATUS")
+            description = [i[0] for i in cursor.description]
+            rows = list(cursor)
+        finally:
+            self.close(conn, cursor)
+        data_column = description.index('Data_length')
+        index_column = description.index('Index_length')
+        return sum([row[data_column] + row[index_column] for row in rows], 0)
 
     def get_current_tid(self, cursor, oid):
         """Returns the current integer tid for an object.

Modified: relstorage/trunk/CHANGES.txt
===================================================================
--- relstorage/trunk/CHANGES.txt	2008-12-12 22:57:01 UTC (rev 94007)
+++ relstorage/trunk/CHANGES.txt	2008-12-13 01:00:50 UTC (rev 94008)
@@ -14,6 +14,10 @@
     replication slave at the exact same time(s) it exists on the
     master.
 
+- Implemented the database size query in MySQL, based on a patch from
+  Kazuhiko Shiozaki.  Thanks!
+
+
 RelStorage 1.1c1
 
 - Added optional memcache integration.  This is useful when the connection

Modified: relstorage/trunk/relstorage/adapters/mysql.py
===================================================================
--- relstorage/trunk/relstorage/adapters/mysql.py	2008-12-12 22:57:01 UTC (rev 94007)
+++ relstorage/trunk/relstorage/adapters/mysql.py	2008-12-13 01:00:50 UTC (rev 94008)
@@ -275,8 +275,16 @@
 
     def get_db_size(self):
         """Returns the approximate size of the database in bytes"""
-        # do later
-        return 0
+        conn, cursor = self.open()
+        try:
+            cursor.execute("SHOW TABLE STATUS")
+            description = [i[0] for i in cursor.description]
+            rows = list(cursor)
+        finally:
+            self.close(conn, cursor)
+        data_column = description.index('Data_length')
+        index_column = description.index('Index_length')
+        return sum([row[data_column] + row[index_column] for row in rows], 0)
 
     def get_current_tid(self, cursor, oid):
         """Returns the current integer tid for an object.



More information about the Checkins mailing list