Python Driver: Connection

Represents an active connection to a Polypheny database. Use this object to manage transactions and execute commands.

The Connection class is a fundamental part of the Polypheny Python Driver, enabling users to establish connections to the Polypheny database and perform various database operations. This section provides a detailed reference for the Connection class, including its constructor, methods, and usage examples.

cursor() → Cursor

Creates and returns a new cursor object, which can be used to execute database commands.

Example:

cur = connection.cursor()
cur.execute("SELECT * FROM users")
print(cur.fetchall())

commit()

Commits the current transaction. Any changes made since the last commit are saved to the database.

Example:

connection.commit()

Note: Performing a DDL statement, such as creating or altering a table, results in an automatic commit.

rollback()

Rolls back the current transaction. This undoes any changes made since the last commit. Note that DDL (Data Definition Language) statements like CREATE TABLE automatically commit and cannot be rolled back.

Example:

connection.rollback()  # Undo changes since the last commit

close()

Closes the connection to the database. After closing, the connection object cannot be used to execute commands.

Example:

connection.close()
© Polypheny GmbH. All Rights Reserved.