Skip to main content

Several options for providing query parameters to 'queryExecute' function

The params argument of the queryExecute() function can be passed in a number of forms.  Using an object or a structure will allow named query parameters, while the array method necessitates the question mark (?) placeholders.

Because of this difference, the SQL variable has been defined twice, once in each manner.  The query is run and the result is dumped in the final example.

Object and structure methods


// Params definition option 1.
var sqlParams =
    {
        firstParam: "FIELD VALUE",
        secondParam: "FIELD VALUE"
    }


// Params definition option 2.
var sqlParams = structNew();

sqlParams.firstParam = "FIELD VALUE";
sqlParams.secondParam = "FIELD VALUE";


// Params definition option 3.
var sqlParams = structNew();

sqlParams["firstParam"] = "FIELD VALUE";
sqlParams["secondParam"] = "FIELD VALUE";


var sql = "
    declare @returnValue nvarchar(255)

    exec storedProcedure
        @firstField=:firstParam,
        @secondField=:secondParam,
        @returnThis=@returnValue output

    select @returnValue as returnValue"
;

Array method


// Params definition option 4.
// (Requires the use of question mark parameter placeholders.)

var sqlParams = ["FIELD VALUE", "FIELD VALUE"];


// Params definition option 5.
// (Requires the use of question mark parameter placeholders.)

var sqlParams = arrayNew(1);

arrayAppend(sqlParams, "FIELD VALUE");
arrayAppend(sqlParams, "FIELD VALUE");


var sql = "
    declare @returnValue nvarchar(255)

    exec storedProcedure
        @firstField=?,
        @secondField=?,
        @returnThis=@returnValue output

    select @returnValue as returnValue";

 Run and dump query


var example = queryExecute(sql, sqlParams);

dump(example);

Comments

Popular posts from this blog

Skype Now Supports Emergency Calls In the US

With the latest round of updates to Skype , it was noticed today that the instant messaging and VoIP phone service now supports emergency calling in the United States. The release notes for the most recent update to the Android version of Skype indicated that the service now allows calls to be made to US emergency calling systems via 911.  Telephony services like Skype, Google Voice , and Vonage typically don't offer this emergency calling ability without some sort of intermediate step like deferring to the phone's default dialer, as is the case with Voice, or setting up a physical address location ahead of time which is how Vonage handles it. The indication is that Skype will handle the 911 calls natively, but when verifying with an account that does not have a Skype phone number assigned to it, it was found that the instructions in the FAQ explaining how to turn on emergency calling are not accurate. Emergency calling support in Skype for the United States Interestingly, th...

Remove control of Chrome being managed by organization on personal devices

Chrome may indicate that it's being managed by a user's organization. This warning is provided by the Chrome Policies feature of the browser. To know if an instance of Chrome is managed by an organization, there will be an entry at the bottom of the browser’s hamburger menu (three dot menu), on the right side of the browser window that reads, "Managed by your organization." This is likely due to an entry in the Chrome Policies listing, which can be found by loading this page in the browser: chrome://policy The policies listed in this section are stored in the computer's file system in one of the following locations as JSON files. /usr/share/chromium/policies/managed /usr/share/chromium/policies/recommended Remove the offending JSON files, and click the Reload policies button. The Managed by your organization entry in the browser menu should be gone. A notice like this on instances of Chrome for work, school, library, or other devices that belong to an organizati...

Allow Windows authentication using SQL Server driver with DBeaver

DBeaver will allow Microsoft Windows single sign on access when connecting to Microsoft SQL Server using the SQL Server driver (rather than jTDS ).  From the driver properties settings, set the integratedSecurity flag to true . Open the Connection configuration panel and choose the Driver properties section. Set the integratedSecurity flag to true . A subtle, but important step is to not provide username and password credentials to the connection.