Last active
November 5, 2015 20:02
-
-
Save danmaps/ce7ecf4a48b13be5bcbf to your computer and use it in GitHub Desktop.
This query only seems to fail under these very specific circumstances and when the last record has a null value in a search field.
This file contains 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 | |
import os | |
import shutil | |
import tempfile | |
GDB_NAME = 'test.gdb' | |
FEATURE_CLASS_NAME = 'Widget' | |
FEATURE_CLASS_TYPE = 'POINT' | |
FEATURE_CLASS_FIELDS = ( | |
('StaticID', 'LONG', None), | |
('QAComment', 'TEXT', 200), | |
) | |
FEATURE_CLASS_DATA = ( | |
(103580, 'Correct Ramp Type', (2.5, 3.0)), | |
(554030, None, (-2.0, 5.5)), | |
) | |
WHERE_1 = "QAComment LIKE 'Correct%' AND StaticID IN (103580, 554030)" | |
WHERE_2 = "StaticID IN (103580, 554030) AND QAComment LIKE 'Correct%'" | |
ORDER = 'ORDER BY StaticID ASC' | |
# Create a file geodatabase. | |
workspace = tempfile.mkdtemp() | |
gdb_path = os.path.join(workspace, GDB_NAME) | |
arcpy.CreateFileGDB_management(workspace, GDB_NAME) | |
# Create a feature class, and add fields. | |
arcpy.CreateFeatureclass_management( | |
gdb_path, FEATURE_CLASS_NAME, FEATURE_CLASS_TYPE) | |
fc_path = os.path.join(gdb_path, FEATURE_CLASS_NAME) | |
for (field_name, field_type, field_precision) in FEATURE_CLASS_FIELDS: | |
arcpy.AddField_management( | |
fc_path, field_name, field_type, field_precision) | |
# Populate the feature class with two features. | |
field_names = [f[0] for f in FEATURE_CLASS_FIELDS] + ['SHAPE@XY'] | |
cursor = arcpy.da.InsertCursor(fc_path, field_names) | |
for row in FEATURE_CLASS_DATA: | |
cursor.insertRow(row) | |
del cursor | |
# Perform the test queries, and report the number of results. | |
search_fields = ['StaticID', 'QAComment'] | |
for where in [WHERE_1, WHERE_2]: | |
cursor = arcpy.da.SearchCursor( | |
fc_path, search_fields, where, sql_clause=(None, ORDER)) | |
count = len(list(cursor)) | |
print 'Where Clause: %s' % (where,) | |
print 'SQL Postfix: %s' % (ORDER,) | |
print 'Count: %i' % (count,) | |
print '\n' | |
del cursor | |
# Clean up. | |
shutil.rmtree(workspace) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This issue only occurs when
QAComment
is null and part of the last expression evaluated.Works:
Works:
Fails:
Fails: