"You have an error in your SQL syntax" message

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Cloud Applications
Post Reply
EeeeEfff
Posts: 15
Joined: Wed 26 Oct 2011 00:48

"You have an error in your SQL syntax" message

Post by EeeeEfff » Fri 10 Feb 2012 23:54

Hi,
Using the snippet below from your sample project, the command fails with the error "You have an error in your SQL syntax at line 1, column 15: Unexpected symbol 'Case'." The full error stack is at the bottom.

But if I change the sql string to "SELECT * FROM Account", things go through just fine. Any limitation I'm not aware of?

Thanks!

Code: Select all

    static void DataReader() {

      const string sql = "SELECT * FROM Case";
      using (SalesforceConnection connection = new SalesforceConnection(ConnectionString)) {

        connection.Open();
        using (SalesforceCommand command = connection.CreateCommand()) {

          command.CommandText = sql;
          using (SalesforceDataReader reader = command.ExecuteReader()) {

            while (reader.Read()) {
              string name = reader.IsDBNull(0) ? null : reader.GetString(0);
              string phone = reader.IsDBNull(1) ? null : reader.GetString(1);
            }
          }
        }
      }
    }

Code: Select all

Devart.Data.Salesforce.SalesforceException was unhandled
  Message=You have an error in your SQL syntax at line 1, column 15: Unexpected symbol 'Case'.
  Source=Devart.Data.Salesforce
  ErrorCode=-2147467259
  Cause=Unexpected
  Code=-1
  StackTrace:
       at Devart.Data.Internal.Parser.j.a(String[] A_0, ab A_1)
       at Antlr.Runtime.j.c(ab A_0)
       at a.cy()
       at a.dy()
       at a.e9()
       at a.d2()
       at a.z()
       at a.h()
       at a.fh()
       at a.bk()
       at a.bd()
       at a.d7()
       at a.cv()
       at a.a()
       at Devart.Data.Internal.Parser.j.c(Boolean A_0)
       at Devart.Data.Salesforce.SalesforceCommand.GetStatement()
       at Devart.Data.Salesforce.SalesforceCommand.InternalPrepare(Boolean implicitPrepare, Int32 startRecord, Int32 maxRecords)
       at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
       at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at Devart.Data.Salesforce.SalesforceCommand.ExecuteReader()
       at ConsoleDemo.Program.DataReader() in C:\Program Files (x86)\Devart\dotConnect\Salesforce\Samples\Console\cs\Program.cs:line 37
       at ConsoleDemo.Program.Main(String[] args) in C:\Program Files (x86)\Devart\dotConnect\Salesforce\Samples\Console\cs\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
[/color]

EeeeEfff
Posts: 15
Joined: Wed 26 Oct 2011 00:48

Post by EeeeEfff » Sun 12 Feb 2012 22:42

Figured it out. Any table or column that is not native to Salesforce.com or does not extend from an existing SF.com object needs to be quoted. So, in my example, when I changed my query to :

"SELECT * FROM \"Case\""

the query went through just fine.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Post by Shalex » Wed 15 Feb 2012 12:12

"Case" is a key word. That's why you have received the error when used it without quotation.

EeeeEfff
Posts: 15
Joined: Wed 26 Oct 2011 00:48

Post by EeeeEfff » Wed 15 Feb 2012 13:11

Duh! Should have thought of that. Thanks for the explanation.

Post Reply