Allow null value when sending notification that includes a condition - notifications

I am trying to send a notification when a field changes. It is working fine as long as there is a value in each field. However, if any field (Upd or Pre) has a null value the notification won't send. Using Laravel 5.7. Field1 is a required field but all others are okay to be null.
if($field1InfoUpd[0]->email != $field1InfoPre[0]->email
OR $field2InfoUpd[0]->email != $field2InfoPre[0]->email
OR $field3InfoUpd[0]->email != $field3InfoPre[0]->email
OR $field4InfoUpd[0]->email != $field4InfoPre[0]->email
OR $field5InfoUpd[0]->email != $field5InfoPre[0]->email
)

Related

How to return empty array in a case block?

working on a trigger in Postgres. Currently running into an issue where I'm trying to set a value as either an empty array or an array with just the one NEW value, depending on if there is a NEW value or not:
project_ids =
CASE NEW.project_tracking_id
WHEN null THEN ARRAY
ELSE ARRAY[NEW.project_tracking_id]
END
"Set project_ids to either [] (if null) or [NEW.project_tracking_id]"
The else block works as expected and will store that new value as the first element in a new array. The WHEN null THEN ARRAY part does not work for me though. It just adds null to the array, producing [null].
How do I specify that it should just be an empty array in that case? Not sure if this helps, but my sequelize type for that field is:
type: Sequelize.ARRAY(Sequelize.STRING),
defaultValue: [],
project_ids =
CASE NEW.project_tracking_id
WHEN null THEN ARRAY[]::XXX[] //XXX is the type of the array.
ELSE ARRAY[NEW.project_tracking_id]
END
The problem is that your CASE expression implicitly compares NEW.project_tracking_id = NULL, which is never true, even if the left side is NULL. Use the other form of CASE:
CASE WHEN NEW.project_tracking_id IS NULL
THEN ARRAY[]::integer[]
ELSE ARRAY[NEW.project_tracking_id]
END
This assumes that the data type of NEW.project_tracking_id is integer; change the array type if that is not the case.
A shorter version of the above would be
coalesce(NEW.project_tracking_id, ARRAY[]::integer[])

typeorm: how to properly use IsNotNull/IsNull?

We created a helper function to create wheres easier. It works fine with eq, neq, lt and gt. Now we're trying to add is null/is not null (for a date column, not sure if that matters).
The critical part of the function looks like this:
// This is ran in a loop for every attribute
const query = `${attribute}` ${comparator} :value${index}`;
// if the checked 'value' is NULL then use IsNull(), same for NOT NULL, otherwise simply use value
const params = { [`value${index}`]: value == 'NULL' ? IsNull() : value === 'NOT NULL' ? Not(IsNull()) : value};
// Add this (sub)query to the qb
qb.andWhere(query, params);
Now we get an error saying this:
You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ’_type = ‘not’, _value = ‘[object Object]‘, _useParameter =
true, `_multipl’ at line 1"
Value is [object Object] - which kind of makes sense if we use IsNotNull(), right?
As far as I understand from this comment, IsNull() and Not(IsNull()) should work like we are trying to.
We use #nestjs/typeorm 7.1.5.
To check for NULL you need
qb.andWhere(`${attribute} IS NULL`)
To check for NOT NULL you need
qb.andWhere(`${attribute} IS NOT NULL`)
(Note: Omit the second argument, parameters, for these cases).
From your code seems you are using string values 'NULL' and 'NOT NULL' as the value arguments and checking these as special cases. Your code will now look like this:
if ((value == 'NULL' && comparator == '=') || (value == 'NOT NULL' && comparator == '<>'))
qb.andWhere(`${attribute} IS NULL`);
if ((value == 'NOT NULL' && comparator == '=') || (value == 'NULL' && comparator == '<>'))
qb.andWhere(`${attribute} IS NOT NULL`);
else
qb.andWhere(`${attribute} ${comparator} :value${index}`, { [`value${index}`]: value});
(In the code above I check for '=' and '<>' which are standard SQL comparison operators. If your SQL dialect uses 'eq' and 'ne' in place of '=' and '<>', which you mention in your question, you will need to change the code above. If so please update your question and add the appropriate tag to say which SQL database you are using).
When you test this, I recommend that you turn on TypeOrm full logging so you can see the actual generated SQL and you be able to quickly solve any problems. See TypeOrm logging.

tmap talend NullPointerException

I'm trying to read two csv's into my SQL Server. Getting NullPointerException even though I'm allowing nullables and checking null each time. When debugging, it appears that the null check expression is evaluating to the FALSE condition every time, even when the string is null.
Here's an example of my null check:
( row2.Acq_date.equals(null) || row2.Acq_date.equals("") ||
row2.Acq_date == null ) ? null : (int)
TalendDate.diffDate(TalendDate.getCurrentDate(),row2.Acq_date,"MM")
You shouldn't do null checking like this row2.Acq_date.equals(null).
This is the correct way : row2.Acq_date == null (which you actually included in your test, only doing it after testing row2.Acq_date.equals(null) is too late, since that is the part throwing the NullPointerException).
Here's the correct way :
( row2.Acq_date == null ? null : (int)
TalendDate.diffDate(TalendDate.getCurrentDate(),row2.Acq_date,"MM")
Based on your comment, row2.Acq_date is of type date, which you can read directly from your file using the appropriate date format. If the column is empty (or contains whitespaces) in your file, Talend returns a null date, which is handled by the above test.

Getting null string from SQL database

I'm trying to pull data from sql database and assigning it to text boxes.
But I get error when there is no data in column (null).
string athleteId = Request.Cookies["LoggedInUser"].ToString();
var athlete = AthleteDAL.GetAthleteByID(athleteId);
if (athlete.AthleteFName != null)
{
TextBoxFirstName.Text = athlete.AthleteFName.ToString();}
I'm getting null point exception on if statement.
you need to have this
if (athlete!=null && athlete.AthleteFName != null)
because athlete may be null and trying to use it (athlete.AthleteFName) is an invalid operation

MS Access SQL If Then statement for check boxes

I am trying to get a search query to run. It is as follows. The last two lines of code do not work. It is a check box. If the checkboxYes is checked then pull only the items in the YES/NO field of the database that are checked. If the checkboxNo is checked then pull only the items in the YEs/No field of the database that are checked. If BOTH boxes are checked, then pull all items. I cannot get either scenario to work. All other fields except the check boxes work correctly.
SELECT *
FROM NLog
Where
(([Forms]![FrmSearch]![Combo13] is Null) OR ((NLog.State)=[Forms]![FrmSearch]![Combo13])) and
(([Forms]![FrmSearch]![daterecsrt] is Null) or (((NLog.DateRec) Between [Forms]![FrmSearch]![daterecsrt] And [Forms]![FrmSearch]![daterecend]))) and
(([Forms]![FrmSearch]![datesrttxt3] is Null) or (((NLog.DateRec) Between [Forms]![FrmSearch]![datesrttxt3] And [Forms]![FrmSearch]![dateendtxt3]))) and
(([Forms]![FrmSearch]![checkyes] is Null) or ((NLog.Compchk)=True)) and
(([Forms]![FrmSearch]![checkNo] is Null) or ((NLog.Compchk)=False))
Thank you!
I am using MS Acess 2010. This is using the boxes on a form to run the query.
NLog is a table so why are you referencing fields in the table as [Forms]![FrmSearch]![Combo13] and etc. Those are controls on a form and not fields in your table. Shouldn't your query really be:
SELECT * FROM NLog WHERE
(NLog.State is Null OR NLog.State = Forms!FrmSearch!Combo13)
AND (NLog.DateRec is Null OR NLog.DateRec Between Forms!FrmSearch!daterecsrt And Forms!FrmSearch!daterecend
AND (NLog.DateRec is Null OR NLog.DateRec Between Forms!FrmSearch!datesrttxt3 And Forms!FrmSearch!dateendtxt3)
AND (NLog.Compchk is Null OR NLog.Compchk = True)
AND (NLog.Compchk is Null OR NLog.Compchk = False)
Also, the following will not give you any results:
AND (NLog.Compchk is Null OR NLog.Compchk = True)
AND (NLog.Compchk is Null OR NLog.Compchk = False)
NLog.Compchk can not be both True and False. It is going to be one or the other or Null.
You will need to check if the boxes are checked and build the last part of your query around that, (ie IIF()).