[英]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. 我想创建一个包含布尔值的列,我不想使用
TINYINT(0)
并为false存储0,为true存储1,相反,我想存储“ true”或“ false”值但不作为VARCHAR
值。
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 : 我这样做是因为我正在使用Extjs,并且正在动态创建组合框,因此需要这些布尔值用作参数,例如:
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). 并且editable将是“ true”或“ false”(不带引号)。
Should I just use a varchar
column and remove the quotes in Extjs? 我应该只使用
varchar
列并删除Extjs中的引号吗? Is there a better way? 有没有更好的办法?
您可以使用ENUM('true','false')作为列数据类型。
使用int并将其转换为布尔值(但可能并非真正需要):
var boolValue = !!intValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.