Exemple #1
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)
Exemple #2
0
    def __enter__(self):
        return self

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.connexion.close()
        if exc_type:
            print(exc_val)


if __name__ == '__main__':

    # connection à la base
    with Connexion('example.db') as sqlite3:

        # ajout d'une personne
        L = ['Legrand', 'Julien']
        sqlite3.insert(L)

        # select
        print(sqlite3.select())

        # compte des personnes
        print(sqlite3.count('Legrand', 'Julien'))

        # Mis à jour de Julien Legrand
        sqlite3.update('Legrand', 'Julien', 0)

        # suppression de la personne
        sqlite3.delete('Legrand', 'Julien')
        print(sqlite3.count('Legrand', 'Julien'))
Exemple #3
0
def get_pages():
    return db.select("pages", order="id DESC")
Exemple #4
0
def get_page_by_id(id):
    try:
        return db.select("pages", where="id=$id", vars=locals())[0]
    except IndexError:
        return None
Exemple #5
0
def get_page_by_url(url):
    try:
        return db.select("pages", where="url=$url", vars=locals())[0]
    except IndexError:
        return None