Python’s SQLITE3 Delete Table Data(and Tables) and Getting Data

Опубликовано: 25 Март 2021
на канале: ZeroLife
142
4

import sqlite3

DFLT_path = 'C:/Desktop/mydatabase.db'
DFLT_table = 'mytable'
DFLT_data = {'name': "bob",'age':20,'address':'3 something st.'}
DFLT_cat = ["username","score"]
DFLT_search = ["Reza",1]

def db_get(db_name=DFLT_path, table=DFLT_table, cat=DFLT_cat, search=DFLT_search):
table = 'db' + str(table)
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
conn.row_factory = sqlite3.Row

with conn:
SELECT * FROM dbmytable WHERE username = ? AND score = ?'
if '*' in search and len(search)==1 and '*' in cat and len(cat)==1:
cursor.execute(f'SELECT * FROM {table}')
elif '*' in search and len(search)==1 and len(cat)==1:
one_cat = ''.join(cat)
cursor.execute(f'SELECT * FROM {table} WHERE {one_cat} IS NOT NULL')
elif '?' in search and len(search)==1 and '?' in cat and len(cat)==1:
cursor.execute(f'SELECT * FROM {table}')
items = cursor.fetchone().keys()
return items
else:
temp1 = []
for item in cat:
temp1.append(f'{item} = ?')
categories =' AND '.join(temp1)
string_execute = f'SELECT * FROM {table} WHERE {categories}'
cursor.execute(string_execute,search)

items = []
for item in cursor.fetchall()
items.append(item)

return items

def delete_row(db_name=DFLT_path, table=DFLT_table, cat=DFLT_cat, search=DFLT_search):

table = 'db' + str(table)
conn = sqlite3.connect(db_name)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()

with conn:
DELETE FROM dbmytable WHERE username = reza OR score = 1
[(username,reza),(score,1)]
tup1 = zip(cat,search)

match1 = []
for cat1,search1 in tup1:
match1.append(cat1+" = "+search1)
match2 = ' OR '.join(match1)

string_execute = f'DELETE FROM {table} WHERE {match2}'

cursor.execute(string_execute)

return string_execute

def delete_table(db_name=DFLT_path, table=DFLT_table):

table = 'db' + str(table)
conn = sqlite3.connect(db_name)
conn.row_factory = sqlite3.Row
cursor = conn.cursor()

with conn:
DROP TABLE IF EXISTS table_
string_execute = f'DROP TABLE IF EXISTS {table}'
cursor.execute(string_execute)
return 'table has been deleted'

PAT:   / rezatahirkheli  
PP: https://www.paypal.com/paypalme/rezat...
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
GFM: https://gofund.me/7d6500bd


Смотрите видео Python’s SQLITE3 Delete Table Data(and Tables) and Getting Data онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь ZeroLife 25 Март 2021, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 142 раз и оно понравилось 4 людям.