pymensago/userinfo.py
def save_user_list_field(db: sqlite3.Connection, fieldname: str, fieldvalues: list) -> RetVal:
	'''Saves a list object into the database as a list'''

	if not fieldname:
		return ErrBadValue
	
	if fieldvalues and not isinstance(fieldvalues[0], str):
		return RetVal(ErrBadType, 'list must contain strings')

	cursor = db.cursor()
	cursor.execute("""DELETE FROM userinfo WHERE fieldname LIKE ?""", (fieldname + '.%',))

	if not fieldvalues:
		db.commit()
		return RetVal()

	for i in range(len(fieldvalues)):
		cursor.execute('INSERT INTO userinfo (fieldname, fieldvalue) VALUES(?,?)',
				(f"{fieldname}.{str(i)}", fieldvalues[i]))
	
	db.commit()
		
	return RetVal()
Saves a list object into the database as a list
Saves a list object into the database as a list
Saves a list object into the database as a list
def save_user_list_field(db: sqlite3.Connection, fieldname: str, fieldvalues: list) -> RetVal:
	if not fieldname:
		return ErrBadValue
	if fieldvalues and not isinstance(fieldvalues[0], str):
		return RetVal(ErrBadType, 'list must contain strings')
	cursor = db.cursor()
	cursor.execute("""DELETE FROM userinfo WHERE fieldname LIKE ?""", (fieldname + '.%',))
	if not fieldvalues:
		db.commit()
		return RetVal()
	for i in range(len(fieldvalues)):
		cursor.execute('INSERT INTO userinfo (fieldname, fieldvalue) VALUES(?,?)',
				(f"{fieldname}.{str(i)}", fieldvalues[i]))
	db.commit()
	return RetVal()
def save_user_list_field ( db : sqlite3 . Connection , fieldname : str , fieldvalues : list ) -> RetVal : if not fieldname : return ErrBadValue if fieldvalues and not isinstance ( fieldvalues [ 0 ] , str ) : return RetVal ( ErrBadType , 'list must contain strings' ) cursor = db . cursor ( ) cursor . execute ( """DELETE FROM userinfo WHERE fieldname LIKE ?""" , ( fieldname + '.%' , ) ) if not fieldvalues : db . commit ( ) return RetVal ( ) for i in range ( len ( fieldvalues ) ) : cursor . execute ( 'INSERT INTO userinfo (fieldname, fieldvalue) VALUES(?,?)' , ( f"{fieldname}.{str(i)}" , fieldvalues [ i ] ) ) db . commit ( ) return RetVal ( )
Saves a list object into the database as a list
Saves a list object into the database as a list
'''Saves a list object into the database as a list'''
db
sqlite3.Connection
fieldname
str
fieldvalues
list