zf2 How to Select Where Like Upper case - zend-framework2

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.

Related

How to find multiple element in appium having same id in Python?

I am writing test code in Appium of an Andriod Project in python . The problem is that I am not able to access two button in two different Activity having same Id . I have tried to access the second button in this way.But none of them works. How to resolve the issue?
driver.find_element_by_id("com.myapp.testApp:id/login[1]").click(), driver.find_element_by_class_name("android.widget.Button").click()
driver.find_element_by_xpath("(//button[#id='login'])[1]").click()
driver.find_element_by_xpath("//android.widget.Button[#text='Change Password']").click()
Use .find_elements*:
elements = driver.find_elements_by_xpath("xpath")
#check elements number
print(len(elements))
#click second element
elements[1].click()
Can you try with textview:
driver.find_element_by_xpath("//android.widget.TextView[#text='Change Password']").click()
If buttons texts are different, try by accessibility_id
driver.find_element_by_accessibility_id("Login").click()
driver.find_element_by_accessibility_id("Change Password").click()
OR
If you are familiar with uiautomator,
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.myapp.testApp:id/login[1]")')
driver.find_element_by_android_uiautomator('new UiSelector().resourceId("com.myapp.testApp:id/login[2]")')
You can use the get method with findElements:
driver.findElements(By.xpath("yourXpath]")).get(0).click();
You can do link this, It will give you proper Output:
Input is:
d1 = driver.find_elements_by_id("com.application.zomato:id/price")
itemtotalprice = d1[0].get_attribute("text")
Here, is my output:
Mandarin Oak
₹200
₹166.75

ZF2 - Select with expression changes

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

Error loading Partial View script (file: ~/Views/MacroPartials/ezSearch.cshtml)

I am having some issue with ezSearch (Umbraco) and it is very similar to this one
http://our.umbraco.org/projects/website-utilities/ezsearch/bugs-feedback-suggestions/48460-Search-error-when-searching-for-test-keyword?p=0#comment176864
Here is the screenshot of error
http://our.umbraco.org/media/upload/e08b702e-b738-42a4-81d8-382a4400b96a/error.jpg
Can anyone hep me with this please?
Thank you,
Adi
I'm using ezSearch, and from reading the ezSearch.cshtml this looks like a bug if the query passed to the macro is " ". That is to say, if the search is empty, it works ok, but if the search is an actual quoted space then the line in the cshtml: (line 60 in my version)
// Check the search term isn't empty
if(!string.IsNullOrWhiteSpace(model.SearchTerm))
{
// Tokenize the search term
model.SearchTerms = Tokenize(model.SearchTerm);
...
etc.
...
}
ends up with a bad set of tokens in model.SearchTerms.
it's a bit of a hack, but i think putting this before that if statement will help.
model.SearchTerm = model.SearchTerm.Replace("\"","").Replace(" ","").Replace("'","");
..hope that helps.
'ingie.

How to force the my url not to change the value of '#'

I have an URL address that I change dynamically I it goes something like this:
The dynamic part is the -> edition = Model.Edition.Usually it as an integer value and the url ends up something like that: ....&edition=1232113 . Sometimes I need it to end up like that : &edition=1232113#10_11 and I managed to pass th right value to the edition placeholder but after the reload it doesn't show the same url that I expected it is similar but it substitutes the '#' with '%23'. And it looks something like that: 1232113%2310_11 and the effect is not what I expect.
From the other side, when I type it manually : 1232113#10_11 it works.
Can you help?
If you problem is concerning that the Url.Action is converting a part of your url, you may want to use the RAW method.
#Html.Raw(Url.Action("Method","Controller", new { Id = Model.DId, dbId = Model.DbId, iconId = Model.IconId, edition = Model.Edition })

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