def select_db(self): with app.app_context(): try: db = get_db() cursor = db.cursor() print self.sqlstr cursor.execute(self.sqlstr) self.result = cursor.fetchall() #get all data except: self.result=False return self.result
def init_db(): """Creates the database tables.""" with app.app_context(): db = get_db() f = open('.\schema.sql', 'r') try: db.cursor().execute(f.read()) except: print "create table failed" else: db.commit() finally: f.close()
def oper_db(self): with app.app_context(): try: db = get_db() cursor = db.cursor() print self.sqlstr if self.para: cursor.execute(self.sqlstr, self.para) else: cursor.execute(self.sqlstr) db.commit() except MySQLdb.IntegrityError,e: print e.args print "oper_db failed" self.result=False #return self.sqlstr else: