Author: justi9
Date: 2010-07-29 14:29:31 -0400 (Thu, 29 Jul 2010)
New Revision: 4167
Modified:
mgmt/newdata/cumin/python/cumin/sqladapter.py
mgmt/newdata/mint/python/mint/expire.py
mgmt/newdata/rosemary/python/rosemary/model.py
mgmt/newdata/rosemary/python/rosemary/sqloperation.py
Log:
Don't require columns in sqlop execute calls
Modified: mgmt/newdata/cumin/python/cumin/sqladapter.py
===================================================================
--- mgmt/newdata/cumin/python/cumin/sqladapter.py 2010-07-29 17:28:53 UTC (rev 4166)
+++ mgmt/newdata/cumin/python/cumin/sqladapter.py 2010-07-29 18:29:31 UTC (rev 4167)
@@ -20,7 +20,7 @@
cursor = conn.cursor()
try:
- self.query.execute(cursor, ("count(1)",), values)
+ self.query.execute(cursor, values, columns=("count(1)",))
return cursor.fetchone()[0]
finally:
@@ -45,7 +45,9 @@
cursor = conn.cursor()
try:
- self.query.execute(cursor, self.columns, values, sql_options)
+ self.query.execute(cursor, values,
+ columns=self.columns,
+ options=sql_options)
return cursor.fetchall()
finally:
Modified: mgmt/newdata/mint/python/mint/expire.py
===================================================================
--- mgmt/newdata/mint/python/mint/expire.py 2010-07-29 17:28:53 UTC (rev 4166)
+++ mgmt/newdata/mint/python/mint/expire.py 2010-07-29 18:29:31 UTC (rev 4167)
@@ -50,7 +50,7 @@
log.info("Expired %i samples", count)
def delete_samples(self, cursor, cls, seconds):
- cls.sql_samples_delete.execute(cursor, (), {"seconds": seconds})
+ cls.sql_samples_delete.execute(cursor, {"seconds": seconds})
log.debug("Deleted %i %s", cursor.rowcount, cls)
Modified: mgmt/newdata/rosemary/python/rosemary/model.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/model.py 2010-07-29 17:28:53 UTC (rev 4166)
+++ mgmt/newdata/rosemary/python/rosemary/model.py 2010-07-29 18:29:31 UTC (rev 4167)
@@ -344,7 +344,6 @@
self.sql_samples_delete = SqlDeleteObjectSamples(table)
def get_object(self, cursor, **criteria):
- columns = self.sql_table._columns
sql = SqlSelect(self.sql_table)
for name in criteria:
@@ -353,7 +352,7 @@
column = self.sql_table._columns_by_name[name]
sql.add_filter(SqlValueFilter(column))
- sql.execute(cursor, columns, criteria)
+ sql.execute(cursor, criteria)
record = cursor.fetchone()
@@ -362,14 +361,12 @@
obj = RosemaryObject(self, None)
- self.set_object_attributes(obj, columns, record)
+ self.set_object_attributes(obj, self.sql_table._columns, record)
return obj
def get_selection(self, cursor, **criteria):
selection = list()
-
- columns = self.sql_table._columns
sql = SqlSelect(self.sql_table)
for name in criteria:
@@ -378,12 +375,12 @@
column = self.sql_table._columns_by_name[name]
sql.add_filter(SqlValueFilter(column))
- sql.execute(cursor, columns, criteria)
+ sql.execute(cursor, criteria)
for record in cursor.fetchall():
obj = RosemaryObject(self, None)
- self.set_object_attributes(obj, columns, record)
+ self.set_object_attributes(obj, self.sql_table._columns, record)
selection.append(obj)
@@ -408,7 +405,7 @@
return obj
def get_new_id(self, cursor):
- self.sql_get_new_id.execute(cursor, ())
+ self.sql_get_new_id.execute(cursor)
values = cursor.fetchone()
@@ -425,31 +422,28 @@
assert isinstance(obj, RosemaryObject)
assert obj._id, obj
- columns = self.sql_table._columns
- self.sql_select_by_id.execute(cursor, columns, obj.__dict__)
+ self.sql_select_by_id.execute(cursor, obj.__dict__)
values = cursor.fetchone()
if not values:
raise RosemaryNotFound()
- self.set_object_attributes(obj, columns, values)
+ self.set_object_attributes(obj, self.sql_table._columns, values)
def load_object_by_qmf_id(self, cursor, obj):
assert isinstance(obj, RosemaryObject)
assert obj._qmf_agent_id, obj
assert obj._qmf_object_id, obj
- columns = self.sql_table._columns
+ self.sql_select_by_qmf_id.execute(cursor, obj.__dict__)
- self.sql_select_by_qmf_id.execute(cursor, columns, obj.__dict__)
-
values = cursor.fetchone()
if not values:
raise RosemaryNotFound()
- self.set_object_attributes(obj, columns, values)
+ self.set_object_attributes(obj, self.sql_table._columns, values)
def set_object_attributes(self, obj, columns, values):
assert isinstance(obj, RosemaryObject)
@@ -463,13 +457,15 @@
assert isinstance(obj, RosemaryObject)
assert obj._id, obj
+ if obj._sync_time:
+ sql = self.sql_update_object
+ else:
+ sql = self.sql_insert_object
+
if columns is None:
columns = self.sql_table._columns
- if obj._sync_time:
- self.sql_update_object.execute(cursor, columns, obj.__dict__)
- else:
- self.sql_insert_object.execute(cursor, columns, obj.__dict__)
+ sql.execute(cursor, obj.__dict__, columns=columns)
obj._sync_time = datetime.now()
@@ -480,13 +476,13 @@
if columns is None:
columns = self.sql_table._columns
- self.sql_samples_insert.execute(cursor, columns, obj.__dict__)
+ self.sql_samples_insert.execute(cursor, obj.__dict__, columns=columns)
def delete_object(self, cursor, obj):
assert isinstance(obj, RosemaryObject)
assert obj._id
- self.sql_delete_object.execute(cursor, (), obj.__dict__)
+ self.sql_delete_object.execute(cursor, obj.__dict__)
def delete_selection(self, cursor, **criteria):
sql = SqlDelete(self.sql_table)
@@ -495,7 +491,7 @@
column = self.sql_table._columns_by_name[name]
sql.add_filter(SqlValueFilter(column))
- sql.execute(cursor, (), criteria)
+ sql.execute(cursor, criteria)
return cursor.rowcount
Modified: mgmt/newdata/rosemary/python/rosemary/sqloperation.py
===================================================================
--- mgmt/newdata/rosemary/python/rosemary/sqloperation.py 2010-07-29 17:28:53 UTC (rev
4166)
+++ mgmt/newdata/rosemary/python/rosemary/sqloperation.py 2010-07-29 18:29:31 UTC (rev
4167)
@@ -15,7 +15,10 @@
def get_filter_exprs(self):
return " and ".join([x.emit() for x in self.filters])
- def execute(self, cursor, columns, values=None, options=None):
+ def execute(self, cursor, values=None, columns=None, options=None):
+ if columns is None:
+ columns = self.table._columns
+
text = self.emit(columns, options)
if values is None: