Search code examples
c#sqlintersystems-cache

Intersystems Cache Named CacheParameter


Instead of using ? marks within an SQL statement for parameters, I'd like to use named fields as it's more readable than WHERE something = ? AND somethingelse < ? and whatever LIKE ?

Is the following possible in some capacity?

SELECT * FROM NAMESPACE.Table WHERE Name = @name AND Something = @anothervar

The official documentation doesn't mention it at all and shows me the following

string SQLtext = 
      "SELECT ID, Name, DOB, SSN "
    + "FROM Sample.Person "
    + "WHERE Name %STARTSWITH ?"
    + "ORDER BY Name";
  CacheCommand Command = new CacheCommand(SQLtext, CacheConnect);

The parameter value is set to get all rows where Name starts with A, and the parameter is passed to the CacheCommand object:

   CacheParameter Name_param = 
    new CacheParameter("Name_col", CacheDbType.NVarChar);
  Name_param.Value = "A";
  Command.Parameters.Add(Name_param);

Solution

  • Named SQL parameters in Caché available only in two ways.

    • Embedded sql with &sql(). You can't use this way, while are working from .Net, just because it is CacheObjectScript only.
    • Class Query You can't also use it, just because such SQL queries should be defined on Class itself, and when you call it, you just should pass all arguments, without names.

    So, in your case no way.