Database Reference
In-Depth Information
In Python, to fetch the cow accessory information and present it using checkboxes or
a scrolling list, do this:
acc_info = get_enumorset_info ( conn , 'cookbook' , 'cow_order' , 'accessories' )
if acc_info [ 'default' ] is None :
acc_def = ""
else :
acc_def = acc_info [ 'default' ] . split ( ',' )
print ( make_checkbox_group ( 'accessories' ,
acc_info [ 'values' ],
acc_info [ 'values' ],
acc_def ,
True )) # display items vertically
print ( make_scrolling_list ( 'accessories' ,
acc_info [ 'values' ],
acc_info [ 'values' ],
acc_def ,
3 , # display 3 items at a time
True )) # create multiple-pick list
In JSP pages, the getEnumOrSetValues() function used earlier to get the value list for
the size column (an ENUM ) can also be used for the accessory column (a SET ). The
column definition and default value can be obtained from INFORMATION_SCHEMA . Query
the COLUMNS table, parse the type definition into a list of values named values , and put
the default value in defList like this:
<sql:query dataSource= "${conn}" var= "rs" >
SELECT COLUMN_TYPE, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'cookbook'
AND TABLE_NAME = 'cow_order'
AND COLUMN_NAME = 'accessories'
</sql:query>
<c:set var= "typeDef" scope= "page" value= "${rs.rowsByIndex[0][0]}" />
<% getEnumOrSetValues ( pageContext , "typeDef" , "values" ); %>
<c:set var= "defList" scope= "page" value= "${rs.rowsByIndex[0][1]}" />
For a SET column, the defList value might contain multiple values, separated by com‐
mas. It needs no special treatment; the JSTL <c:forEach> tag can iterate over such a
string, so initialize the default values for a checkbox set as follows:
<c:forEach items= "${values}" var= "val" >
<input type= "checkbox" name= "accessories"
value= "<c:out value=" ${val}" /> "
<c:forEach items= "${defList}" var= "defaultVal" >
<c:if test= "${val == defaultVal}" > checked="checked" </c:if>
</c:forEach>
/> <c:out value= "${val}" /><br />
</c:forEach>
Search WWH ::




Custom Search