is it a bug?
when I use mybatis and mysql, a column name id permission_ids, I got null always.
but when I change it to permissions, it worked. Why?
SELECT
sys_role.id,
sys_role.role,
sys_role.description,
sys_role.permission_ids
FROM sys_role
WHERE id = #{id}
If you're using XML file:
you should have:
<select id="selectQuery" resultMap="selectMap">
SELECT
sys_role.id,
sys_role.role,
sys_role.description,
sys_role.permission_ids
FROM sys_role
WHERE id = #{id}
</select>
<resultMap id="selectMap" type="SysRole">
<id column="permission_ids" property="permissionIds">
<result ....//the rest columns to map to java properties in your model class "SysRole"
</resultMap>
That should work !
If not, as an alternative to your solution, you can use Alias instead of renaming the column "permission_ids":
SELECT
sys_role.id,
sys_role.role,
sys_role.description,
sys_role.permission_ids **as permissions**
FROM sys_role
WHERE id = #{id}
Related
I have an issue in finding the correct records from the database. This is my query:
#interested_individual = Profile.where('category_id = ?', #event.interests).all
Where category_id is the column in the profiles table what holds the integer value and #event.interests returns an array that is ["1", "2", "3"]
What I want here is to fetch all the profiles where its category_id is present in the #event.interests array.
Please let me know the solution. Thanks in advance
You don't really need to manually write the binding with ? and all.
Try this:
#interested_individual = Profile.where(category_id: #event.interests).all
Active Record will then turn that into category_id IN (?) for you if you pass in an array.
This query will translate to category_id IN [interest_ids...]
Profile.where(category_id: #event.interests).all
You were close. Use IN.
#interested_individual = Profile.where('category_id IN (?)', #event.interests).all
But, I would suggest find you here, if you are only wanted to get collection of all Profile records :
#interested_individual = Profile.find(#event.interests)
I want to query string from a field from my database. For example: Field "Address", value "Toul Kork District, Phnom Penh". Want I want to get is only "Phnom Penh". I know that my sql is not allow to select only this string from the field. So, what is the good way to do that?
This may help you :
SELECT SUBSTR(Address,
LOCATE(Value,Address),
LENGTH(Address) - LENGTH(Value));
POSITION function is synonim for LOCATE. You can use POSITION function as well :
SELECT SUBSTR(Address,
LOCATE(Value IN Address),
LENGTH(Address) - LENGTH(Value));
In static variable it's looks like :
SELECT SUBSTR('Toul Kork District,Phnom Penh',
LOCATE('Phnom Penh','Toul Kork District,Phnom Penh'),
LENGTH('Toul Kork District,Phnom Penh') - LENGTH('Phnom Penh'));
Result : Phnom Penh
Exple :
I have a result like this
Result1 AFTER EMIT:
Key-------------------------------value
"2014/10/31" ----------------- {"A":a}
"2014/10/31" ----------------- {"B":b}
"2014/10/31"----------------- {"C":c}
"2014/10/31"----------------- {"D":d}
How can I output this new result from the previous one:
Key-------------------------value
"2014/10/31" -----------------{"Array":["A":a, "B":b, "C":c, "D":d]}
Is there a way? Any help will be appreciated. Thanks
You can use Couchbase v3 new N1QL query language for that. Also there is Query Language Tutorial. Specifically Array Comprehensions syntax.
I found it . Just do : group = true in the path or select it from the filter result .
and a reduce function to return all the values from the map. also you can add the start key = "2014/10/31" and end key= "2014/10/31".
I would like to change the availability of an item in a database.
<td><select name="avl">
<option value="1" name="true ">Available</option>
<option value="0" name="false">Unavailable</option>
</select>
</td>
Here is my sql statement to update the field.
<sql:update dataSource="${dbsource}" var="count">
UPDATE restaurant SET available = ? WHERE idrestaurant ='${param.id}'
<sql:param value="${param.avl}" />
</sql:update>
my datatype for the FIELD available is BIT.
But I get this error.
WARNING: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'available' at row 1
I'm using BIT in MySQL the same way you are. I understand this is a bit different from your situation but hopefully it will help.
I have a column:
NAME:PUBLISHED | DATATYPE:BIT
that gets toggled via a button on a page.
<li sec:authorize="hasRole('ROLE_ADMIN')">
<a th:href="#{'/administration/'+*{postId} + '/publish'}" th:text="*{postMetaData.published} ? 'unpublish' : 'publish'">publish</a>
</li>
The controller mapped above is calls the following method in the service:
public boolean togglePublishPost(int postId){
Post post = postRepo.findOne(postId);
if(post.isPublished()){
post.setPublished(false);
}else{
post.setPublished(true);
post.setPublishDate(new Date());
}
postRepo.save(post);
return post.isPublished();
}
Like I said, it's different but it looks like we are kinda trying to achieve the same thing. So, I guess in short, a BIT can be updated with true and false.
I have an html drop down with some values like :
This one is inside form :
<b>Priority</b><select><name = "priority" id="priority"><option>Low</option><option>Medium </option><option>High</option></select>
Now when I click submit, What the value I select should be inserted to db. For that iadded like :
$priority = $_POST['priority'];
$sql3= "INSERT INTO work (priority) VALUES ('$priority')";
But it throw error : unknown identifier.
So how can I get the value from the select and insert into db. Pleasehelp
Change:
<select><name = "priority" id="priority">
to:
<select name="priority" id="priority">