mysql/funcs/crud_mysql.py
def update(id, name=False, price=False, stock=False):
    """Update an item selected by id."""
    connection = connect()
    cursor = connection.cursor()
    if name:
        new_name = input('Enter new product name: ')
        cursor.execute(f"UPDATE produtos SET nome='{new_name}' WHERE id = {int(id)}")
        check_operation(connection, cursor)
        print('Product name was updated.')
    if price:
        new_price = input('Enter new product price: ')
        cursor.execute(f"UPDATE produtos SET preco={new_price} WHERE id = {int(id)}")
        check_operation(connection, cursor)
        print('Product price was updated.')
    if stock:
        new_stock = input('Enter new product stock: ')
        cursor.execute(f"UPDATE produtos SET estoque={new_stock} WHERE id = {int(id)}")
        check_operation(connection, cursor)
        print('Product stock was updated.')
    else:
        print('Any item was updated.')
    disconnect(connection)
Update an item selected by id.
Update an item selected by id.
Update an item selected by id .
def update(id, name=False, price=False, stock=False):
    connection = connect()
    cursor = connection.cursor()
    if name:
        new_name = input('Enter new product name: ')
        cursor.execute(f"UPDATE produtos SET nome='{new_name}' WHERE id = {int(id)}")
        check_operation(connection, cursor)
        print('Product name was updated.')
    if price:
        new_price = input('Enter new product price: ')
        cursor.execute(f"UPDATE produtos SET preco={new_price} WHERE id = {int(id)}")
        check_operation(connection, cursor)
        print('Product price was updated.')
    if stock:
        new_stock = input('Enter new product stock: ')
        cursor.execute(f"UPDATE produtos SET estoque={new_stock} WHERE id = {int(id)}")
        check_operation(connection, cursor)
        print('Product stock was updated.')
    else:
        print('Any item was updated.')
    disconnect(connection)
def update ( id , name = False , price = False , stock = False ) : connection = connect ( ) cursor = connection . cursor ( ) if name : new_name = input ( 'Enter new product name: ' ) cursor . execute ( f"UPDATE produtos SET nome='{new_name}' WHERE id = {int(id)}" ) check_operation ( connection , cursor ) print ( 'Product name was updated.' ) if price : new_price = input ( 'Enter new product price: ' ) cursor . execute ( f"UPDATE produtos SET preco={new_price} WHERE id = {int(id)}" ) check_operation ( connection , cursor ) print ( 'Product price was updated.' ) if stock : new_stock = input ( 'Enter new product stock: ' ) cursor . execute ( f"UPDATE produtos SET estoque={new_stock} WHERE id = {int(id)}" ) check_operation ( connection , cursor ) print ( 'Product stock was updated.' ) else : print ( 'Any item was updated.' ) disconnect ( connection )
Update an item selected by id.
Update an item selected by id .
"""Update an item selected by id."""
id
name
price
stock