how to check if a variable is defined in hive from within the view? - fat-free-framework

I'd like to setup a <check if='...'> where the if statement is defined on a param being defined. Is there a way to access this directly using the view?

You can use the variable on the if condition, it works:
<check if="#doesnotexist">
<true>The variable exists (?!)</true>
<false>The variable does not exist</false>
</check>
This is possible because when you try to retrieve a value from the F3 Hive, it returns NULL when the key does not exist. Per documentation, NULL is considered false for this verification:
An F3 expression inside an if attribute that equates to NULL, an empty string, a boolean FALSE, an empty array or zero, automatically invokes <false>

Related

MySQL don't read second OR condition if the first one is true

I'm trying to make an SQL-statement where I get the parameters from c# code.
The problem is that some of the parameters can be 'null'. But in MySQL I can't properly read WHERE column=NULL and I can only do WHERE column IS NULL.
So I was trying to make the statement like this:
SELECT *
FROM table
WHERE column=param #(param given from C#)
OR column IS param
I thought this would work fine because MySQL shouldn't care about the second condition if the first one is already true (like Python). And it does work when param is null. But there's an error when param is a string because then MySQL reads: WHERE column IS 'string'.
Is there a way to solve this?
You seem to want <=>, the null-safe equality operator:
WHERE column <=> param
Basically, NULL <=> NULL is true, while NULL = NULL is undefined.
Note that you should be properly passing your parameter to the query, using a prepared statement. String 'null' is not the same thing as a null value.

Mysql select query if condition parameter is null then ignore the parameter

I have the following condition (m.idAgent = agent OR agent is null). It simply returns me all agents if i pass null to agent param.
But how can i achieve the same thing in MYSQL.
I.e if i pass null then that part of the where condition should be ignored and only the other conditions which are not null should be considered.
You could use COALESCE as follows:
WHERE COALESCE(agent, m.idAgent) = m.idAgent
This should work because when agent is NULL, it would just be replaced with the RHS of the comparison, and therefore would always pass. I presume that the following is actually what your code looks like:
WHERE COALESCE(?, m.idAgent) = m.idAgent
Here the ? is a placeholder for a value to be bound in the statement.

how to escape single quotes in paramterised query

I have a problem. i am passing parameter in query using IN clause, but it is giving me error because instead of considering it as a two different values it is considering it as a one single value, so how can i handle this on sql level?
select * from table where name in ('abc','xyz'); this will work fine.
instead of this it is considering it as a
select * from table where name in ('abc,xyz'); this will give error
my parameter values are as below
basically i am checking conditional filtering. that why written this logic if values are there then consider this parameter in where clause or else ignore it.
case when '${thera}' <> '''' then
( ccp.name in ('${thera}') ) ELSE 1=1 END
Note : for avoiding conditional filtering any better approach is their then please suggest that to.
You can indeed pass a list of values as a parameter. But you need to use a Custom Parameter component.
For your example, you can create a Custom Parameter named parThera, and then for initial value you can use the expression as you would do in javascript:
['abc','xyz']
Another option is to use a function expression, like:
function (){
return "A list of words".split(" ");
}
Then, on the SQL query, add this parameter, using thera as argument name, and the parameter parThera as value.
Now you can use it inside the SQL like in your first example:
SELECT * FROM TABLE WHERE name IN (${thera})
The parameter will be expanded to 'abc','xyz', thus making it usable inside the IN (...) clause.
Note: on the SQL parameters setup, you need to specify that this parameter is of type StringArray. Otherwise it will not expand correctly.

linq to sql string property from non-null column with default

I have a LINQ to SQL class "VoucherRecord" based on a simple table. One property "Note" is a string that represents an nvarchar(255) column, which is non-nullable and has a default value of empty string ('').
If I instantiate a VoucherRecord the initial value of the Note property is null. If I add it using a DataContext's InsertOnSubmit method, I get a SQL error message:
Cannot insert the value NULL into column 'Note', table 'foo.bar.tblVoucher'; column does not allow nulls. INSERT fails.
Why isn't the database default kicking in? What sort of query could bypass the default anyway? How do I view the generated sql for this action?
Thanks for your help!
If you omit the column, the value becomes the database default, but anything you insert is used instead of the default, example:
INSERT INTO MyTable (ID, VoucherRecord) Values(34, NULL) -- Null is used
INSERT INTO MyTable (ID) Values(34) -- Default is used
Picture for example you have a column that defaults to anything but NULL, but you specifically want NULL...for that to ever work, whatever value you specify MUST override the default, even in the case of NULL.
You need to set Auto-Sync to OnInsert, Auto Generated Value to true and Nullable to false for your column to work. See here for a full run-down with explanation on the Linq side.
For viewing the generated SQL, I have to recommend LinqPad

SSIS SQL Task - "Parameter name is unrecognized"

I have a SQL Task that needs to run a simple update to update a single row.
I have set the SQLStatement to:
update agency set AgencyLastBatchSeqNo = ? where agencyID = ?
On the Parameter Mapping page I gave set Parameter 0 and Parameter 1 to variables that I know contain the right values. I have also set the Parameter Name values correctly.
In the database, the column AgencyLastBatchSeqNo is an int, AgencyID is a big int. Does anyone have a reference to find what the data types map to in SSIS? I have guessed at SHORT for the int and LONG for the big int.
When I run the task I get the following error:
[Execute SQL Task] Error: Executing the query "update agency set AgencyLastBatchSeqNo = ? where AgencyID = ?" failed with the following
error: "Parameter name is unrecognized.". Possible failure reasons:
Problems with the query, "ResultSet" property not set correctly,
parameters not set correctly, or connection not established
correctly.
Could anyone please suggest what may be wrong?
Thanks
Rob.
The answer to this is to change the Parameter Name value in the Parameter Mapping screen.
Given the following query
SELECT Id, AnimalName FROM dbo.Farm WHERE Farm_id = ?
Assuming my Parameter is an integer Variable named User::Farm_id
Choose the following values on the Parameter Mapping Screen
Variable Name - User::Farm_id
Direction - Input
Data Type - LONG
Parameter Name - 0
Parameter Size - -1
Originally the Parameter Name will be "NewParameterName". Simply change this to the ordinal position of your variable marker ("?")
If you are using more than 1 parameter then in the execute sql task window go to parameter mapping and set the parameter name to 0,1,2,3....depending on the number of parameter and the parameter size to -1..
This must be helpful to resolve your issue.
One thing you don't mention is your connection type. I assume you are not using ADO.Net since the parameter marking in that case is not a ?. For the other types of connection, parameters are named as follows:
ADO (not ADO.Net) connection: parameter names are Param1, Param2...
ODBC connection: parameter names are 1,2,3...
OLEDB connection: parameter names are 0,1,2...
For the variable types (they are different in the parameter mapping section than in any other area of SSIS) I typically use Long for Int's and I typically leave the length set to -1. I believe that a Long will work for both Int's and Bigint's.
See SSIS data types.
int = DT_I4 (4 byte integer) = Int32 variable
bigint = DT_I8 (8 byte integer) = Int64 variable
Make sure you're quoting your values, and that you don't have typos in your column names.
When defining the parameter mappings any trailing blanks after the parameter name can cause this message too.
Go to Parameter Mapping and change Mapped Parameter_Name = 0 instead of using default name.
and for next parameter it should be 1. and so on...
Note:- you have to change the "Data Type" as per the value.
it will just take place on the occurrence of "?"