filmov
tv
Python’s SQLITE3 Delete Table Data(and Tables) and Getting Data
![preview_player](https://i.ytimg.com/vi/h9LQh7yijUs/maxresdefault.jpg)
Показать описание
import sqlite3
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)
with conn:
# SELECT * FROM dbmytable WHERE username = ? AND score = ?'
if '*' in search and len(search)==1 and '*' in cat and len(cat)==1:
elif '*' in search and len(search)==1 and len(cat)==1:
one_cat = ''.join(cat)
elif '?' in search and len(search)==1 and '?' in cat and len(cat)==1:
return items
else:
temp1 = []
for item in cat:
categories =' AND '.join(temp1)
string_execute = f'SELECT * FROM {table} WHERE {categories}'
items = []
return items
def delete_row(db_name=DFLT_path, table=DFLT_table, cat=DFLT_cat, search=DFLT_search):
table = 'db' + str(table)
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:
match2 = ' OR '.join(match1)
string_execute = f'DELETE FROM {table} WHERE {match2}'
return string_execute
def delete_table(db_name=DFLT_path, table=DFLT_table):
table = 'db' + str(table)
with conn:
# DROP TABLE IF EXISTS table_
string_execute = f'DROP TABLE IF EXISTS {table}'
return 'table has been deleted'
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
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)
with conn:
# SELECT * FROM dbmytable WHERE username = ? AND score = ?'
if '*' in search and len(search)==1 and '*' in cat and len(cat)==1:
elif '*' in search and len(search)==1 and len(cat)==1:
one_cat = ''.join(cat)
elif '?' in search and len(search)==1 and '?' in cat and len(cat)==1:
return items
else:
temp1 = []
for item in cat:
categories =' AND '.join(temp1)
string_execute = f'SELECT * FROM {table} WHERE {categories}'
items = []
return items
def delete_row(db_name=DFLT_path, table=DFLT_table, cat=DFLT_cat, search=DFLT_search):
table = 'db' + str(table)
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:
match2 = ' OR '.join(match1)
string_execute = f'DELETE FROM {table} WHERE {match2}'
return string_execute
def delete_table(db_name=DFLT_path, table=DFLT_table):
table = 'db' + str(table)
with conn:
# DROP TABLE IF EXISTS table_
string_execute = f'DROP TABLE IF EXISTS {table}'
return 'table has been deleted'
BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU