Hi all,
I work with an arcSDE database (SQL server Enterprise geodatabase) and I want to retrive using python code the modification date of each of its elements (tables, features classes, rasters, ...)
Thanks
Hi Said,
When you say modified date, do you mean table structure or last updated/added row?
I Mean last feauture class modification or the date of creation
Thanks for your quick answer
Hi Said,
This is something that can be done by sending SQL queries to your SDE repository tables to get the created UNIX time from the sde_table_registry and convert that to a more standard time. I have attached a script I have used to perform this in the past and write it out to a logfile.
However, this should be enough to get you started on how to access and convert the registration time in your Enterprise Geodatabase.
import arcpy, os, datetime, time workPath = r"Database Connections\Connection to cwells.sde" arcpy.CreateDatabaseView_management(workPath, viewName, "select database_name, owner, table_name, registration_date from sde.sde_table_registry") for row in arcpy.SearchCursor(os.path.join(workPath, viewName)): tableName = row.getValue("DATABASE_NAME") + "." + row.getValue("OWNER") + "." + row.getValue("TABLE_NAME") cDate = row.getValue("REGISTRATION_DATE") dTime = time.strftime('%d-%b-%Y %H:%M:%S', time.localtime(cDate))
Thanks
Is there a possibility to have just one date or the date creation or a last modification of a feature class instead of looping in all rows
I'm not sure of your exact question, but are you asking if its possible to return a date for a single feature class only?
Some time you want to know the date when a feature classe was added to a dataset or when was its last modification. it is about those kind of information
Here is a sample of a single feature class:
import arcpy, os, datetime, time gdb = r"Database Connections\Connection to cwells.sde" conn = arcpy.ArcSDESQLExecute(gdb) owner = 'sde' table = 'alex' sql = """SELECT create_date,modify_date FROM sys.tables where UPPER(SCHEMA_NAME(schema_id)) = '{0}' AND UPPER(OBJECT_NAME(object_id)) = '{1}'""" dates = conn.execute(sql.format(owner.upper(), table.upper())) print (owner + '.' + table).upper() print "Create Date: {0}".format(dates[0][0]) print "Modify Date: {0}".format(dates[0][1]) OUTPUT SDE.ALEX Create Date: 8/3/2015 10:55:11 AM Modify Date: 8/3/2015 11:00:51 AM
Sorry but how can I try it with a single feature class
Thanks
You can change the "owner" and "table" variables to be your feature class, table or raster.
So if the feature class you want to get information for appears as "gis.abc.polygons" the variable would be:
owner = 'abc'
table = 'polygons'