# Path: canary/utils.py
# class DTable:
#     """
#     Convenience class for rdbms-persisted object types.  Allows simple
#     loading of data for single-valued fields using set() and for multi-valued
#     fields using append().
#     """
#     
#     def set (self, field, value):
#         """
#         Dynamic field setting for simpler database lookups
#         """
#         if value == None:
#             setattr(self, str(field), str(''))
#         else:
#             setattr(self, str(field), value)
#        
#     #def append (self, field, value):
#     #    list_attr = getattr(self, str(field))
#     #    if not value in list_attr:
#     #        list_attr.append(value)
#     
#        
#     def get_new_uid (self, context):
#         cursor = context.get_cursor()
#         try:
#             cursor.execute('SELECT LAST_INSERT_ID() AS new_uid')
#             row = cursor.fetchone()
#             new_uid = int(row[0])
#         except:
#             new_uid = -1
#         return new_uid
#     
# 
#     def load (self, context):
#         cursor = context.get_cursor()
#         if self.uid:
#             cursor.execute("""SELECT * FROM """ + self.TABLE_NAME +
#                 """
#                 WHERE uid LIKE %s
#                 """, (self.uid))
#             fields = [d[0] for d in cursor.description]
#             desc = dtuple.TupleDescriptor([[f] for f in fields])
#             row = cursor.fetchone()
#             if row:
#                 row = dtuple.DatabaseTuple(desc, row)
#                 for field in fields:
#                     self.set(field, row[field])
#             else:
#                 context.logger.debug('No %s "%s"', self.TABLE_NAME, self.uid)
#                 print 'No %s "%s"' % (self.TABLE_NAME, self.uid)
#                 raise 'InvalidId'
#                 
# 
#     def delete (self, context):
#         cursor = context.get_cursor()
#         try:
#             if self.uid >= 0:
#                 cursor.execute("""DELETE FROM """ + self.TABLE_NAME +
#                     """
#                     WHERE uid = %s
#                     """, self.uid)
#         except Exception, e:
#             context.logger.error(e)


import dtuple
import time
from canary.utils import DTable
            """, self.uid)
        rows = cursor.fetchall()
        fields = [d[0] for d in cursor.description]
        desc = dtuple.TupleDescriptor([[f] for f in fields])
        if rows and len(rows) > 0:
            row = dtuple.DatabaseTuple(desc, rows[0])
            for field in fields:
                self.set(field, row[field])
        

    def save (self, context):
        cursor = context.get_cursor()
        if self.uid == -1:
            cursor.execute("""
                INSERT INTO terms
                (uid, name, description, date_modified,
                token, vocabulary_uid, source_id, is_multivalue,
                re_multivalue_sep, mapped_term_id)
                VALUES
                (NULL, %s, %s, CURDATE(),
                %s, %s, %s, %s,
                %s, %s)
                """, (self.name, self.description,
                    self.token, self.vocabulary_uid, self.source_id, int(self.is_multivalue),
                    self.re_multivalue_sep, self.mapped_term_id)
                )
        else:
            cursor.execute("""
                UPDATE terms
                SET name=%s, description=%s, date_modified=CURDATE(),

# Path: canary/utils.py
# class DTable:
#     """
#     Convenience class for rdbms-persisted object types.  Allows simple
#     loading of data for single-valued fields using set() and for multi-valued
#     fields using append().
#     """
#     
#     def set (self, field, value):
#         """
#         Dynamic field setting for simpler database lookups
#         """
#         if value == None:
#             setattr(self, str(field), str(''))
#         else:
#             setattr(self, str(field), value)
#        
#     #def append (self, field, value):
#     #    list_attr = getattr(self, str(field))
#     #    if not value in list_attr:
#     #        list_attr.append(value)
#     
#        
#     def get_new_uid (self, context):
#         cursor = context.get_cursor()
#         try:
#             cursor.execute('SELECT LAST_INSERT_ID() AS new_uid')
#             row = cursor.fetchone()
#             new_uid = int(row[0])
#         except:
#             new_uid = -1
#         return new_uid
#     
# 
#     def load (self, context):
#         cursor = context.get_cursor()
#         if self.uid:
#             cursor.execute("""SELECT * FROM """ + self.TABLE_NAME +
#                 """
#                 WHERE uid LIKE %s
#                 """, (self.uid))
#             fields = [d[0] for d in cursor.description]
#             desc = dtuple.TupleDescriptor([[f] for f in fields])
#             row = cursor.fetchone()
#             if row:
#                 row = dtuple.DatabaseTuple(desc, row)
#                 for field in fields:
#                     self.set(field, row[field])
#             else:
#                 context.logger.debug('No %s "%s"', self.TABLE_NAME, self.uid)
#                 print 'No %s "%s"' % (self.TABLE_NAME, self.uid)
#                 raise 'InvalidId'
#                 
# 
#     def delete (self, context):
#         cursor = context.get_cursor()
#         try:
#             if self.uid >= 0:
#                 cursor.execute("""DELETE FROM """ + self.TABLE_NAME +
#                     """
#                     WHERE uid = %s
#                     """, self.uid)
#         except Exception, e:
#             context.logger.error(e)


# Path: canary/source_catalog.py
import dtuple
import time
from canary.utils import DTable

            """, self.uid)
        rows = cursor.fetchall()
        fields = [d[0] for d in cursor.description]
        desc = dtuple.TupleDescriptor([[f] for f in fields])
        if rows and len(rows) > 0:
            row = dtuple.DatabaseTuple(desc, rows[0])
            for field in fields:
                self.set(field, row[field])
        

    def save (self, context):
        cursor = context.get_cursor()
        if self.uid == -1:
            cursor.execute("""
                INSERT INTO terms
                (uid, name, description, date_modified,
                token, vocabulary_uid, source_id, is_multivalue,
                re_multivalue_sep, mapped_term_id)
                VALUES
                (NULL, %s, %s, CURDATE(),
                %s, %s, %s, %s,
                %s, %s)
                """, (self.name, self.description,
                    self.token, self.vocabulary_uid, self.source_id, int(self.is_multivalue),
                    self.re_multivalue_sep, self.mapped_term_id)
                )
        else:
            cursor.execute("""
                UPDATE terms
                SET name=%s, description=%s, date_modified=CURDATE(),

                token=%s, vocabulary_uid=%s, source_id=%s,