예제 #1
0
def create_blacklist_tokens():
    """ Function To create blacklist_tokens table"""

    cur = conn.cursor()
    cur.execute("DROP TABLE IF EXISTS blacklist_tokens")
    cur.execute(
        "CREATE TABLE blacklist_tokens(id serial PRIMARY KEY, token varchar,\
        blacklisted_on date);")
    conn.commit()
    print("Table blacklist_tokens Successfullyn Created")
예제 #2
0
def create_requests():
    """ Function To create requests table"""

    cur = conn.cursor()
    cur.execute("DROP TABLE IF EXISTS requests")
    cur.execute(
        "CREATE TABLE requests(id serial PRIMARY KEY, user_id integer, \
    category varchar, location varchar, req_date date, description varchar, \
    status varchar, isresolved boolean);")
    print("Table requests Successfullyn Created")
    conn.commit()
예제 #3
0
 def create_user(self):
     # Wybierz wszystkie parametry umieszone w  kolumnie "name" z tabeli game.
     _cursor.execute("SELECT name FROM game")
     result = _cursor.fetchall()
     for x in result:
         if self.name == x[0]:
             print("Login istnieje, wybierze inny")
             break
     else:
         # Dodaje do tabeli 'game', wiersz który odnosi się do kolumn "name, password, register_date" - czyli Tworzenie nowego gracza
         _cursor.execute("INSERT INTO game (name, password, register_date) VALUES ('"+self.name+"','"+self.password+"','"+self.date+"')")
         conn.commit() # Importowanie wyżej podanych danych do bazy danych
         print(f'Użytkownik {self.name} stworzony')
예제 #4
0
def create_users():
    """ Function To create users table"""

    cur = conn.cursor()
    cur.execute("DROP TABLE IF EXISTS users")
    cur.execute("CREATE TABLE users(id serial PRIMARY KEY, username varchar, \
        email varchar,role varchar, password varchar);")
    #create ADmin user
    password = sha256_crypt.encrypt("pass123")
    cur.execute("INSERT INTO users( username, email, role, password) VALUES (%s, %s, %s, %s)",\
    ( "dess","*****@*****.**", "Admin", password))
    cur.execute("SELECT * FROM users")
    items = cur.fetchall()
    print(items)
    print("Table Users Successfullyn Created")
    conn.commit()
예제 #5
0
 def save(self):
     conn.commit()
예제 #6
0
 def create_table(self):
     # Tworzy tabelę "game" w bazie danych "gra" która jest wyciągnięta z pliku connect.py
     _cursor.execute("CREATE TABLE IF NOT EXISTS game (id SERIAL PRIMARY KEY, name TEXT, password TEXT, register_date TEXT)")
     conn.commit()
#   We only want certain indices in a certain order from our input data
def indexList(indices, list):
    return [list[i] for i in indices]


chunksize = 10**5
for chunk in pd.read_csv(fileLoc, chunksize=chunksize, skiprows=[0, 1]):
    data = [
        indexList((1, 2, 3, 4, 7, 8, 10, 13, 14, 16), row)
        for row in (chunk.values.tolist())
    ]
    print("Chunk formatted")

    values = b','.join(
        cur.mogrify("(1, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", row)
        for row in data)

    command = b"""INSERT INTO taxi (city_id, pickup_time, dropoff_time, passenger_count, 
                              trip_distance, pickup_location, dropoff_location, fare, 
                              tip, tolls, total) VALUES """ + values

    print("Executing insert")
    cur.execute(command)
    print("Insert finished")

conn.commit()
print("Taxi data committed successfully")

cur.close()
conn.close()
예제 #8
0
#!/usr/bin/env python
# coding=utf-8
from connect import cursor
from connect import conn
print "请选择删除信息的类别"
print "1-按ID删除"
print "2-按NAME删除"
c = input("请输入你的选择:")
class delete(object):
    def __init__(self,id,name):
        self.id = id
        self.name = name
    def set_delete(self,id,name):
        if c==1:
            id = raw_input('ID:')
            cursor.execute('DELETE FROM little WHERE id = %s',id)
        if c==2:
            name = raw_input('NAME:')
            cursor.execute('DELETE FROM little WHERE name = %s',name)
conn.commit()