Currently we have a table with a column in json datatype. That stores
{
"newTicketLowInd": false,
"newTicketHighInd": false,
"newTicketMediumInd": false,
"newTicketUrgentInd": false,
"becomeTicketOwnerInd": false
}
and I wanted to add a new element with default value of true. Thus
#Modifying
#Query("update UserSettings u set u.jsonCol = json_set(u.jsonCol , '$.newElement', :indicator)")
void bulkUpdateTicketConversationUpdateMyselfInd(#Param("indicator") boolean indicator);
Or in MySQL
update UserSettings u set u.jsonCol = json_set(u.jsonCol , '$.newElement', true)
But it is storing boolean value as 1/0.
{
"newTicketLowInd": false,
"newTicketHighInd": false,
"newTicketMediumInd": false,
"newTicketUrgentInd": false,
"becomeTicketOwnerInd": false,
"newElement": 1
}
How can I store it as true or false? the same as the current elements stored.
I just used nativeQuery in jpa
#Query(nativeQuery = true, value = "update user u set u.email_notification_settings = json_set(u.email_notification_settings, '$.ticketConversationUpdateMyselfInd', true)")
Related
In SailsJS, I created a model Profiles including a custom primary key as follows:
module.exports = {
tableName: 'tbl_profiles',
autoPK: false,
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
user_id: {
type: 'integer',
size: 11,
columnName: 'user_id',
unique: true,
primaryKey: true,
},
...
Now, when calling the blueprint route to update a user profile, I get the following error:
ER_BAD_FIELD_ERROR: Unknown column 'tbl_profiles.id' in 'where clause'
Debugging this down (and seeing question SailsJS and mySQL custom ID name not working with blue prints not helping) I found out that the update is carried through all right in the db and that the record is changed but in the controller callback function an error and status 400 is raised nevertheless:
Profiles.update({user_id: req.param('id')}, req.body).exec(function(err, profile) {
if (err) {
return res.status(400).json(err);
} else {
return res.status(200).json(profile);
}
});
Tracing down the SQL involved in /node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14, it seems the following statement is executed just after the update is finished (note the final WHERE clause):
SELECT `tbl_profiles`.`user_id`,
`tbl_profiles`.`lastName`,
`tbl_profiles`.`firstName`,
`tbl_profiles`.`date_of_birth`,
`tbl_profiles`.`address_line1`,
`tbl_profiles`.`address_line2`,
`tbl_profiles`.`zip_code`,
`tbl_profiles`.`city`,
`tbl_profiles`.`gender`,
`tbl_profiles`.`country_id`,
`tbl_profiles`.`phone`,
`tbl_profiles`.`user_id`
FROM `tbl_profiles` AS `tbl_profiles`
WHERE `tbl_profiles`.`id` = undefined
Where could I set SailsJS/Waterline to use the custom column ID? Setting autoPK true either in the beginning or the end of the model wouldn't do the trick..
I have this weird problem. I have a User domain class in a Grails app. The class is as follows:
class User {
transient springSecurityService
String username
String name
String password
String email
String company
Date activationDate
String contactPhone
boolean enabled
boolean passwordExpired = false
boolean accountExpired
boolean accountLocked
boolean isDeleted=false
boolean isPrimary
String jobTitle
String jobFunction
String deskPhone
String mobile
String profilePicURL
boolean isLinkExpired=false
UserType userType
Date dateCreated
Date lastUpdated
static constraints = {
password nullable: true
company nullable: true
email blank: false, unique: true
name nullable: true
activationDate nullable:true
username nullable: true
enabled nullable: false
isDeleted nullable: false
passwordExpired nullable: false
jobFunction nullable:true
jobTitle nullable:true
contactPhone nullable:true
mobile nullable:true
profilePicURL nullable:true
deskPhone nullable:true
userType nullable:true
}
static auditable = true
static mapping = {
password column: '`password`'
tablePerHierarchy false
cache true
}
Set<Role> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
And there is a method activeDeactiveUser which enables/disables user authorization for some functionality as follows:
def activeDeactiveUser(String username) {
def user = User.findByUsername(username)
if (user.enabled == false)
user.enabled = true
else
user.enabled = false
if (user.validate()) {
user.save(flush: true, failOnError: true)
} else {
user.errors.allErrors.each {
print it
}
}
def userJson = new JSONObject()
userJson.put("isEnabled", user.enabled)
return userJson
}
When the app is running on localhost, the table is updating fine. But when the same code is running on server, the table fails to update. I don't know why it's behaving like this.
The app isn't raising any exception on the save method on localhost. May be the problem is with different versions of mysql on my machine and the server. Is there any the to debug the app while it is running on the server?
The app is hosted in an AWS EC2 instance running Ubuntu 14.04 and Grails version 2.4.3. The database is stored in an AWS RDS instance running mysql 5.5.40.
there are many reasons for it - I think you need to provide more information for yourself and in this thread so we can help.
I suggest, first add log information by one of the options:
you can add logSql to dataSource file:
dataSource {
logSql = true
}
to produce far more readable SQL commands than simply logSql would do add the following properties in DataSource.groovy:
hibernate {
format_sql = true
use_sql_comments = true
}
Then, add the following log4j settings to Config.groovy:
log4j = {
debug 'org.hibernate.SQL'
trace 'org.hibernate.type'
}
The first setting logs the SQL commands, the second one logs the bound parameters and the bindings of the result set.
the issue can also be related to schema update - so maybe your local DB schema is not in sync with server one. you ned to check field type and constraints.
Is this code:
IIF(Fields!XXX.Value = "0" OR ISNOTHING(Fields!XXX.Value), TRUE, FALSE)
The same as:
IIF(Fields!XXX.Value = "0", TRUE, IIF(ISNOTHING(Fields!XXX.Value), TRUE, FALSE))
Will the first method work or only the second method for SSRS?
Both are equivalent and will work
I need the MySQL column type for the String field in my Domain class to be TEXT or VARCHAR(3000), but nothing I try seems to work - it remains VARCHAR(255). I've tried
static mapping = {
longString type: 'text'
}
and
static mapping = {
longString sqlType: 'text'
}
and
static constraints = {
longString (blank: true, nullable: true, maxSize: 3000)
}
and
static constraints = {
longString (blank: true, nullable: true, size: 0..65535)
}
MySQL Server version 5.0.95, Grails 2.4.3.
I'm totally mystified and would appreciate any help..
You need to define the type of the column in the mapping block rather than constraints. Assuming the name of the property is longString, add this
static mapping = {
longString type: 'text'
}
This will create a column with a MySQL type of longtext.
To verify that this works, try dropping your database, create a new (empty) database, restart the app and check the type of the column that is created. See this example for reference.
I'd like to create a column which will contain boolean values, I don't want to use TINYINT(0) and store 0 for false and 1 for true, instead i'd like to store "true" or "false" values but not as VARCHAR values.
I'm doing this because I'm using Extjs, and I'm dynamically creating comboboxes, I need those boolean values to use as parameters like so :
function createComboBox(editable) {
var combo = new Ext.form.ComboBox({
typeAhead: true,
mode: 'local',
forceSelection: true,
triggerAction: 'all',
emptyText: 'Select item...',
selectOnFocus: true,
//...other settings
editable: editable // true or false
});
return combo;
};
And editable would be "true" or "false" (without quotes).
Should I just use a varchar column and remove the quotes in Extjs? Is there a better way?
You could use ENUM('true', 'false') as the column data type.
Use an int and cast it to a boolean (but it is probably not really needed):
var boolValue = !!intValue;