Workaround for param in Open BlueDragon - coldfusion

Open BlueDragon 2.0.2, does not support:
param rc.nodeid = "";
In particular the param part does not work
What is a good workaround?

Although I'm not familiar with BD, each of these options should work:
Ternary operator:
rc.nodeid = structKeyExists( rc, "nodeid" ) ? rc.nodeid : "";
Normal if/else statement:
if( !structKeyExists( rc, "nodeid" ) ) {
rc.nodeid = "";
}
Personally, I prefer the ternary operator because it's almost as concise as param, but you will be sacrificing some readability for those who are unfamiliar with it.
EDIT: I went and had a look at BD's documentation. It looks like BD requires the "name" attribute, so you should be able to do this:
param name="rc.nodeid" default="";

Related

How do I make a working AND Statement in Discord JS?

const args = message.content.split(" ");
const questionString = args.slice(1).join(" ");
if (questionString.includes(("THIS" && "THAT"))) message.channel.send(`Sure thing, <#${message.author.id}>`);
So I am trying to make my Bot check if both of these are included in a message. The problem is thought that the bot doesn't react to just "THIS" being in the message, but it reacts when just "THAT" is included in the message which I don't want. I only want the Bot to respond when both "THIS" and "THAT" are included. I couldn't find anything about AND statements in Discord JS and the ones I found for normal JavaScript tutorials always showed it like that. Is it different for Discord JS? And if so what do I have to do to make it work.
Thanks!
you can not use the AND statement like that. The correct usage will be:
if (questionString.includes("THIS") && questionString.includes("THAT"))
So your code will end in something like:
const args = message.content.split(" ");
const questionString = args.slice(1).join(" ");
if (questionString.includes(("THIS" && "THAT"))) message.channel.send(`Sure thing, <#${message.author.id}>`);
You can also use the Array.every funtion, if you use this, you will get something like:
const args = message.content.split(" ");
const questionString = args.slice(1).join(" ");
const searchParams = ["THIS", "THAT"];
if (searchParams.every(questionString.includes)) message.channel.send(`Sure thing, <#${message.author.id}>`);

cfscript and queryExecute() using like instead of equals

I'm curious if this is the correct method to use the like operator when using queryExecute() in a cfscript function.
if( len(arguments?.lastName) ){
local.sqlWhere & = " AND t_lastname LIKE :lName";
local.sqlParams.lName = { value : arguments.lastName & '%', cfsqltype:'cf_sql_varchar'};
};
Is it just appended like a string with & '%'?
I've just go through your issue. In coldfusion & symbol always concatenation the two string. So we could not able to use like that. Here I've wrote some sample code for you please check that. I hope it will more help full to wrote a script based query.
local.MyQry = "SELECT * FROM Users WHERE 1=1 ";
I've used same condition from you. Not sure about your conditions
if( len(arguments?.lastName) ){
local.MyQry &= " AND Email like :email"
}
Here concatenate the query with previous one if the condition is true. And mentioned :(colon as we are going to use as queryparam)
local.qry = new Query( datasource = 'your DB name' , sql = Local.MyQry);
if( len(arguments?.lastName) ){
local.qry.addParam( name="email", value="%#Arguments.email#%", cfsqltype="cf_sql_varchar");
}
return local.qry.execute();
You can give the % symbol here based on your scenario . Ex %#Arguments.email#. or %#Arguments.email#%
I hope this will help you more. Thanks

Create stored procedure from x++

Got myself into trouble today trying to create a stored procedure from ax.
Here is a simple example:
static void testProcedureCreation(Args _args)
{
MyParamsTable myParams;
SqlStatementExecutePermission perm;
str sqlStatement;
LogInProperty Lp = new LogInProperty();
OdbcConnection myConnection;
Statement myStatement;
ResultSet myResult;
str temp;
;
select myParams;
LP.setServer(myParams.Server);
LP.setDatabase(myParams.Database);
//Lp.setUsername("sa");
//Lp.setPassword("sa");
sqlStatement = #"create procedure testproc
as begin
print 'a'
end";
//sqlStatement = strFmt(sqlStatement, myStr);
info(sqlStatement);
perm = new SqlStatementExecutePermission(sqlStatement);
perm.assert();
try
{
myConnection = new OdbcConnection(LP);
}
catch
{
info("Check username/password.");
return;
}
myStatement = myConnection.createStatement();
myResult = myStatement.executeQuery(sqlStatement);
while (myResult.next())
{
temp = myResult.getString(1);
info(temp);
if (strScan(temp, 'Error', 1, strLen(temp)) > 0)
throw error(temp);
}
myStatement.close();
CodeAccessPermission::revertAssert();
}
To be honest, in my real example I am using BCP and some string concat with a lot of | ' and "".
Anyway, here is what I got:
For a couple of hours I kept changing and retrying a lot of things and, a good thought came into my mind.
"Let's try with a much easier example and check the results!"
OK, no luck, the results were the same, as you can see in the pic above.
But for no reason, I tried to :
exec testproc
in my ssms instance and to my surprise, it worked. My small procedure was there.
It would be so nice if someone could explain this behavior and maybe what should be the correct approach.
This Q/A should provide an answer.
How to get the results of a direct SQL call to a stored procedure?
executeQuery vs executeUpdate

Replace the jquery datepicker dateFormat with momentjs parsing and format

For the sake of consistency I would like to be able to switch the parsing/formatting of JQuery UI's datepicker to use momentjs instead. Any thoughts on what might be the best way to do this?
So far the best method that I've found to do this is to override the global jquery-ui parseDate and formatDate functions like so:
$.datepicker.parseDate = function(format, value) {
return moment(value, format).toDate();
};
$.datepicker.formatDate = function (format, value) {
return moment(value).format(format);
};
Then this nicely allows you to use the usual syntax for attaching a datepicker to a field but the format you specify will instead refer to a momentjs format instead http://momentjs.com/docs/#/parsing/string-format/
$(".selector").datepicker({ dateFormat: "MM-DD-YYYY" });
If anyone using https://xdsoft.net/jqplugins/datetimepicker plugin and facing the same issue, the first solution will be your take.
After using the accepted solution you will face selected date doesn't highlighted the issue.
So modifying accepted solution to fix selected date highlight issue
jQuery.datetimepicker.setDateFormatter({
parseDate: function (date, format) {
var d = moment(date, format);
return d.isValid() ? d.toDate() : false;
},
formatDate: function (date, format) {
if (format == "Y/m/d")
return moment(date).year() + "/" + moment(date).month() + "/" + moment(date).date();
return moment(date).format(format);
}
});

Replace expression with subsection using regex?

My IDE PHPstorm allows you to do search and replace using regex, one of the things I find myself often doing is switching the order or action, aka, in function a I will set a value on items from list a using list b as the values.
but then in function b I want to invert it.
so I want to set a value on items from list b using list a as the values.
A proper example is this:
var $clipDetailsGame = $('#clipDetailsGame');
var $clipDetailsTitle = $('#clipDetailsTitle');
var $clipDetailsByline = $('#clipDetailsByline');
var $clipDetailsTeamOne = $('#clipDetailsTeamOne');
var $clipDetailsTeamTwo = $('#clipDetailsTeamTwo');
var $clipDetailsReferee = $('#clipDetailsReferee');
var $clipDetailsDescription = $('#clipDetailsDescription');
var $clipDetailsCompetition = $('#clipDetailsCompetition');
function a(clip){
clip.data('gameId' , $clipDetailsGame.val());
clip.data('title' , $clipDetailsTitle.val());
clip.data('byline' , $clipDetailsByline.val());
clip.data('team1' , $clipDetailsTeamOne.val());
clip.data('team2' , $clipDetailsTeamTwo.val());
clip.data('refereeId' , $clipDetailsReferee.val());
clip.data('description' , $clipDetailsDescription.val());
clip.data('competitionId', $clipDetailsCompetition.val());
}
function b (clip){
$clipDetailsGame .val(clip.data('gameId'));
$clipDetailsTitle .val(clip.data('title'));
$clipDetailsByline .val(clip.data('byline'));
$clipDetailsTeamOne .val(clip.data('team1'));
$clipDetailsTeamTwo .val(clip.data('team2'));
$clipDetailsReferee .val(clip.data('refereeId'));
$clipDetailsDescription.val(clip.data('description'));
$clipDetailsCompetition.val(clip.data('competitionId'));
}
Excluding the formatting (It's just there to make my point clearer), what kind of regex could I use to do the replacement for me?
Basic regex -- nothing fancy or complex at all
Search for: (clip\.data\('[a-zA-Z0-9]+')\s*, (\$[a-zA-Z0-9]+\.val\()(\)\);)
Replace with: \$2\$1\$3
The only PhpStorm-related thing here is replacement string format -- you have to "escape" $ to have it work (i.e. it has to be \$2 to use 2nd back-trace instead of just $2 or \2 (as used in other engines)).
This will transform this:
clip.data('gameId' , $clipDetailsGame.val());
clip.data('title' , $clipDetailsTitle.val());
clip.data('byline' , $clipDetailsByline.val());
clip.data('team1' , $clipDetailsTeamOne.val());
clip.data('team2' , $clipDetailsTeamTwo.val());
clip.data('refereeId' , $clipDetailsReferee.val());
clip.data('description' , $clipDetailsDescription.val());
clip.data('competitionId', $clipDetailsCompetition.val());
into this:
$clipDetailsGame.val(clip.data('gameId'));
$clipDetailsTitle.val(clip.data('title'));
$clipDetailsByline.val(clip.data('byline'));
$clipDetailsTeamOne.val(clip.data('team1'));
$clipDetailsTeamTwo.val(clip.data('team2'));
$clipDetailsReferee.val(clip.data('refereeId'));
$clipDetailsDescription.val(clip.data('description'));
$clipDetailsCompetition.val(clip.data('competitionId'));
Useful link: http://www.jetbrains.com/phpstorm/webhelp/regular-expression-syntax-reference.html
Mopping up (not quite the answer to this question, but another way of organizing the code to make search and replace unnecessary):
var $details = {};
var fields = [
'Game', 'Title', 'Byline', 'TeamOne', 'TeamTwo', 'Referee', 'Description',
'Competition'
];
for(field in fields) {
$details[field] = $('#clipDetails' + field);
}
function a(clip) {
for(field in fields) {
clip.data(field, $details[fields].val());
}
}
function b(clip) {
for(field in fields) {
$details[field].val(clip.data(field));
}
}
Yes, I know that there are tiny naming inconsistencies that means that this isn't working out of the box, such as Game versus gameId. This is an excellent occasion to clean that up too :). If you still want to keep the title case for the ids (such as #clipDetailsGame in stead of #clipDetailsgame), keep it in title case in the fields array and use toLowerCase where you need lower case.
By the way, there is an interesting read on what makes DRY a good thing here: https://softwareengineering.stackexchange.com/questions/103233/why-is-dry-important