I use python every day with great attention to working with the database.
Using pyodbc, my standard startup 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 to reuse the cursor for another query instead of creating a new cursor, I can save the result set from the first query as follows:
results_from_query = cursor_hostname.fetchall()
And move on.
This approach has worked for me so far.
I recently changed jobs, and some of my new employees, who usually use graphical interfaces to work with their database, began to panic when I demonstrated the above technique. What was set was the cursor keyword. I understand that cursors are big no-no with a DB because they point to set-not logic that aims to direct the host to low / zero parallelization levels and operations like RBAR, but I donβt believe that Iβm an ODBC cursor The m declaring above matches the cursor we think of when we have our SQL Server engineering and administrative hats.
Can someone explain the difference between these ODBC cursors and SQL Server type cursors (assuming I'm right that they are different)?
If I'm wrong, please enlighten me and tell me how I can interact more effectively with my databases.
Why can't you just execute directly from the connection, for example
connection_hostname.execute(command_hostname)
It seems to me that ODBC cursor structures, since they have something to do with allowing multiple cursors through the same connection to reduce connection costs and the like. Indent from the base?