Mysql store boolean that reads to true or false - mysql

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;

Related

Spring JPA Mysql json_set boolean saving as 1/0

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)")

Enable only createdAt time stamp and ignore updatedAt timestamp in Sequelize

I am trying to create some records into table with only the createdAt column filled. I want the updatedAt column to not exist how ever when i create a model it automatically generates the createdAt and updatedAt timestamps.
I tried to use timestamps : false but the createdAt column contains empty values.
const MyTable = sequelize.define(
'my_table',
{
id: {
type: DataTypes.INTEGER(11),allowNull: false,
primaryKey: true,autoIncrement: true,
},
person_name: {type: DataTypes.STRING(255),allowNull: false},
created: {type: DataTypes.DATE,allowNull: true},
},
{
tableName: 'my_table',
timestamps: false,
createdAt: 'created',
},
);
Is it possible to fix this issue in the model itself without doing any change in the query ?
According to the documentation on Init, you'll wanna leave the timestamps feature turned on, but configure your model to not use updatedAt.
Here's an edited version of the options object in your sample code that should give you what you are looking for:
{
tableName: 'my_table',
updatedAt: false,
}
NB: The docs say "Timestamps must be true", which might indicate why it wasn't working the way it is in the sample you provided.
Cheers!

ExtJS: How do I load a ComboBox with the value in another ComboBox?

I'm a bit of an ExtJS noob. I have a loaded up an ExtJS ComboBox (call it CBa) where the value field contains a JSON string that, when selected, should be loaded into a second combobox (CBb).
All of the examples I can find tell me how to load up a ComboBox from an external URL, but in this case, I want to load it up from a string I already have locally.
What magic do I place on each ComboBox to make this happen?
You can create a local combo like so :
// The data store containing the list of states
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data : [
{"abbr":"AL", "name":"Alabama"},
{"abbr":"AK", "name":"Alaska"},
{"abbr":"AZ", "name":"Arizona"}
//...
]
});
var combo2 = Ext.create('Ext.form.ComboBox',{
// combo config;
});
// Create the combo box, attached to the states data store
Ext.create('Ext.form.ComboBox', {
fieldLabel: 'Choose State',
store: states,
queryMode: 'local', //makes it a local combo. Don't need a url.
displayField: 'name',
valueField: 'abbr',
renderTo: Ext.getBody(),
listeners : {
select : function() {
var value = this.getValue();
combo2.setValue(value);
}
}
});
Use the select event of combo to set the selected value into the second combo. Note that the selected value should be a value present in the data which is defined in the store of combo2 for it to be set. Read docs of setValue here for exact information.
EDIT after reading comment:
You can set the second combo's store dynamically. Change the select event mentioned above to this:
select : function()
{
var dataArray = [],data = this.getValue(); //Json string
dataArray.push(Ext.decode(data)); //In case there is only one object in the string instead of any array.
combo2.getStore().loadData(dataArray, false); //dataArray is automatically parsed into Model Objects. Second param to allow append to existing store data.
}
}

Filtering a comboxes remote store locally in ExtJs

I have an ExtJs combobox. Its store loaded using JSON (using MyStore class below). I want to load all the values to the store, and then filter them with the text entered in the combo's textfield (preferably using the typeAhead feature).
The problem is that I want to do the filtering on the client side (combo's mode property is 'remote', by default). I don't want my combo to reload its store every time I type something.
How can I do that?
Thanks.
Here's my store class :
MyStore = Ext.extend(Ext.data.JsonStore, {
constructor: function(jsonUrl, storeId, id, description, isAutoLoad, cfg) {
cfg = cfg || {};
GenericStore.superclass.constructor.call(this, Ext.apply({
storeId: storeId,
root: 'result',
url: jsonUrl,
autoLoad: isAutoLoad,
fields: [
{
name: id
},
{
name: description
}
]
}, cfg));
}
});
And the combo :
xtype: 'combo',
fieldLabel: 'The Combo',
width: 150,
store: myStoreData,
valueField: 'id',
displayField: 'name',
minChars : 0,
editable : false,
itemId : 'my-combo'
To achieve this you must:
Construct MyStore class with "isAutoLoad" config option as "true"
In your combobox config set the "mode" config option to "local" (see Built the combo config code bellow for another config)
Here is my short example:
Construct myStoreData variable
var myStoreData = new MyStore({
autoLoad: true, //so the store will load automatically
...any_other_config_option...
});
Built the combo config
{
xtype: 'combo',
fieldLabel: 'The Combo',
width: 150,
store: myStoreData,
// myStoreData is already loaded before as it have 'autoLoad' config set to true
// and act as localstore to populate the combo box item
// when the combo "mode" config set to 'local'
valueField: 'id',
displayField: 'name',
minChars : 0,
editable : true, //before was editable : false,
itemId : 'my-combo',
mode: 'local', // by default this was mode: 'remote'
typeAhead: true // by default this was typeAhead: false
}
You will want to use the store.filter() method. You can use this to use user-entered information to filter your store that the combo box uses. This is taken from the ExtJS API documentation for data.store.
store.filter([
{
property : 'name',
value : 'Ed',
anyMatch : true, //optional, defaults to true
caseSensitive: true //optional, defaults to true
},
//filter functions can also be passed
{
fn : function(record) {
return record.get('age') == 24
},
scope: this
}
]);
In my case I had to add the config option lastQuery:'' to the combo.
explanation : http://progex.wordpress.com/2010/03/26/extjs-combo-dropdown-does-not-filter-on-first-trigger/
Add listener to your store on 'load' event, do filtering, by removing or flagging records, if removing it is clear load to combo component, if flagging you need to recognize those flaggs in combo and display or not...
It hard to go with more details if I do not see your code for store and combo, so I can give you only general idea

JSON dot notation in jQgrid?

I am using addRowData method to populate my grid. But my current JSON data have another object inside of each object in the JSON data. To make it view in the grid, i followed the notations in the documentation of jQgrid. But that column remain empty.
My Grid definition:
$("#ExpenseTable").jqGrid({
datatype : "local",
mtype : 'GET',
colNames : [ 'Entry ID','User Name', 'Category Name','Date','Amount','Status'],
colModel : [
{name:'expnsId',label:'ID', width:150 ,editable: false},
{name:'userName',label:'NAME', width:150 ,editable: false},
{name:'category.catName',label:'CATEGORY', width:150 ,editable: false},
{name:'date',label:'DATE', width:150 ,editable: false},
{name:'amount',label:'AMOUNT', width:150 ,editable: false},
{name:'status',label:'STATUS', width:150 ,editable: false},
],
pager : '#ExpPager',
rowNum : 10,
rowList : [ 10, 20, 30 ],
sortname : 'invid',
sortorder : 'desc',
viewrecords : true,
autowidth : false,
caption : 'Expenses Details',
onSelectRow : function(expnsId) { dispExpensData(expnsId); }
});
Code used to populate the Grid:
ExpenseDetailsManagement.getexpenseList(function(expRecords){
//for(count = 0; count<expRecords.length; count++){
// expRecords[count].catId = expRecords[count].category.catId;
// expRecords[count].catName = expRecords[count].category.catName;
//}//I am using this for loop to convert the category object
$("#ExpenseTable").clearGridData(true);
$("#ExpenseTable").jqGrid('addRowData', "expnsId", expRecords);
});
The data returned from the server looks like:
Any idea or suggestions about where i am going wrong!!!
If the values from the 'expnsId' column are unique, I'll recommend you to use key:true parameter as a option of 'expnsId' coulmn. Then the value of the column will be used as the row id.
To be able to help you with the dotted column names you should post the JSON data and not the screenshort with "Object" text on the place of the most important information. Probably your main problem can be easy solved with respect of localReader instead of dotted name.
One more small remark. Beause you use label option for all columns you can remove colNames array which will be not used. The option editable: false is default, so you can remove it also. The parameter mtype you can also remove because it will not used for local data.
UPDATED: Sorry the value of the first parameter of addRowData should be do the name of the column with the data like you as do. So I deleted the first paragraph from the first version of my answer.