Exemple #1
0
 def save(self):
     if hasattr(self, 'id'):
         sql = '''
         update authors set (id,name)=({id}, '{name}')
         where id = {id};
         '''.format(name=self.name, id=self.id)
     else:
         sql = '''
         insert into authors(name) values('{name}');
         '''.format(name=self.name)
     cur = Connection().getConnection().cursor()
     print sql
     cur.execute(sql)
Exemple #2
0
 def get(self, id=None, name=None, article=None):
     sql = 'select * from %s where true ' % self.__tableName__
     if id:
         sql += 'and id = %s ' % str(id)
     if name:
         sql += 'and name = \'%s\' ' % str(name)
     if article:
         # TODO change authors_id to self.__tableName__
         sql += '''
         and exists(
             select * from authorlists as al
             where\'%s\' = al.article_id
             and al.author_id = authors.id
         )
         ''' % article
     cur = Connection().getConnection()
     cur = cur.cursor()
     cur.execute(sql)
     authors = []
     for data in cur.fetchall():
         print data
         author = self.__model__(data)
         authors.append(author)
     return authors