ArcSDESQLExecute is not able to handle unique identifiers

837
3
Jump to solution
12-02-2022 01:38 AM
Cristian_Galindo
Occasional Contributor III

Using ArcGIS Pro 2.9.5 I found that ArcSDESQLExecute is not able to handle unique identifiers in a table.

I tried to run the following Script:

database = 'C:\\Installation\\updm.sde'

egdb_conn = arcpy.ArcSDESQLExecute(database)
sql_clause = "SELECT PROJECT_ID from DataOwner.My_PROJECTS;"
print(sql_query)

query_return = egdb_conn.execute(sql_clause)

len(query_return)

 

the table My_PROJECTS has a column PROJECT_ID defined as a uniqueidentifier., the result odf the execution is:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
In  [39]:
Line 12:    query_return = egdb_conn.execute(sql_clause)

File C:\ArcGISPro\Resources\ArcPy\arcpy\arcobjects\arcobjects.py, in execute:
Line 44:    return convertArcObjectToPythonObject(self._arc_object.Execute(*gp_fixargs(args)))

AttributeError: ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 Invalid pointer argument to function

 

 

0 Kudos
1 Solution

Accepted Solutions
Cristian_Galindo
Occasional Contributor III

Despite the fact that unique identifiers are supported, I went for a casting approach

database = 'C:\\Installation\\updm.sde'

egdb_conn = arcpy.ArcSDESQLExecute(database)
# Getting the ID's froma table
sql_clause = "SELECT CAST(PROJECT_ID AS VARCHAR(100)) from DataOwner.My_PROJECTS;"

query_return = egdb_conn.execute(sql_clause)

# Whatever operation you want to do with the results, in this case
# is just the verification of how many results, but they will be 
# iterated later

len(query_return)

 

* by the way the semicolon does not make any difference.

View solution in original post

0 Kudos
3 Replies
BlakeTerhune
MVP Regular Contributor

Try without the ending semicolon in the SQL statement.

0 Kudos
Cristian_Galindo
Occasional Contributor III

Thanks for the suggestion.

As a matter of fact I did it before of making the post, but I did it again just to be able to copy and paste the output from the execution:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
In  [48]:
Line 7:     query_return = egdb_conn.execute(sql_clause)

File C:\ArcGISPro\Resources\ArcPy\arcpy\arcobjects\arcobjects.py, in execute:
Line 44:    return convertArcObjectToPythonObject(self._arc_object.Execute(*gp_fixargs(args)))

AttributeError: ArcSDESQLExecute: StreamBindOutputColumn ArcSDE Error -65 Invalid pointer argument to function
---------------------------------------------------------------------------

 

As I already state in my original post this happens with columns defined as unique identifier. If I try to make the query to an INT, VARCHAR or DECIMAL column, the query is performed with out any issues.

0 Kudos
Cristian_Galindo
Occasional Contributor III

Despite the fact that unique identifiers are supported, I went for a casting approach

database = 'C:\\Installation\\updm.sde'

egdb_conn = arcpy.ArcSDESQLExecute(database)
# Getting the ID's froma table
sql_clause = "SELECT CAST(PROJECT_ID AS VARCHAR(100)) from DataOwner.My_PROJECTS;"

query_return = egdb_conn.execute(sql_clause)

# Whatever operation you want to do with the results, in this case
# is just the verification of how many results, but they will be 
# iterated later

len(query_return)

 

* by the way the semicolon does not make any difference.

0 Kudos