Inserindo valores (INSERT INTO), DELETE sem WHERE e zerando a sqlite_sequence
This commit is contained in:
@@ -9,6 +9,16 @@ TABLE_NAME = 'customers'
|
||||
connection = sqlite3.connect(DB_FILE)
|
||||
cursor = connection.cursor()
|
||||
|
||||
# CUIDADO: fazendo delete sem where
|
||||
cursor.execute(
|
||||
f'DELETE FROM {TABLE_NAME}'
|
||||
)
|
||||
cursor.execute(
|
||||
f'DELETE FROM sqlite_sequence WHERE name="{TABLE_NAME}"'
|
||||
)
|
||||
connection.commit()
|
||||
|
||||
# Cria a tabela
|
||||
cursor.execute(
|
||||
f'CREATE TABLE IF NOT EXISTS {TABLE_NAME}'
|
||||
'('
|
||||
@@ -19,5 +29,15 @@ cursor.execute(
|
||||
)
|
||||
connection.commit()
|
||||
|
||||
# Registrar valores nas colunas da tabela
|
||||
# CUIDADO: sql injection
|
||||
cursor.execute(
|
||||
f'INSERT INTO {TABLE_NAME} '
|
||||
'(id, name, weight) '
|
||||
'VALUES '
|
||||
'(NULL, "Helena", 4), (NULL, "Eduardo", 10)'
|
||||
)
|
||||
connection.commit()
|
||||
|
||||
cursor.close()
|
||||
connection.close()
|
||||
|
||||
Reference in New Issue
Block a user