Home Documents How To

How To

Use Map to get default value or field type 

<$

var type_defaultvalue={

     'int':'0',

     'tinyint':'false',

     'varchar':'""',

     'datetime':'new Date()',

}; 

 

for (var i=0; i<sys_fields.length; i++) {

     var type = sys_fields[i].type; 

     if(undef(type_defaultvalue[type])){

         println("Undefined default value for field type: '"+ type+"'");

     }

 

     println(sys_table_name+".set"+formatFieldName(sys_fields[i].name)+"("+type_defaultvalue[type] + ");");

$>

     <%=sys_table_name%>.set<%=formatFieldName(sys_fields[i].name)%>(<%=type_defaultvalue[type] %>);

<$

}

$>

Last Updated on Monday, 26 January 2009 09:00