def get_word_count_top(Number): """ Returns the Top "Number" in much talking by luke86 """ conn = sqlite3.connection('database.sqlite3') c = conn.cursor() c.execute("SELECT TOP 10 user,words FROM word_count ORDER BY words DESC;") res = c.fetchall() return res[Number]
def view_prescription(): conn=sqlite3.connection("Health_Monitoring.db") cur=conn.cursor() query='SELECT * FROM prescription WHERE uid=username2' cur.execute(query) if(query): info=cur.fetchall() view_prescription(info) else: messagebox.showerror("Invalid patient")
def insert(): medicine_name=medicine_name.get() mg=mg.get() timings=timings.get() entry.delete(0,END) entry1.delete(0,END) entry2.delete(0,END) conn=sqlite3.connection("Health_Monitoring.db") cur=conn.cursor() cur.execute('INSERT INTO prescription (pid,tablet_mg,timing) VALUE(medicine_name,mg,timings) WHERE pid=id1') cur.commit() messagebox.show("Inserted the record successfully.")
def adduser(ID, PW): connection = sqlite3.connection("session.db") p = ("select * from stuff where ID = %s", ID) cursor = connection.execute(p) if p != null: return 1 q = ("insert into stuff(ID, PW) values('%s','%s')", ID, PW) cursor = connection.execute(q) connection.commit() return 0
def display_patient_detail(): global id1 = enter_id.get() entry.delete(0,END) conn=sqlite3.connection("Health_Monitoring.db") cur=conn.cursor() query = SELECT * FROM patient_detail WHERE pid=id1 cur.execute(query) if(query): info=cur.fetchall() patient_detail(info) else: messagebox.showerror("Patient with %s id not found"%id1)
def createTables(): connection = sqlite3.connection("lecture.db") cursor = connection.cursor() cursor.execute(""" CREATE TABLE student( id INTEGER PRIMARY KEY, name VARCHAR(256), average REAL) """) connection.commit() connection.close()
def main(): conn = sqlite3.connection('sqlite3db/feedback.db', detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) mastertalklist = json.load(open('fixtures.json', 'r')) for item in mastertalklist: query = """INSERT INTO talk(start_time,end_time,title,speaker,room,type,speaker_link,speaker_image) values(?, ?, ?, ?, ?, ?, ?, ?)""" querydata = (item['start_time'], item['end_time'], item['title'], item['speaker'], item['room'], item['type'], item['speaker_link'], item['speaker_image']) conn.excute(query, querydata) conn.commit() conn.close()
def authenticate(ID, PW): connection = sqlite3.connection("session.db") p = ("select * from stuff where ID = %s", ID) cursor = connection.execute(p) if p == null: return 2 q = ("select * from stuff where where ID = %s and PW = %s", ID, PW) cursor = connection.execute(q) if q == null: return 1 return 0
def validation2(): global username2 = username_verify.get() password2 = password_verify.get() entry.delete(0, END) entry1.delete(0, END) conn=sqlite3.connection("Health_Monitoring.db") cur=conn.cursor() query=SELECT * FROM login where username=username2 and password=password2 cur.execute(query) if(query): patient_homepage() else: message.showerror("Invalid username and password")
def validation1(): username1 = username_verify.get() password1 = password_verify.get() entry.delete(0, END) entry1.delete(0, END) conn=sqlite3.connection("Health_Monitoring.db") cur=conn.cursor() query='SELECT * FROM login where username=username1 and password=password1' cur.execute(query) if(query): doctor_homepage() else: message.showerror("Invalid username and password")
def printMessage(msgDB): try: conn = sqlite3.connection(msgDB) c = conn.cursor() c.execute( 'select datetime(date,\'unixepoch\'), address, text from message where address>0;' ) for row in c: date = str(row[0]) addr = str(row[1]) text = row[2] print('\n[+] Date: ' + date + ', Addr: ' + addr + ' Message: ' + text) except Exception: pass
def db_bioguide_lookup(lastname, year, position, state=None): import sqlite3 conn = sqlite3.connection('../api/capitolwords') cursor = conn.cursor() congresses = {'2010': '111', '2009': '111', '2008': '110', '2007': '110', '2006': '109', '2005': '109', '2004': '108', '2003': '108', '2002': '107', '2001': '107', '2000': '106', '1999': '106', } query = """SELECT bioguide_id AS bioguide, party AS party, state AS state, first AS firstname, last AS lastname FROM bioguide_legislator WHERE last = ? AND year = ? AND position = ?""" args = [lastname.upper(), congresses[year], position.title(),] if state: query += " AND state = ?" args.append(state) cursor.execute(query, args) return list(cursor.fetchall())
def create_connection(self): self.conn = sqlite3.connection('myquotes.db') self.curr = self.conn.cursor()
def __init__(self): self.connection = sqlite3.connection(users.db) self.cursor = self.connection.cursor()
import sqlite3 connection = sqlite3.connection("student.db") curs = connection.cursor() firstname = input("Enter your firstname: ") lastname = input("Eter your lastname: ") #this create a database table sqlCreate = "CREATE TABLE records (id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,firstname TEXT, lastname TEXT)" #THIS QUERRY INSERT DATA TO THE DATABASE TABLE sqlInsert = "INSERT INTO recorrds(id, firstname,lastname)VALUES(NULL,'%s','%s')" % ( firstname, lastname) #this querry will retrieve data from the database sqlRetrieve = "SELECT * FROM records" #Removing a data in database sqlRemove = "DELETE FROM records WHERE id = %d " % idNumber newFirstname = input("Enter your name firstname: ") newLastname = input("Enter your lastname: ") ids = int(input("Enter the user id to update: ")) #updating a data in database sqlUpdate = "UPDATE records SET(firstname, lastname) = ('%s','%s') WHERE id = %d " % ( newFirstname, newLastname, ids) #this create a database table
#!/usr/bin/env python # -*- coding: utf-8 -*- import sqlite3 as lite import sys con = lite.connection('test.db') with con: cur = con.cursor() cur.execute('SELECT SQLITE_VERSION()') data = cur.fetchone() print "SQLite version: %s" % data
#Connect_sqlite.py import sqlite3 from sqlite3 import Error def create_connection(db_file): """ create a database connection to the SQLite database specified by the db_file :param db_file: database file :return: Connection object or None """ try: connection = sqlite3.connection(db_file) return connection except Error as e: print e return None
import sqlite3 connection = sqlite3.connection('coachdata.sqlite') cursor = connection.cursor() import glob import athletemodel data_files = glob.glob("../data/*.txt") athletes = athletemodel.put_to_store(data_files) for each_ath in athletes: name = athletes[each_ath].name dob = athletes[each_ath].dob cursor.execute("INSERT INTO athletes (name, dob) VALUES (? ,? )", (name,dob)) connection.commit() connection.close()
import sqlite3 c = sqlite3.connection("test.db") q = "select * form teachers" cursor = c.execute(q) result = [x for x in cursor] # or we could do: #result=[] #for line in cursor: # result.append(line) # now result is a list where each line is a line returned by the query
import keys import pylast import sqlite3 conn = sqlite3.connection("lastfmdb.db") cur = conn.cursor() query = "SELECT * FROM tags" tags = cur.fetchall() query = "SELECT * FROM artist_tags" artist_tags = cur.fetchall()
import sqlite3 conn = sqlite3.connection('data.db') curs = conn.cursor() curs.execute("""create table data_db( title text, sno number, particulars text, details text, charges text )""") conn.commit() conn.close()
def connect_db(): return sqlite3.connection(app.config['DATABASE_PATH'])