ZF2 - Select with expression changes - zend-framework2

in a project with 2.2.7 there is code like this:
$select->where->expression('CXORDERNUMBER = "' . $orderNumber . '"', null);
When trying to update this for 2.4.9 I get the following error:
*Zend\Db\Sql\Exception\RuntimeException
The number of replacements in the expression does not match the number of parameters*
I had to change it to the following, which is also more familiar to me:
$select->where(array("CXORDERNUMBER" => $orderNumber));
There are many of these expressions in the code. Sometimes it is not possible for me to change it in the way above. Can someone explain me, why this happens in the newer version of ZF?
Thanks!
Update:
The expression must be used like this:
$select->where->expression('CXORDERNUMBER = ?', array($orderNumber));
In 2.4.9 there is always a parameter set and not ignored as in 2.2.7 with a null-Value

After checking, you can write :
$where = new Where();
$where->equalTo('CXORDERNUMBER', $orderNumber);
$select->where($where);
Don't forget
use Zend\Db\Sql\Where;
Best

Related

format timezone using XSLT/xpath 2.0

I need to get one date in one format like this:
2020-06-03T06:14:00.000+0100.
following this documentation page [1], I tried to do with this expression, but always get an error:
format-dateTime(current-dateTime(), "[Y0001]-[M01]-[D01]-[H01]:[m01]:[s][Z0000]")
I tried to put with this mask too:
format-dateTime(current-dateTime(), "[Y0001]-[M01]-[D01]-[H01]:[m01]:[s][Z0001]")
but the result is 2020-06-03-14:39:50+02:00
I need to delete the ":" on the offset, ¿Which mask may I use?
[1]https://www.rfc-editor.org/rfc/rfc3339#section-5.6
A workaround for your problem could be splitting the output of format-dateTime into two parts and remove the colon on the second expression:
concat(format-dateTime(current-dateTime(), "[Y0001]-[M01]-[D01]-[H01]:[m01]:[s]"),translate(format-dateTime(current-dateTime(), "[Z0001]"),":",""))
Maybe this works for you.

Correct way to update map data type with cqerl

I am having hard time coming with the syntax of updating map using cqerl. I have tried the following till now and it doesn't work
statement = "UPDATE keyspace SET data[?] = :data_value WHERE scope = ?;",
values = [{data,"Key Value"},{data_value, "Data Value",{scope, "Scope Value"}]
What am I doing wrong here?
Also setting ttl does not work
statement = "INSERT INTO data(scope)
VALUES(?) USING ttl ?",
values = [{scope, "Scope Value"},{[ttl], 3650}]
Anyone, any idea?
Please note that you are using single quotes around the values, which in Erlang syntax indicates you are using atoms. Based on the documentation cqerl, it doesn't expect atoms there. cqerl data types
For example try:
statement = "INSERT INTO data(scope)
VALUES(?) USING ttl ?",
values = [{scope, "Scope Value"},{[ttl], 3650}]
Based on reply from the contributor on github, it takes an atom, so '[ttl]' is the right way
https://github.com/matehat/cqerl/issues/122
For updating a map correct way is with atom in the values part
statement = "UPDATE keyspace SET data[?] = ? WHERE scope = ?;",
values = [{'key(data)',"Key Value"},{'value(data)', "Data Value",{scope, "Scope Value"}]

EPStatmentObject model not working?

Im trying to modify an epl by compiling it using the compileEPL() method and add more to e.g the where clause, however im havin trouble getting it work.
Lets say this is my epl:
select * from event where A = 1
and I want to add another where condition using the AND
and I compile the epl using compileEPL()
model.getWhereClause().getChildren().add(Expressions.and()
.add(Expressions.eq("B", )));
instead of giving me:
select * from event where A = 1 and B = 2 it just gives ..where A = 1 and not adding the new where clause.
Am I doing it wrong? The EPStatementObjectModel works fine for building an object EPL from scratch but not when compiling it and adding or modify it.
Does anyone know? Thanks.
The where-clause is rooted in an EQ since "A=1".
Expression equalsExpr = model.getWhereClause();
So construct an AND clause that holds the old EQ and the new EQ.
Expression and = Expressions.and().add(equalsExpr).add(Expressions.eq("B", ...));
Finally set the "and" as the new where-clause:
model.setWhereClause(and);
In summary, when modifying expressions to add "and": when old expression is not itself an AND you should build an AND node and add the old expression and new ones.

zf2 How to Select Where Like Upper case

I trying to get some title from my database. But it doesn`t works:
$select->where->like('LOWER(title)','%'.$search_by.'%');
without LOWER it works fine.
$select->where->like('title','%'.$search_by.'%');
but I need LOWER case.
like() only seems to accept an identifier as its first parameter.
You should try this
$select->where->literal('LOWER(title) LIKE "%'.$search_by.'%"');
// or
$select->where->expression('LOWER(title) LIKE ?', '%'.$search_by.'%');
I have found a solution (in ZF3) for people who searched for:
use Zend\Db\Sql\Expression;
$upperExpr = new Expression('LOWER(?)', [title], [Expression::TYPE_IDENTIFIER]);
$select->where->like($upperExpr, "%" . mb_strtolower($search_by, 'UTF-8') . "%");
Or only strtolower() if you have no 'äÄöÖüÜ' ;)
This will create the right SQL-Statement.

Select attribute from node with XPath

I have a file with the following structure
<admin>
<sampleName>Willow oak leaf</sampleName>
<sampleDescription comment="Total genes">
<cvParam cvLabel="Bob" accession="123" name="Oak" />
</sampleDescription>
</admin>
I'm trying to get out the text "Total genes" after the sampleDescription comment, and I have used the following code:
sampleDescription = doc.xpath( "/admin/Description/#comment" )
sampleDescription = doc.xpath( "/admin/Description" ).text
But neither work. What am I missing?
might be a typo... have you tried doc.xpath("/admin/sampleDescription/#comment").text?
It's not working because there's no Description element. As mentioned by Iwe, you need to do something like sampleDescription = doc.xpath("/admin/sampleDescription/#comment").to_s
Also, if it were me, I would just do sampleDescription = doc.xpath("//sampleDescription/#comment").to_s. It's a simpler xpath, but it might be slower.
And as a note, something that trips up a lot of people are namespaces. If your xml document uses namespaces, do sampleDescription = doc.xpath("/xmlns:admin/sampleDescription/#comment").to_s. If your doc uses namespaces and you don't specify it with xmlns:, then Nokogiri won't return anything.
Try this:
doc.xpath("//admin/sampleDescription/#comment").to_s
doc.xpath returns a NodeSet which acts a bit like an array. So you need to grab the first element
doc.xpath("//admin/sampleDescription").first['comment']
You could also use at_xpath which is equivalent to xpath(foo).first
doc.at_xpath("//admin/sampleDescription")['comment']
Another thing to note is that attributes on nodes are accessed like hash elements--with [<key>]

Resources