Page 1 of 1

"You have an error in your SQL syntax" message

Posted: Fri 10 Feb 2012 23:54
by EeeeEfff
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]

Posted: Sun 12 Feb 2012 22:42
by EeeeEfff
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.

Posted: Wed 15 Feb 2012 12:12
by Shalex
"Case" is a key word. That's why you have received the error when used it without quotation.

Posted: Wed 15 Feb 2012 13:11
by EeeeEfff
Duh! Should have thought of that. Thanks for the explanation.