Mybatis to return a string not List of String - ibatis

I have a straight forward query like,
Select emp_Name from Employee where empID=123
How can i get the return as only String instead of List<String>, as here this query will return only one value.

Change return type of method in your mapper interface to String. This will return only value or null if there is no entry.

Related

Database.getQueryLocator return wrong data

I am very puzzled on the result returned by the Database.getQueryLocator().
global Database.QueryLocator start(Database.BatchableContext BC) {
string query = 'Select Label, Batch_Name__c, SObject_Name__c, External_system__c from Batch_Upload_Config__mdt where Is_Active__c = true';
System.debug(query);
return Database.getQueryLocator(query);
}
In the Query Editor, I entered the exact query and did get the correct data back. However when running the batch, instead of returning the records with 'Is_Active__c = true', it returns the records with 'Is_Active__c = false'.
Any pointers will be appreciated.
Looks like this is related to query on custom metadata types. When I changed to use custom object, I was able to get the correct result using Database.getQueryLocator().

Get the comma separated list from an array

I have a function which has a return type of IList<Product>
class Product
{
int Id,
string ProductClass,
string ProductName
}
I have to make a comma separated string of ProductName. I am trying below code but it is not giving me correct result
Array arrayofProduct = MyFunction().ToArray();
string productNames = string.Join(",", arrayofProduct);
I think it is because arrayofProduct has 3 columns and I have to pass only 1 (i.e. ProductName) to get the comma separated list.
Use Linq to Select the ProductName into a collection and then use that to construct the desired comma separated string
var names = MyFunction().Select(p => p.ProductName);
string productNames = string.Join(",", names);
Or apart from the above answer you can directly query your array of product and get the result.
string productNames = string.Join(",", arrayofProduct.Select(x => x.ProductName);

How to concatenate the elements of int array to string in Hive

I'm trying to concatenate the element of int array to one string in hive.
The function concat_ws works only for string arrays, so I tried cast(my_int_array as string) but it's not working.
Any suggestion?
Try to transform using /bin/cat:
from mytable select transform(my_int_array) using '/bin/cat' as (my_int_array);
Second option is to alter table and replace delimiters:
1) ALTER TABLE mytable CHANGE COLUMN my_int_array = my_int_array_string string;
2) SELECT REPLACE(my_int_array_string, '\002', ', ') FROM mytable;
It seems that the easiest way is to write a custom UDF to perform this specific task:
public class ConcatIntArray extends UDF {
public String evaluate(ArrayList<Integer> in, final String delimiter){
return in.stream().map(u-> String.valueOf(u)).collect(Collectors.joining(delimiter));
}
}

laravel htmlentities() expects parameter 1 to be string, array given (raw sql count)

I am having the following error: htmlentities() expects parameter 1 to be string, array given when I am executing the following sql statement in laravel.
public function index($id)
{
$event = Task::find($id);
//$tickremain = DB::select(DB::raw("SELECT artists FROM tasks where id='1'"));
$tickremain = DB::table('tasks')->select(DB::raw('count(*) as thresholdc'))->get();
return view('buy.index', ['event' => $event],['tickremain'=>$tickremain]);
}
My view:
<p>No. of Tickets remaining: {{$tickremain}}</p>
I want to get a count of a column field but I'm left with that error.
Use {{$tickremain->thresholdc}} to print the count.
You are getting this array because $tickremain is an array. htmlentities() format is
string htmlentities ( string $string ).
So just try to print $tickremain and check whether it is array or not. If it is array just access like
$tickremain['thresholdc']
(based on array)

Variable in filter query in Jaydata

I have a string which I need to pass in filter query of Jaydata.Kindly guide..
Here is my following code:
var string = ((id=4 || id>6)&& (Name contains 'a'));
mydb.Document.filter(function(result){
return result.str;
}).toArray(function(abc){
console.log(abc);
});
Here mydb is sQlite db instance name and Document is table name.
Error comes when I use result.str as str is not the field name of the table.
How can I do this.
your filter is not correct, also you can pass parameter with referring the second parameter, like this
mydb.Document.filter(function(result){
return result.str == this.foo;
}, { foo: 'bar'}).toArray(function(abc){
of course, instead of 'bar' you can pass any value

Resources