tailieunhanh - Web to py enterprise web framework - p 20

OTHER OPERATORS 175 Other Operators web2py has other operators that provide an API to access equivalent SQL operators. Let’s define another table "log" to store security events, their timestamp and severity, where the severity is an integer number. 1 2 3 ('log', Field('event'), Field('timestamp', 'datetime'), Field('severity', 'integer')) As before, insert a few events, a "port scan", an "xss injection" and an "unauthorized login". For the sake of the example, you can log events with the same timestamp but with different severities (1, 2, 3 respectively). 1 2 3 4 5 1 import datetime now = () print (event='port scan', timestamp=now, severity=1) print (event='xss injection',. | OTHER OPERATORS 175 Other Operators 1 2 3 1 2 3 4 5 6 7 8 1 2 3 1 2 3 web2py has other operators that provide an API to access equivalent SQL operators. Let s define another table log to store security events their timestamp and severity where the severity is an integer number. log Field event Field timestamp datetime Field severity integer As before insert a few events a port scan an xss injection and an unauthorized login . For the sake of the example you can log events with the same timestamp but with different severities 1 2 3 respectively . import datetime now print event port scan timestamp now severity 1 1 print event xss injection timestamp now severity 2 2 print event unauthorized login timestamp now severity 3 3 like upper lower Fields have a like operator that you can use to match strings for row in db port .select print port scan Here port indicates a string starting with port . The percent sign character is a wild-card character that means any sequence of characters . Similarly you can use upper and lower methods to convert the value of the field to upper or lower case and you can also combine them with the like operator. for row in db .like PORT .select print port scan year month day hour minutes seconds The date and datetime fields have day month and year methods. The datetime and time fields have hour minutes and seconds methods. Here is an example 176 THE DATABASE ABSTRACTION LAYER 1 2 3 4 5 1 2 3 4 1 2 3 4 5 6 1 2 3 for row in db 2009 .select print port scan xss inj ection unauthorized login belongs The SQL IN operator is realized via the belongs method which returns true when the field value belongs to the specified set list of tuples for row in db 1 2 .select print port scan xss injection The DAL also allows a nested select as the argument .

TỪ KHÓA LIÊN QUAN