在测试(非 web2py)程序中,我正在使用调用 SELECT SUBSTRING_INDEX 的 MySQL 查询。在 web2py 的 DAL 规范中将其转换为正确用法的最简单方法是什么?
查询如下:
http://pastie.textmate.org/3848916
SELECT SUBSTRING_INDEX( ipaddress, '.', 3 ) AS first_three_octet, count( * ) AS ipCount, updated
FROM ips
GROUP BY SUBSTRING_INDEX( ipaddress, '.', 3 )
HAVING ipCount = 254
ORDER BY ipCount DESC
仅供参考 - 我同时将这段代码拼凑在一起以完成我需要的事情:
def ListFullRanges():
import re
f3o = '(\d{1,3}\.\d{1,3}\.\d{1,3})'
fullrange = []
rg1 = re.compile(f3o,re.IGNORECASE|re.DOTALL)
for row in db(db.ips).select():
m = rg1.findall(row.ipaddress)
if not m[0] in fullrange:
if db(db.ips.ipaddress.startswith(m[0])).count() == 254:
fullrange.append(m[0])
print fullrange
return dict(fr=fullrange)