### Install pysqream-blue Source: https://github.com/sqream/pysqream-blue/blob/master/README.rst Install the connector package using pip3. ```console $ pip3 install pysqream-blue ``` -------------------------------- ### Validate Installation Source: https://github.com/sqream/pysqream-blue/blob/master/README.rst Create a test script to verify connectivity and query execution against a SQream DB instance. ```python #!/usr/bin/env python import pysqream_blue """ Connection parameters include: * IP/Hostname * Port * database name * username * password * Connect through load balancer, or direct to worker (Default: false - direct to worker) * use SSL connection (default: false) * Optional service queue (default: 'sqream') """ # Create a connection object con = pysqream_blue.connect(host='127.0.0.1', port='80', database='master', username='sqream', password='sqream') # Create a new cursor cur = con.cursor() # Prepare and execute a query cur.execute('select 1') result = cur.fetchall() # `fetchall` gets the entire data set print(f"Result: {result}") # This should print the SQream DB version. For example ``Version: v2020.1``. # close statement cur.close() # Finally, close the connection con.close() ``` -------------------------------- ### Verify Python Version Source: https://github.com/sqream/pysqream-blue/blob/master/README.rst Check the installed Python version to ensure it meets the 3.9+ requirement. ```console $ python --version Python 3.9 ``` -------------------------------- ### Configure Logging and Connect Source: https://context7.com/sqream/pysqream-blue/llms.txt Set the log path and enable debug logging before establishing a connection to the SQream server. ```python # Configure logging before connecting pysqream_blue.set_log_path('/var/log/sqream_connector.log') # Connect with logging enabled con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream', use_logs=True, log_level='DEBUG' # Options: INFO, DEBUG, CRITICAL, WARNING, ERROR ) # Perform operations - all activity will be logged cur = con.cursor() cur.execute("SELECT * FROM users") cur.fetchall() cur.close() con.close() ``` -------------------------------- ### connect() - Establish Database Connection Source: https://context7.com/sqream/pysqream-blue/llms.txt Creates a connection to a SQream DB Blue cloud instance. Authenticates using username/password or an access token and returns a Connection object. ```APIDOC ## connect() - Establish Database Connection ### Description Creates a connection to a SQream DB Blue cloud instance. This is the primary entry point for the connector. The function authenticates using either username/password or an access token and returns a Connection object for executing queries. ### Method `connect()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import pysqream_blue # Basic connection with username/password authentication con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream', use_ssl=True # Default is True ) # Connection with access token (IDP authentication) con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', access_token='your-oauth-access-token', use_ssl=True ) # Connection with all parameters con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream', use_ssl=True, tenant_id='tenant', service='sqream', reconnect_attempts=10, # Number of reconnection attempts reconnect_interval=3, # Seconds between reconnection attempts query_timeout=0, # Query timeout in seconds (0 = no timeout) pool_name=None, # Optional connection pool name source_type='EXTERNAL' # Source type identifier ) # Always close connection when done con.close() ``` ### Response #### Success Response (200) - **Connection object**: An object representing the database connection. ``` -------------------------------- ### Configure Logging Source: https://github.com/sqream/pysqream-blue/blob/master/README.rst Enable and configure logging for the connector by specifying a log file path and level. ```python pysqream_blue.set_log_path('PATH LOG FILE') con = pysqream_blue.connect('127.0.0.1', '80', use_logs=True, log_level='INFO') ``` ```python pysqream_blue.set_log_path('/tmp/sqream_dbapi.log') con = pysqream_blue.connect('127.0.0.1', '80', use_logs=True, log_level='INFO') ``` -------------------------------- ### Establish Database Connection with pysqream Blue Source: https://context7.com/sqream/pysqream-blue/llms.txt Connect to a SQream DB Blue cloud instance using username/password or an access token. Ensure to close the connection when done. ```python import pysqream_blue # Basic connection with username/password authentication con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream', use_ssl=True # Default is True ) # Connection with access token (IDP authentication) con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', access_token='your-oauth-access-token', use_ssl=True ) # Connection with all parameters con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream', use_ssl=True, tenant_id='tenant', service='sqream', reconnect_attempts=10, # Number of reconnection attempts reconnect_interval=3, # Seconds between reconnection attempts query_timeout=0, # Query timeout in seconds (0 = no timeout) pool_name=None, # Optional connection pool name source_type='EXTERNAL' # Source type identifier ) # Always close connection when done con.close() ``` -------------------------------- ### Handle Data Types and Arrays Source: https://context7.com/sqream/pysqream-blue/llms.txt Demonstrates automatic type conversion between SQream DB and Python, including support for complex types like arrays. ```python import pysqream_blue from datetime import date, datetime from decimal import Decimal con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) # Create a table with various data types cur = con.cursor() cur.execute(""" CREATE OR REPLACE TABLE data_types_demo ( col_bool BOOL, col_tinyint TINYINT, col_smallint SMALLINT, col_int INT, col_bigint BIGINT, col_real REAL, col_double DOUBLE, col_date DATE, col_datetime DATETIME, col_text TEXT, col_numeric NUMERIC(18, 4) ) """) cur.close() # Insert data cur = con.cursor() cur.execute(""" INSERT INTO data_types_demo VALUES ( true, 127, 32000, 2147483647, 9223372036854775807, 3.14, 3.141592653589793, '2024-01-15', '2024-01-15 14:30:45', 'Hello World', 12345.6789 ) """) cur.close() # Query and inspect types cur = con.cursor() cur.execute("SELECT * FROM data_types_demo") row = cur.fetchone()[0] # Python types returned: # col_bool: int (0 or 1) # col_tinyint: int # col_smallint: int # col_int: int # col_bigint: int # col_real: float # col_double: float # col_date: datetime.date # col_datetime: datetime.datetime # col_text: str # col_numeric: Decimal print(f"Boolean: {row[0]} (type: {type(row[0]).__name__})") print(f"Date: {row[7]} (type: {type(row[7]).__name__})") print(f"Datetime: {row[8]} (type: {type(row[8]).__name__})") cur.close() # Working with arrays cur = con.cursor() cur.execute("CREATE OR REPLACE TABLE array_demo (int_array INT[])") cur.close() cur = con.cursor() cur.execute("INSERT INTO array_demo VALUES (ARRAY[1, 2, 3, 4, 5])") cur.close() cur = con.cursor() cur.execute("SELECT * FROM array_demo") result = cur.fetchall() print(f"Array result: {result}") # [([1, 2, 3, 4, 5],)] cur.close() # Arrays with other types cur = con.cursor() cur.execute("SELECT ARRAY['hello', 'world']") string_array = cur.fetchall() print(f"String array: {string_array}") # [(['hello', 'world'],)] cur.close() cur = con.cursor() cur.execute("SELECT ARRAY['2024-01-01'::DATE, '2024-12-31'::DATE]") date_array = cur.fetchall() print(f"Date array: {date_array}") # [([datetime.date(2024, 1, 1), datetime.date(2024, 12, 31)],)] cur.close() con.close() ``` -------------------------------- ### Fetch All Results with fetchall() Source: https://context7.com/sqream/pysqream-blue/llms.txt Use fetchall() to retrieve all rows from a query result set. Returns an empty list if no results are found. Ensure to close the cursor and connection when done. ```python cur.execute("SELECT id, name, created_date FROM users") rows = cur.fetchall() for row in rows: user_id, name, created_date = row print(f"User {user_id}: {name}, created on {created_date}") # Returns empty list if no results cur.execute("SELECT * FROM users WHERE id = -1") empty_result = cur.fetchall() print(empty_result) # [] cur.close() con.close() ``` -------------------------------- ### Create and Use Query Cursor with pysqream Blue Source: https://context7.com/sqream/pysqream-blue/llms.txt Create a cursor from a connection to execute SQL queries. Cursors can be closed independently, and multiple cursors can be used from a single connection. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) # Create a cursor cur = con.cursor() # Execute a query cur.execute('SELECT 1') result = cur.fetchall() print(f"Result: {result}") # Output: [(1,)] # Close cursor when done cur.close() # Create multiple cursors for parallel operations cur1 = con.cursor() cur2 = con.cursor() cur1.execute("SELECT 'hello'") cur2.execute("SELECT 'world'") result1 = cur1.fetchall() # [('hello',)] result2 = cur2.fetchall() # [('world',)] cur1.close() cur2.close() con.close() ``` -------------------------------- ### Connection.cursor() - Create Query Cursor Source: https://context7.com/sqream/pysqream-blue/llms.txt Creates a new cursor object for executing SQL queries. Each cursor opens its own session while sharing the same gRPC channel with the parent connection. ```APIDOC ## Connection.cursor() - Create Query Cursor ### Description Creates a new cursor object for executing SQL queries. Each cursor opens its own session while sharing the same gRPC channel with the parent connection. Multiple cursors can be created from a single connection for concurrent operations. ### Method `Connection.cursor()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) # Create a cursor cur = con.cursor() # Execute a query cur.execute('SELECT 1') result = cur.fetchall() print(f"Result: {result}") # Output: [(1,)] # Close cursor when done cur.close() # Create multiple cursors for parallel operations cur1 = con.cursor() cur2 = con.cursor() cur1.execute("SELECT 'hello'") cur2.execute("SELECT 'world'") result1 = cur1.fetchall() # [('hello',)] result2 = cur2.fetchall() # [('world',)] cur1.close() cur2.close() con.close() ``` ### Response #### Success Response (200) - **Cursor object**: An object for executing SQL queries. ``` -------------------------------- ### Configure Logging with set_log_path() Source: https://context7.com/sqream/pysqream-blue/llms.txt Use set_log_path() to specify the file path for connector activity logs. This function must be called before establishing a connection with `use_logs=True`. It supports various log levels including INFO, DEBUG, CRITICAL, WARNING, and ERROR. ```python import pysqream_blue ``` -------------------------------- ### Handle unsupported features Source: https://context7.com/sqream/pysqream-blue/llms.txt Catch NotSupportedError when attempting to use features not currently implemented, such as parameterized queries. ```python cur = con.cursor() try: cur.execute("SELECT * FROM users WHERE id = ?", (1,)) except NotSupportedError as e: print(f"Feature not supported: {e}") # "Parametered queries currently not supported" con.close() ``` -------------------------------- ### Handle connection errors Source: https://context7.com/sqream/pysqream-blue/llms.txt Use a try-except block to catch ProgrammingError when establishing a connection to the database. ```python try: con = pysqream_blue.connect( host='invalid-host', port='443', database='master', username='sqream', password='sqream' ) except ProgrammingError as e: print(f"Connection failed: {e}") ``` -------------------------------- ### Cursor.fetchone() Source: https://context7.com/sqream/pysqream-blue/llms.txt Fetches the next row from the result set. ```APIDOC ## Cursor.fetchone() ### Description Fetches the next row from the result set, returning a single-item list containing the row tuple, or None if no more rows are available. ### Method Python Method ### Response - **row** (list/None) - A list containing the row tuple or None. ``` -------------------------------- ### Upgrade PIP Source: https://github.com/sqream/pysqream-blue/blob/master/README.rst Verify and upgrade the pip package manager to the latest version. ```console $ python -m pip3 install --upgrade pip Collecting pip Downloading https://files.pythonhosted.org/packages/00/b6/9cfa56b4081ad13874b0c6f96af8ce16cfbc1cb06bedf8e9164ce5551ec1/pip-19.3.1-py2.py3-none-any.whl (1.4MB) |████████████████████████████████| 1.4MB 1.6MB/s Installing collected packages: pip Found existing installation: pip 19.1.1 Uninstalling pip-19.1.1: Successfully uninstalled pip 19.1.1 Successfully installed pip-19.3.1 ``` -------------------------------- ### Cursor.fetchall() Source: https://context7.com/sqream/pysqream-blue/llms.txt Fetches all rows from the result set of a query. ```APIDOC ## Cursor.fetchall() ### Description Fetches all rows from the result set of a query. Returns an empty list if no results are found. ### Method Python Method ### Parameters None ### Response - **rows** (list) - A list of tuples containing the result set. ``` -------------------------------- ### Import Error Classes Source: https://context7.com/sqream/pysqream-blue/llms.txt Import standard DB-API 2.0 exception classes for robust error handling. ```python import pysqream_blue from pysqream_blue.utils import ( Error, Warning, InterfaceError, DatabaseError, DataError, OperationalError, IntegrityError, InternalError, ProgrammingError, NotSupportedError ) ``` -------------------------------- ### Cursor.fetchall() - Fetch All Results Source: https://context7.com/sqream/pysqream-blue/llms.txt Retrieves all remaining rows from the result set as a list of tuples. Fetches data in chunks internally and parses all rows before returning. ```APIDOC ## Cursor.fetchall() - Fetch All Results ### Description Retrieves all remaining rows from the result set as a list of tuples. This method fetches data in chunks internally and parses all rows before returning. Best used when the result set is reasonably sized. ### Method `Cursor.fetchall()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() # Assuming a query has been executed and results are available # cur.execute("SELECT * FROM some_table") # results = cur.fetchall() ``` ### Response #### Success Response (200) - **list of tuples**: A list where each tuple represents a row from the result set. ``` -------------------------------- ### set_log_path() Source: https://context7.com/sqream/pysqream-blue/llms.txt Configures the logging path for the connector. ```APIDOC ## set_log_path() ### Description Sets the file path for logging connector activity. Must be called before connecting with use_logs=True. ### Parameters - **path** (string) - Required - The file path for logs. ``` -------------------------------- ### Cursor.execute() - Execute SQL Statement Source: https://context7.com/sqream/pysqream-blue/llms.txt Executes a SQL query or statement. Returns the cursor object itself, allowing method chaining. Supports all SQream SQL statements. ```APIDOC ## Cursor.execute() - Execute SQL Statement ### Description Executes a SQL query or statement. Returns the cursor object itself, allowing method chaining. Supports all SQream SQL statements including SELECT, INSERT, CREATE, DROP, and DDL operations. Note: Parameterized queries are not currently supported. ### Method `Cursor.execute(sql_statement)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() # Execute SELECT query cur.execute("SELECT * FROM my_table WHERE id > 100") # Execute DDL statements cur.execute("CREATE OR REPLACE TABLE test (id INT, name VARCHAR(100))") cur.close() # Execute INSERT statements cur = con.cursor() cur.execute("INSERT INTO test VALUES (1, 'Alice')") cur.close() cur = con.cursor() cur.execute("INSERT INTO test VALUES (2, 'Bob')") cur.close() # Method chaining - execute returns the cursor cur = con.cursor() result = cur.execute("SELECT * FROM test").fetchall() print(result) # [(1, 'Alice'), (2, 'Bob')] cur.close() # Execute with special characters using dollar-quoted strings cur = con.cursor() cur.execute("INSERT INTO test VALUES (3, $$O'Brien$$)") cur.close() con.close() ``` ### Response #### Success Response (200) - **Cursor object**: The cursor object itself, allowing for method chaining. ``` -------------------------------- ### Cursor.fetchmany() Source: https://context7.com/sqream/pysqream-blue/llms.txt Fetches a specified number of rows from the result set. ```APIDOC ## Cursor.fetchmany() ### Description Fetches a specified number of rows from the result set. Returns an empty list when no more rows are available. ### Method Python Method ### Parameters - **size** (int) - Required - The number of rows to fetch. Pass -1 to fetch all remaining rows. ``` -------------------------------- ### Fetch All Results with Cursor.fetchall() in pysqream Blue Source: https://context7.com/sqream/pysqream-blue/llms.txt Retrieve all remaining rows from a result set as a list of tuples. This method is suitable for reasonably sized result sets. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() ``` -------------------------------- ### Execute SQL Statements with pysqream Blue Cursor Source: https://context7.com/sqream/pysqream-blue/llms.txt Execute various SQL statements including SELECT, DDL, and INSERT using the cursor's execute method. Method chaining is supported, and dollar-quoted strings can handle special characters. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() # Execute SELECT query cur.execute("SELECT * FROM my_table WHERE id > 100") # Execute DDL statements cur.execute("CREATE OR REPLACE TABLE test (id INT, name VARCHAR(100))") cur.close() # Execute INSERT statements cur = con.cursor() cur.execute("INSERT INTO test VALUES (1, 'Alice')") cur.close() cur = con.cursor() cur.execute("INSERT INTO test VALUES (2, 'Bob')") cur.close() # Method chaining - execute returns the cursor cur = con.cursor() result = cur.execute("SELECT * FROM test").fetchall() print(result) # [(1, 'Alice'), (2, 'Bob')] cur.close() # Execute with special characters using dollar-quoted strings cur = con.cursor() cur.execute("INSERT INTO test VALUES (3, $$O'Brien$$)") cur.close() con.close() ``` -------------------------------- ### Fetch Single Row with fetchone() Source: https://context7.com/sqream/pysqream-blue/llms.txt Use fetchone() to retrieve rows one at a time from a result set. It returns a single-item list containing the row tuple, or None if no more rows are available. This is efficient for processing large datasets. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() cur.execute("SELECT id, name FROM users") # Fetch rows one at a time while True: row = cur.fetchone() if row is None: break # row is a list with one tuple, e.g., [(1, 'Alice')] user_id, name = row[0] print(f"Processing user: {user_id} - {name}") cur.close() con.close() ``` -------------------------------- ### Fetch Multiple Rows with fetchmany() Source: https://context7.com/sqream/pysqream-blue/llms.txt Use fetchmany(size) to retrieve a specified number of rows from the result set. Pass -1 to fetch all remaining rows. Returns an empty list when no more rows are available. This method is useful for processing data in batches. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() cur.execute("SELECT id, value FROM large_table") # Fetch in batches of 100 rows batch_size = 100 while True: rows = cur.fetchmany(batch_size) if not rows: break print(f"Processing batch of {len(rows)} rows") for row in rows: # Process each row pass # Combining fetch methods cur = con.cursor() cur.execute("SELECT * FROM test_table") first_row = cur.fetchone() # Get first row next_two = cur.fetchmany(2) # Get next 2 rows remaining = cur.fetchall() # Get all remaining rows cur.close() con.close() ``` -------------------------------- ### Access Result Set Metadata Source: https://context7.com/sqream/pysqream-blue/llms.txt Use the cursor.description attribute to retrieve column metadata such as name, type, and nullability after executing a query. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() cur.execute("SELECT id, name, salary, hire_date FROM employees") # Access column metadata for col in cur.description: name, type_code, display_size, internal_size, precision, scale, null_ok = col print(f"Column: {name}, Type: {type_code}, Nullable: {null_ok}") # Example output: # Column: id, Type: NUMBER, Nullable: False # Column: name, Type: STRING, Nullable: True # Column: salary, Type: NUMBER, Nullable: True # Column: hire_date, Type: DATETIME, Nullable: True cur.close() con.close() ``` -------------------------------- ### Close Connection with connection.close() Source: https://context7.com/sqream/pysqream-blue/llms.txt Call connection.close() to close the database connection and all associated cursors. This terminates the session with the SQream server and releases all resources. Closing the connection automatically closes any open cursors. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() cur.execute("SELECT 1") cur.fetchall() # Close cursor first, then connection cur.close() con.close() # Or just close connection (auto-closes all cursors) con2 = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur2 = con2.cursor() cur2.execute("SELECT 2") con2.close() # Automatically closes cur2 as well ``` -------------------------------- ### Close Cursor with cursor.close() Source: https://context7.com/sqream/pysqream-blue/llms.txt Always call cursor.close() when you are finished with a cursor to release server-side resources and close the gRPC channel. This ensures proper cleanup. It can be used with try-finally blocks for robust resource management. ```python import pysqream_blue con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) # Proper resource management cur = con.cursor() try: cur.execute("SELECT * FROM users") results = cur.fetchall() # Process results finally: cur.close() # Always close the cursor # Using cursor as a one-liner pattern con.cursor().execute("DROP TABLE IF EXISTS temp_table").close() con.close() ``` -------------------------------- ### Connection.close() Source: https://context7.com/sqream/pysqream-blue/llms.txt Closes the database connection. ```APIDOC ## Connection.close() ### Description Closes the database connection and all associated cursors, releasing all resources and the gRPC channel. ### Method Python Method ``` -------------------------------- ### Cursor.close() Source: https://context7.com/sqream/pysqream-blue/llms.txt Closes the cursor and releases resources. ```APIDOC ## Cursor.close() ### Description Closes the cursor and releases associated server-side resources and the gRPC channel. ### Method Python Method ``` -------------------------------- ### Handle query errors Source: https://context7.com/sqream/pysqream-blue/llms.txt Catch OperationalError during query execution to manage issues like missing tables. ```python con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) try: cur = con.cursor() cur.execute("SELECT * FROM nonexistent_table") except OperationalError as e: print(f"Query execution error: {e}") ``` -------------------------------- ### Cancel Running Query with cursor.cancel() Source: https://context7.com/sqream/pysqream-blue/llms.txt Use cursor.cancel() to abort a query that is currently executing. This is useful for implementing query timeouts or stopping long-running operations. The cursor must have an active statement to be canceled. ```python import pysqream_blue import threading import time con = pysqream_blue.connect( host='your-sqream-host.sqream.io', port='443', database='master', username='sqream', password='sqream' ) cur = con.cursor() # Function to run a long query def run_long_query(): try: cur.execute("SELECT * FROM very_large_table") cur.fetchall() except Exception as e: print(f"Query cancelled or failed: {e}") # Start query in a thread query_thread = threading.Thread(target=run_long_query) query_thread.start() # Wait a bit, then cancel time.sleep(5) cancel_response = cur.cancel() print("Query cancellation requested") query_thread.join() cur.close() con.close() ``` -------------------------------- ### Cursor.cancel() Source: https://context7.com/sqream/pysqream-blue/llms.txt Cancels a currently executing query. ```APIDOC ## Cursor.cancel() ### Description Cancels a currently executing query. Useful for aborting long-running queries. ### Method Python Method ``` -------------------------------- ### Handle closed cursor errors Source: https://context7.com/sqream/pysqream-blue/llms.txt Catch ProgrammingError when attempting to execute a query on a cursor that has already been closed. ```python cur = con.cursor() cur.close() try: cur.execute("SELECT 1") except ProgrammingError as e: print(f"Cursor error: {e}") # "Statement has been closed" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.