I use python every day with a heavy emphasis on database work.
Using pyodbc my standard start is something like
connection_hostname = pyodbc.connect('connection_string')
cursor_hostname = connection_hostname.cursor()
command_hostname = 'select * from everything_forever;'
cursor_hostname.execute('command_hostname')
and if i need want to reuse the cursor for another query instead of creating a new cursor, I can store the result set from the first query like so:
results_from_query = cursor_hostname.fetchall()
And move on after that.
This approach has worked well for me so far.
Recently, I changed jobs, and some of my new coworkers who typically use GUIs to work with their DB's started panicking when I demonstrated the above technique. What set them off was the cursor keyword. I understand cursors are a big no-no with DBs because they indicate logic not founded in set theory, tend to push the host into low/zero levels of parallelization, and RBAR type operations, but I don't believe the ODBC cursor I'm declaring above is the same as a cursor we think of when we have our SQL Server engineering and administration hats on.
Can someone explain the difference between these ODBC cursors and SQL Server type cursors (assuming I'm correct that they are different)?
If I am incorrect, please enlighten me and tell me how i can more efficiently interface with my DBs.
Why cant you just execute directly from a connection like
connection_hostname.execute(command_hostname)
I feel like having ODBC cursor structures as they are has something to do with allowing multiple cursors through the same connection to reduce connection cost and such. Way off base?