Exemple #1
0
 def create(self):
     columns = ",".join(self.__class__.db_columns)
     values = [getattr(self, x) for x in self.__class__.db_columns]
     nvalues = ",".join(["?"] * len(values))
     sql = """INSERT INTO %s (%s) values(%s)""" % (self.__class__.__name__, columns, nvalues)
     DB.query(sql, values)
     x = DB.last_id
     self.id = x
Exemple #2
0
    def update(self):
        columns = [t + "=?" for t in self.__class__.db_columns[1:]]
        columns = ",".join(columns)

        values = [getattr(self, x) for x in self.__class__.db_columns[1:]]
        values.append(self.id)
        sql = """UPDATE %s set %s where id=?""" % (self.__class__.__name__, columns)

        DB.query(sql, values)
Exemple #3
0
    def update(self):
        columns = [t + "=?" for t in self.__class__.db_columns[1:]]
        columns = ",".join(columns)

        values = [getattr(self, x) for x in self.__class__.db_columns[1:]]
        values.append(self.id)
        sql = """UPDATE %s set %s where id=?""" % (self.__class__.__name__,
                                                   columns)

        DB.query(sql, values)
Exemple #4
0
 def delete(self):
     sql = """DELETE FROM %s WHERE id=?""" % (self.__class__.__name__)
     DB.query(sql, (self.id,))
Exemple #5
0
 def findBySQL(cls, sql, data):
     result_set = DB.query(sql, data)
     result_list = []
     for item in result_set:
         result_list.append(cls.instantiate(item))
     return result_list
 def delete(self):
     sql = """DELETE FROM %s WHERE id=?""" % (self.__class__.__name__)
     DB.query(sql, (self.id, ))
 def findBySQL(cls, sql, data):
     result_set = DB.query(sql, data)
     result_list = []
     for item in result_set:
         result_list.append(cls.instantiate(item))
     return result_list