简体   繁体   中英

Mysql store boolean that reads to true or false

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?

您可以使用ENUM('true','false')作为列数据类型。

使用int并将其转换为布尔值(但可能并非真正需要):

var boolValue = !!intValue;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM