Spring data jpa error while parse `ignorecase` param in custom function - spring-data-jpa

I have a repository class with custom method
#RepositoryRestResource(path = "issues", collectionResourceRel = "issues", excerptProjection = IssueProjection.class)
public interface IssueRepository extends JpaRepository<Issue, UUID> {
...
#Query(value = "select i from Issue i " + "where LOWER(name) LIKE LOWER(concat('%', ?1, '%')) "
+ "OR LOWER(status.name) LIKE LOWER(concat('%', ?1, '%')) "
+ "OR LOWER(project.name) LIKE LOWER(concat( '%', ?1, '%')) "
+ "OR LOWER(concat(project.code, '-', number)) LIKE LOWER(concat( '%', ?1, '%'))",
countQuery = "select count(i) from Issue i "
+ "where LOWER(name) LIKE LOWER(concat('%', ?1, '%')) "
+ "OR LOWER(status.name) LIKE LOWER(concat('%', ?1, '%')) "
+ "OR LOWER(project.name) LIKE LOWER(concat( '%', ?1, '%')) "
+ "OR LOWER(concat(project.code, '-', number)) LIKE LOWER(concat( '%', ?1, '%'))")
<S extends Issue> Page<S> findAllByValue(String value, Pageable pageable);
...
My problem is that ignorecase param causes error if i use custom function:
This works fine:
http://localhost:8081/api/issues?size=10&page=0&sort=creationDateTime,desc,ignorecase
But this not:
http://localhost:8081/api/issues/search/findAllByValue?value=g&size=10&page=0&sort=creationDateTime,desc,ignorecase
I got an error:
Caused by: org.postgresql.util.PSQLException: ERROR: function lower(timestamp with time zone) does not exist
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
If i remove ignorecase function will work but result will be case sensitive
If i change sort to some string name function will work properly but why sort works properly with default query?

Related

Fix Mongo query in Lumen

I have a query in the lumen. But it does not work. The query is :
return Order::whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
->whereBetween('source_latitude',[51.365807806703,51.454384193297])
->where('status','=','pending')
->where('created_at','<=', 2016-04-07 12:00:35)
->where('created_at','>=', 2016-04-07 11:55:35)
->orWhere(function($query)
{
$query->whereBetween('source_longitude', [51.321519613407, 51.498672386593])
->whereBetween('source_latitude',[35.612195271526,35.756086728473])
->where('status','=','pending')
->where('created_at','<=',2016-04-07 11:55:35)
->where('created_at','>=',2016-04-07 11:50:35);
}
)->get();
But when I remove orWhere function from the query I get expected result
You probably using orWhere a little bit wrong. You need to put where to another where to execute query properly. What You are doing now is something like that where a is 1 and b is 2 or (c is 3 and d is 4), but I believe, You want to do something like that where (a is 1 and b is 2) or (c is 3 and d is 4)
Try this one:
return Order::where(function ($query) {
$query->whereBetween('source_longitude', [$minLon_try_one, $maxLon_try_one])
->whereBetween('source_latitude', [51.365807806703, 51.454384193297])
->where('status', '=', 'pending')
->where('created_at', '<=', '2016-04-07 12:00:35')
->where('created_at', '>=', '2016-04-07 11:55:35');
})->orWhere(function ($query) {
$query->whereBetween('source_longitude', [51.321519613407, 51.498672386593])
->whereBetween('source_latitude', [35.612195271526, 35.756086728473])
->where('status', '=', 'pending')
->where('created_at', '<=', '2016-04-07 11:55:35')
->where('created_at', '>=', '2016-04-07 11:50:35');
})->get();

Zend Framework Inner Join Query

I am not sure why Zend makes it difficult to write queries. I am from CodeIgniter background.
I want to write this query
SELECT tbllicenses.*, tblclients.email As clientemail FROM tbllicenses
INNER JOIN tblclients ON tblclients.id = tbllicenses.clientid
Do you know how can I write this query without using "table AS t" kind of assignments ?
Having table aliases is the standard way to write queries. so if you will go for zend join functions then aliases are required. Another way around is that you can pass the whole query to '$this->db->query("query....")'.
One way to do it could be:
class Application_Model_Soa_Service_LicenseService extends Zend_Db_Table_Abstract
{
public function getLicenses()
{
$statementString = " ";
$statementString .= " SELECT ";
$statementString .= " tbllicenses.*, ";
$statementString .= " tblclients.email As clientemail ";
$statementString .= " FROM tbllicenses ";
$statementString .= " INNER JOIN tblclients ON tblclients.id = tbllicenses.clientid ";
$statementQuery = $this->_db->prepare($statementString);
$statementQuery->execute();
$rowsetData = $statementQuery->fetchAll();
return $rowsetData;
}
}

Best approach to add a case in a column for nhibernate

What is it the best way to add this query as projection in an nhibernate?
CASE
WHEN account.firstname = '' AND account.lastname = ''
THEN email.EmailAddress
ELSE account.firstname + ' ' + account.lastname
END
Should be something like this:
var accounts = session.QueryOver<Account>()
.Select(Projections.Conditional(Restrictions.And(
Restrictions.Eq("firstname", ""),
Restrictions.Eq("lastname", "")),
Projections.Concat(p.LastName, ", ", p.FirstName),
Projections.Property(t => t.EmailAddress)))
.List();

Postgresql lowercase to compare data

I want to get the contents from a row in the Postgresql database and compare the lowercase version of it to a lowercase version of a user input to check if it exists in the database.
i tried:
"SELECT LOWER(name) FROM user_names WHERE name LIKE '%$search%' ORDER BY name ASC"
but that make query not working at all.
EDIT
I am trying to implement an autocomplete Jquery UI like here:
http://jqueryui.com/demos/autocomplete/#remote
for search box (for names)
using javascript and php.
php code:
$search = ($_GET['term']);
if (!$con)
{ die('Could not connect: ' . pg_last_error ());}
else
{
$sql = "SELECT name FROM users_table WHERE name LIKE '%$search%' ORDER BY name ASC";
$result = pg_query($sql);
$json = '[';
$first = true;
while ($row = pg_fetch_array($result))
{
if (!$first) { $json .= ','; } else { $first = false; }
$json .= '{"value":"'.$row['name'].'"}';
}
$json .= ']';
echo $json;
exit();
}
JavaScript code:
$(document).ready(function()
{
$('#auto').autocomplete(
{
source: "./file.php",
minLength: 3
})
})
all above work great.. exactly like in Demo here: http://jqueryui.com/demos/autocomplete/#remote
my problem is that the names in database stored in Uppercase (e.g. LORI)
and of course the user prefers to insert a lowercase in search box to search for name (e.g. lori). but since it stored in uppercase, i need to convert it.
i tried as your suggestion :
$sql = "SELECT LOWER(name) FROM users_table WHERE name ILIKE '%$search%' ORDER BY name ASC";
then i got an empty drop down list!
pretty weird!
thanks in advance.
Google is your friend:
SELECT LOWER(name) FROM user_names
WHERE name ILIKE '%$search%' ORDER BY name ASC

need help Displaying more than 1 response from FQL query is_app_user Or Similar solutions

I am currently trying to get a list of friends who have added the same app via the FQL query.
I am actually doing this for a school project, and apparently, the server where this is going to be saved is not supported via PHP.That is why i am using the JavaScript SDK to code this.
This is actually the first time that I am doing a project in Facebook and everything is extremely new to me and having the graph api is not helping with me with any old documentations at all since many things have been changed and documentation is very scarce >.<.
Currently, I am having problems displaying multiple results (i am only able to do so if i hard code the response)
I've tried using a for loop to print the result but to no avail.
FB.api('/me', function(response) {
showLoader(false);
var query = FB.Data.query('SELECT uid, name, pic_square FROM user WHERE uid
IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user');
query.wait(function(rows) {
for(var i = 0; i< rows.length;i++)
{
document.getElementById('debug').innerHTML =
''+ rows[i].name +"<br />" + "<img src=\""+ rows[i].pic_square +"\" /><br />";
}
});
});
am i doing this wrong in any way? >.<. Any help would be reallllly great!!
Thanks!
Maybe it is the fact that you are stepping over what you are placing in the debug div. Try
document.getElementById('debug').innerHTML +=
Also, you do not have to have a for loop. You can have facebook do it for you by using their forEach function.
To get multiple results returned, I do this:
var linkquery = FB.Data.query('select owner, owner_comment, url from link where owner={0}', response.id);
FB.Data.waitOn([linkquery], function() {
FB.Array.forEach(linkquery.value, function(row) {
document.getElementById('debug').innerHTML += 'FQL Information: '+ "<br />" +
'Your name: ' + row.owner + "<br />" +
'Your comment: ' + row.owner_comment + "<br />" +
'Your link: ' + "<a href='" + row.url + "'>" + row.url + "</a><br /><br />";
});
});
The FB.Array.forEach gets each row.owner and they are being added to the debug div -
document.getElementById('debug').innerHTML +=
with each row that is returned.
Hope that helps