Python Connector for BigCommerce

Querying data - Python Connector for BigCommerce

Querying data

Once connected to BigCommerce, you can execute SQL queries to retrieve data from your BigCommerce data.

Execute a query

  1. Create a cursor object using the cursor() connection method.
    my_cursor = my_connection.cursor()
  2. Execute the SQL statement using the execute() cursor method.
    my_cursor.execute("SELECT * FROM employees")
  3. Retrieve the result set using one of the fetch*() cursor methods.
    for row in my_cursor.fetchall(): 
        print(row)

Parameterized queries

You can use parameterized queries to pass variable values to your SQL statements. This allows you to reuse the same query with different data and helps to prevent SQL injection attacks.

Pass parameters as a list or tuple to the execute() method:

query = "SELECT Id, Name FROM Contact WHERE Name = ? AND Email = ?"
params = ["Jordan Sanders", "[email protected]"]
my_cursor.execute(query, params)

results = my_cursor.fetchall()
for row in results:
    print(row)

Each placeholder ? in the query is replaced with a corresponding value from the parameter list.

© 2022-2026 Devart. All Rights Reserved. Request Support Python Connectors Forum Provide Feedback