Reputation: 185
I have some code that was using an ADODB.Recordset
object to query a MariaDb database. In my query I am using coalesce
such as this -
SELECT COALESCE(offers_owner.description, offers.description) AS description FROM
offers_owner LEFT JOIN websites on offers_owner.website_id = websites.id LEFT JOIN offers on
offers_owner.offer_id = offers.id WHERE offers_owner.id = 401
and in my code I have this -
If Not IsNull(rs("description")) or rs("description") <> "" Then
response.write "<p class=" & chr(34) & "clear" & chr(34) & "><br />" & replace(replace(rs("description"),"company_name",session("company")),"company_city",session("city2")) & "<br /><br /></p>" & vbcrlf
end if
This works fine, and outputs as need be.
But, as soon as I switch to using an ADODB.Command
object, I get an "invalid use of null". If I remove the conditional If Then
, it does not throw and error.
Any idea as to why?
Thank you.
I tried to limit the conditionals in the IF Then statement
Upvotes: 0
Views: 165
Reputation: 357
Assuming that your rs("description")
yields null
, then the condition in your question would compare null agains an empty string.
I could imagine, that that is the 'invalid use of null' from the error.
In the codesnippet from your answer, you comapre the .Value
of rs("description")
against the empty string. It is possible (very likely) that .Value
always returns a string and is therefore allowed to be checked against the empty string.
As the comments to your answer have pointed out, it is vanishingly unlikely (if still tecnically possible) that the assignment to a var makes a difference.
Edit:
you could also solve the "null to empty string" problem in your mariadb query, by simply wrapping your COALESCE
in to a IFNULL(COALESCE([...]), '')
Upvotes: 0
Reputation: 185
The way I solved this was to assign the value of the field in question to a variable, such as this:
description = myRS("description").value
if not isNULL(description) and description <> "" Then
replace(description,"xyz","abc")
end if
Upvotes: -1