I
I
Ilya Korol2018-11-27 21:02:46
Python
Ilya Korol, 2018-11-27 21:02:46

Why are the actions of the program with the database not saved?

There is a program

import psycopg2

connection = psycopg2.connect(host="localhost", user="postgres", password="password")
cursor = connection.cursor()

if True:
    cursor.execute("""CREATE TABLE products (id serial PRIMARY KEY,name varchar (40) NOT NULL, description varchar (255) NOT NULL, attachments varchar (255) NOT NULL, selled serial, author_id serial NOT NULL, customer serial, checher serial NOT NULL);""")

commands = [
    "INSERT INTO products (name, description, attachments, selled, author_id, customer,  checher) VALUES ('Its Product', 'Its description', 'Its attachments', 0, 1, 0, 0)",
    "SELECT * FROM products",
    ]
for i in range(3):
    for query in range(len(commands)):
        cursor.execute(commands[query])
        try:
            data = cursor.fetchall()
            print(i+1)
            for _ in data:
                print("   ",_)
        except:
            continue

Why are all actions with the table that took place here canceled after this code is executed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2018-11-27
@welcome32

https://www.python.org/dev/peps/pep-0249/#commit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question