I am trying to use arcpy to identify the name of the archive class for a number of feature classes, but cannot find a function that will output the name of the archive class, only whether the feature class has archiving enabled.
import arcpy
gdbConn = r"Database Connections\ScriptTest.sde"
arcpy.env.workspace = gdbConn
queryResult = ["List of all my feature classes"]
for row in queryResult:
gisLayer = row
desc = arcpy.Describe(gisLayer)
if desc.isArchived:
print "{} has Archiving Enabled".format(gisLayer)
gisLayer_Archive = "" # Identify Archive Class here
arcpy.FeatureClassToFeatureClass_conversion(gisLayer_Archive, r'D:\temp\TempOutput.gdb', gisLayer_Archive)
My intention is to take a copy of each archive class and save them in a file geodatabase.
Is there a way to find the name of the archive class for archived feature classes in a geodatabase so that I can copy those archives out?
I could possibly assume that all archive classes have a _H
suffix, however it is possible that some of these have changed over time.
ArcGIS for Desktop/Server 10.3.1 MS SQL Server 2012
1 Answer 1
There is no way to find this out using arcpy
functions, however using arcpy.ArcSDESQLExecute
lets you submit SQL queries, so you can stay within the Python ecosystem.
import arcpy
fc = 'SIGNPOSTS'
sql = '''select table_name from sde.SDE_table_registry where
registration_id = (select history_regid from sde.SDE_archives where archiving_regid =
(select registration_id from sde.SDE_table_registry where table_name = '{0}'))'''.format(fc)
con = arcpy.ArcSDESQLExecute(server='localhost', instance='sde:sqlserver:localhost',database='gdbname')
print con.execute(sql)
>>> SIGNPOSTS_H
-
Thanks for that. Yes this is pretty much the same as what I ended up with (once I figured out which tables to use). I quite like
ArcSDESQLExecute()
, I use it often2016年09月21日 06:16:54 +00:00Commented Sep 21, 2016 at 6:16 -
No problem at all. Would have answered earlier, but the time zones are out of sync ;) Agree, very handy to be able to submit the queries. Keep in mind that you can also submit other calls - I call often some stored procedures with
EXEC
and then get back the result as a recordset or a scalar value in Python (provided it was a part of SELECT statement).Alex Tereshenkov– Alex Tereshenkov2016年09月21日 06:35:35 +00:00Commented Sep 21, 2016 at 6:35
_H1
or_H2