I am Curious about the behaviour of the SearchCursor on a server Database feature class. the data for some of the the fields I want to read is set as TEXT, with some of those fields values set as <Null>
I am using an insert cursor to write those fields to another database of which the equivalent field is set as DOUBLE.
The Source field names and target field names are variable and could be one field, could be 10+ fields (but always 1 to 1 mapping from source to target fields) depending on the DS/FC combo
the basis of the code that is doing the read from source and then write to target is this:
TargetCursor = arcpy.da.InsertCursor(TargetFC,TargetFields) #grab the row information from the source feature class and the equivalent mapped source fields (that should line up to the target fields) with arcpy.da.SearchCursor(SourceFC,SourceFields) as cursor: for row in cursor: print row TargetCursor.insertRow(row) del TargetCursor
The TargetFC is iterated from all feature classes within all Datasets. And the SourceFields and TargetFields are built for each specific target Featureclass so that they map when the insert cursor happens.
Mostly the source field types (however many there might be) are the same as the target field types, but there are a few instances where one of the source fields is a type TEXT and the Target is a type DOUBLE (Allows Null) But when the script runs the search cursor interprets Nulls in the source data as ' ' so when the insert cursor runs, it produces an incompatible field type error.
TargetCursor.insertRow(row) RuntimeError: The value type is incompatible with the field type. [CONFDATE]
SourceFields = [u'Shape@', u'DATA_SOURC', u'DESCRIPTIO', u'DATE_SOURC', u'DATE_DATA_', u'AMENDMENT_'] TargetFields = [u'Shape@', u'DATASRCE', u'DESCRIPT', u'SRCEDATE', u'CONFDATE', u'AMENDATE'
(note these Source and Target Field maps are specific for this loop of the overall DS/FC loop)
The last line that prints from the SearchCursor is this:
(<Polygon object at 0x46a9f10[0x104fd8c0]>, u'SP', u'SP172165ROADWAY', u'20170329', u' ', u'20170403')
So I can see that the second to last field in the source data (DATE_DATA_) is ' '
Is there a way to read that Null from the source field and insert it as Null also into the target for where that scenario happens? Or alternatively insert the 0 into the target for that situation where a TEXT is going to a DOUBLE and the Source field is Null (or interpreted as ' ')?