Created
August 1, 2017 19:22
-
-
Save stdavis/eeb18ee8ec7ba6cf64a0e5b0c6791143 to your computer and use it in GitHub Desktop.
Template with no OID bug in Pro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import arcpy | |
| from os import path | |
| #: SQL Server (non-SDE) database table | |
| source = r'X:\deq-enviro\scripts\nightly\databases\ustdata.sde\USTDATA.dbo.FMSFacilityUstNew' | |
| destination_workspace = r'c:\temp\destination.gdb' | |
| destination_name = 'FMSFacilityUstNew' | |
| if path.exists(destination_workspace): | |
| print('cleaning up old database') | |
| arcpy.management.Delete(destination_workspace) | |
| print('creating new database') | |
| arcpy.CreateFileGDB_management(path.dirname(destination_workspace), path.basename(destination_workspace)) | |
| #: creates empty records... | |
| destination = arcpy.CreateTable_management(destination_workspace, destination_name, source) | |
| fields = [field.name for field in arcpy.da.Describe(source)['fields']] | |
| with arcpy.da.SearchCursor(source, fields) as cursor, arcpy.da.InsertCursor(destination, fields) as insert_cursor: | |
| for row in cursor: | |
| insert_cursor.insertRow(row) | |
| #: works the way that it should... | |
| print('copying data') | |
| fgdb_source = arcpy.management.Copy(source, str(destination) + '_Copy') | |
| #: works correctly... | |
| destination = arcpy.CreateTable_management(destination_workspace, destination_name + '_addField') | |
| types = { | |
| 'Blob': 'BLOB', | |
| 'Date': 'DATE', | |
| 'Double': 'DOUBLE', | |
| 'Guid': 'GUID', | |
| 'Integer': 'LONG', | |
| 'Single': 'FLOAT', | |
| 'SmallInteger': 'SHORT', | |
| 'String': 'TEXT' | |
| } | |
| fields = [] | |
| for field in arcpy.da.Describe(source)['fields']: | |
| if field.isNullable: | |
| nullable = 'NULLABLE' | |
| else: | |
| nullable = 'NON_NULLABLE' | |
| if field.required: | |
| required = 'REQUIRED' | |
| else: | |
| required = 'NON_REQUIRED' | |
| arcpy.management.AddField(destination, field.name, types[field.type], | |
| field_precision=field.precision, | |
| field_scale=field.scale, | |
| field_length=field.length, | |
| field_is_nullable=nullable, | |
| field_is_required=required) | |
| fields.append(field.name) | |
| with arcpy.da.SearchCursor(source, fields) as cursor, arcpy.da.InsertCursor(destination, fields) as insert_cursor: | |
| for row in cursor: | |
| insert_cursor.insertRow(row) | |
| print('done') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment