2014-03-04 59 views
0

我想要创建一个包含布尔值的列,我不想使用TINYINT(0)并将0存储为false,将1存储为true,而是想要存储“真”或“假”值,但不是VARCHAR值。读取为true或false的Mysql存储布尔值

因为我使用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; 
}; 

和可编辑的将是“真”或“假”(不含引号)。

我应该只使用varchar列并删除Extjs中的引号?有没有更好的办法?

+0

我的事'MySQL'还没有一个'boolean'数据类型:HTTP://dev.mysql。 com/doc/refman/5.0/en/numeric-type-overview.html –

+0

这是一个很好的答案:http://stackoverflow.com/questions/289727/which-mysql-datatype-to-use-for-storing-布尔值 – Jehy

回答

0

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

0

使用int和它转换为一个boolean(但它可能不是真正需要的):

var boolValue = !!intValue; 
相关问题