8

I'm using ArcGIS Server 10.0. I have a geoprocessing using arcpy search, update and insert cursors. I'd like to know more about the technology behind these cursors.

Does it use any driver or pool to connect to the database (I'm using Oracle 11g)?

Does it open a connexion to the DB once at the creation of the cursor and close it when the cursor is deleted? What about transactions?

Does the cursor open a new connexion and transaction to the DB each time a row is updated or inserted?

4

All ArcPy does is provide hooks in to the normal ArcGIS desktop. Just like desktop once you have a connection it will keep it open until it is explicitly closed by ArcGIS (usually when the associated python windows are closed). As for the drivers it will use the drivers you installed for ArcGIS to connect to your ArcSDE/RDBMS

  • I have a geoprocessing that doesn't open any window. Does it mean that the connexion stays open till the application executes del myCursor? – yo_haha Sep 26 '13 at 15:38
  • 1
    If you are using the windowless processes the connection will stay open until the process is closed. ArcGIS is very aggressive with the different types of data locks it puts on any data used, including open database connections. Even after removing all references to a connection or data set ArcGIS may keep it connected in the background and locked until the application with that lock is closed. It has been a major pain for users for years. Using the del function will delete all references in your python app, but it will not necessarily cause ArcGIS to actually close the database connection. – Lemur Sep 26 '13 at 15:58
  • 1
    The situation you describe seems to have been improved at 10.1 (see Jason's comments to this blog post: sgillies.net/blog/1067/get-with-it) – blah238 Sep 26 '13 at 22:27
  • @blah238 the link was incomplete, so here is the full url to the post mentioned: sgillies.net/2011/02/01/get-with-it.html – Priscilla Dec 3 '16 at 16:25
3

You need to understand the concept of Python cursors.

They are modelled after SQL database cursors in the PEP 249: Python Database API Specification v2.0 to process the results returned by database queries.

The majority of Python database interfaces adhere to this standard: cx_Oracle (Oracle), Psycopg2 (PostgreSQL/PostGIS), MySQLdb (MySQL), sqlite3 (SQLite), etc..

A cursor allows retrieval of one or more rows of the result, until all the matching rows have been processed and it will fetch the entire result set at once, which may cause problems of processing speed (performance) (Is there anything faster than a cursor in ArcGIS to calculate records?).

The databases cursors generally returns list of tuples or list of list while the cursor methods in ArcGIS return a Python enumeration object.

To improve the cursor solution, several wrappers that provide simplified interfaces to SQL databases exist. Some of these might be referred to as object relational mappers, or ORM (creation of Pythonic objects out of database rows) and others may only help generate SQL, or provide simple mapping support (see Higher Level Database Programming)

For ArcPy, solutions are provided by, for example, Sean Gillies (Get with it) and others.

The others geospatial solutions (PyQGIS, grass, osgeo.ogr, Pyshp, Rpy, Fiona, PySAL,etc.) do not use cursors, which makes things easier...

  • 3
    This is tangential and not in any way related/specific to Arcpy cursors, which is what the poster asked about. – Jason Scheirer Sep 26 '13 at 16:38
  • 2
    I am sorry but the question is "What technology is used behind arcpy cursors?" and the technology is the Python cursors, not ArcPy, and if you don't know them, you cannot understand the ArcPy cursors: it is the same thing. – gene Sep 26 '13 at 16:46
  • 8
    The technology behind arcpy cursors is ArcObjects with a Python wrapper. The technology behind arcpy.*Cursor is a Python mapping to ArcObjects' I*Cursor interfaces. An understanding of ArcObjects and ArcGIS' geodatabase model is far more useful than a knowledge of the PEP 249 cursor interface definition. – Jason Scheirer Sep 26 '13 at 16:55
  • 1
    @JasonScheirer that is basically the correct answer to the question so if you were to write an actual answer to the same effect I would vote for it :) – blah238 Sep 26 '13 at 22:23
  • 1
    Already posted the answer to the cross-posted thread at forums.arcgis.com/threads/… – Jason Scheirer Sep 26 '13 at 22:26
0

As commented by @JasonScheirer:

The technology behind arcpy cursors is ArcObjects with a Python wrapper. The technology behind arcpy.Cursor is a Python mapping to ArcObjects' ICursor interfaces. An understanding of ArcObjects and ArcGIS' geodatabase model is far more useful than a knowledge of the PEP 249 cursor interface definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.