ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Core.Data Namespace / Datastore Class / GetSQLSyntax Method
Example

In This Topic
    GetSQLSyntax Method
    In This Topic
    Gets the gateway to access information about the SQL syntax and other functionality supported by this Datastore. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public SQLSyntax GetSQLSyntax()
    Public Function GetSQLSyntax() As SQLSyntax

    Return Value

    The gateway to access information about the SQL syntax and other functionality supported by this Datastore.
    Exceptions
    ExceptionDescription
    No valid data store has been opened prior to invoking this operation.
    The data store does not support this operation.
    A geodatabase-related exception has occurred.
    Example
    Searching a Table for non-Latin characters
    using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
    using (Table table = geodatabase.OpenDataset<Table>("TableWithChineseCharacters"))
    {
      // This will fail with many database systems that expect Latin characters by default
      string incorrectWhereClause = "颜色 = '绿'";
    
      // Correct solution is to prepend the 'National String Prefix' to the attribute value
      // For example, with SQL Server this value is 'N'
      // This value is obtained using the SQLSyntax class
      string nationalStringPrefix = "";
      SQLSyntax sqlSyntax = geodatabase.GetSQLSyntax();
      nationalStringPrefix = sqlSyntax.GetSupportedStrings(SQLStringType.NationalStringPrefix).First();
    
      // This Where clause will work
      QueryFilter queryFilter = new QueryFilter()
      {
        WhereClause = "颜色 = " + nationalStringPrefix + "'绿'"
      };
    }
    
    Using SQLSyntax to form platform agnostic queries
    public async Task UsingSqlSyntaxToFormPlatformAgnosticQueries()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("C:\\Data\\LocalGovernment.gdb"))))
        using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("FacilitySite"))
        {
          SQLSyntax sqlSyntax = geodatabase.GetSQLSyntax();
          string substringFunctionName = sqlSyntax.GetFunctionName(SQLFunction.Substring);
          string upperFunctionName = sqlSyntax.GetFunctionName(SQLFunction.Upper);
          string substringfunction = string.Format("{0}({1}(FCODE, 1, 6)) = 'SCHOOL'", upperFunctionName, substringFunctionName);
    
          QueryFilter queryFilter = new QueryFilter
          {
            WhereClause = substringfunction
          };
          using (Selection selection = featureClass.Select(queryFilter, SelectionType.ObjectID, SelectionOption.Normal))
          {
            // work with the selection.
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also