Updating a Python SQLITE3 Database

preview_player
Показать описание
import sqlite3, json, base64

DFLT_data = {'username':'Reza','something':'nothing'}

def convertToBinaryThenBase64(filename):
# Convert digital data to binary format then base64 formate
with open(filename, 'rb') as fout:
base64_data = base64.b64encode(blobData)
return base64_data

data=DFLT_data, cat=['*'], search=['*']):
table = 'db' + str(table)

data_val = []
for item in data:
elif isinstance(data[item], (list,dict,set)):
else:

temp = []
for item in data:
columns = ' ,'.join(temp)
#columns = ', '.join([f'{item} = ?' for item in data])

if cat == ['*'] and search ==['*']:
conditions = ''
#UPDATE dbmytable SET username = ?, something = ?
elif len(cat) == 1 and len(search) greaterThan 1:

temp = []
for _ in range(len(search)):
q_marks = ','.join(temp)
#q_marks = ','.join(['?' for _ in range(len(search))])
conditions = 'WHERE ' + f'{cat[0]} IN ({q_marks})'

#UPDATE dbmytable SET username = ?, something = ? WHERE username in (?,?,?..)
elif len(cat) greaterThan= 1 and len(cat) == len(search):
temp = []
for ct in cat:
condition2 = ' OR '.join(temp)
conditions = 'WHERE ' + condition2
#conditions = 'WHERE ' + ' OR '.join([f'{ct} = ?' for ct in cat])
#UPDATE dbmytable SET username = ?, something = ? WHERE username = ? OR something = ?
else:
print('something went wrong')

string_execute = f'UPDATE {table} SET {columns} {conditions}'

with conn:

return string_execute

BTC: 3EUQBWZKX9Vcwdffd3cUGATQopxrAQQxJ9
LTC: MBXE6hJgxxFYSD8SjmR7sHCHGTqFXmNGoU
Рекомендации по теме
Комментарии
Автор

I did try it and it works like a charm. Thank you for sharing this function. 👍👍👍

meocon