Beispiel #1
0
    def POST(self):
        db = web.database(dbn='sqlite', db='./msg.db')
        i = web.input('content')
        n = web.input('user')
        #print(i, n)
        now = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        rc = db.query("SELECT COUNT(*) AS count FROM msgs")[0]
        db.insert('msgs', id=rc.count+1, name=n.user, date=now, content=i.content)

        cp = (rc.count+1) / perp
        cp = (cp + 1) if ((rc.count+1) % perp > 0) else cp
        print('cnt=', rc.count+1, 'cp=', cp)
        return web.seeother('/'+str(cp))
Beispiel #2
0
 def GET(self, page=1):
     #实例化sqldb,然后读取内容
     s = ''
     db = web.database(dbn='sqlite', db='./msg.db')
     
     page = 1 if (page=='') else int(page)
     offset = (page - 1) * perp
     rt = db.select('msgs', order='id', what='id, content, date, name', offset=offset, limit=perp)
     rc = db.query("SELECT COUNT(*) AS count FROM msgs")[0]
     print(rc)
     pages = rc.count / perp
     pages = (pages + 1) if (rc.count % perp > 0) else pages
     if page > pages:
         raise web.seeother('/')
     else:
         return render.index(rcs=rt, pages=pages, page=page)
Beispiel #3
0
def read_fields_from_tscheduler():
    sql = "select * from Field"
    db = FieldsDatabase()
    res = db.query(sql)
    names = ['field_id', 'fov_rad', 'RA', 'dec', 'gl', 'gb', 'el', 'eb', 'tag']
    types = [int, float, float, float, float, float, float, float, int]
    fields = np.zeros(len(res), dtype=list(zip(names, types)))

    for i, row in enumerate(res):
        fields['field_id'][i] = row[0]
        fields['fov_rad'][i] = row[1]
        fields['RA'][i] = np.radians(row[2])
        fields['dec'][i] = np.radians(row[3])
        fields['gl'][i] = row[4]
        fields['gb'][i] = row[5]
        fields['el'][i] = row[6]
        fields['eb'][i] = row[7]

    return fields
            return True
        except Exception, e:
            print str(e)
            self.cur.close()
        return False

    def excute(self, sql):
        self.cur = self.con.cursor()
        try:
            self.cur.execute(sql)
            self.con.commit()
            self.cur.close()
            return True
        except Exception, e:
            print str(e)
            self.cur.close()
        return False

    # 关闭数据库连接
    def close(self):
        if self.cur is not None:
            self.cur.close()
        self.con.close()

if __name__ == "__main__":
    sql = "insert into test values(?,?)"

    db = SqlLiteHandle(r'C:\Users\29625\Desktop\tt.db')
    #db.insert(sql, [(1, "hx")])
    res = db.query("select * from tt_1")
    print res