本文整理汇总了Python中sqlalchemy.sql._sql函数的典型用法代码示例。如果您正苦于以下问题:Python _sql函数的具体用法?Python _sql怎么用?Python _sql使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_sql函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _unlock_many
def _unlock_many():
tickets = []
with self.db_engine.begin() as conn:
cur = conn.execute(_sql('select * from slc_rad_online where nas_addr = :nas_addr'),nas_addr=nas_addr)
for online in cur:
conn.execute(bsql,**_ticket(online))
conn.execute(_sql('delete from slc_rad_online where nas_addr = :nas_addr'),nas_addr=nas_addr)
示例2: set
def set(self, key, value, expire=0):
raw_data = self.encode_data(value)
with self.dbengine.begin() as conn:
_time = expire>0 and (int(time.time()) + int(expire)) or 0
try:
conn.execute(_sql("insert into %s values (:key, :value, :time) " % self.cache_table),
key=key,value=raw_data,time=_time)
except:
conn.execute(_sql("delete from %s where _key = :key " % self.cache_table),key=key)
conn.execute(_sql("insert into %s values (:key, :value, :time) " % self.cache_table),
key=key,value=raw_data,time=_time)
示例3: _raw_set
def _raw_set(self, key, value, timeout,**kwargs):
with self.dbengine.begin() as conn:
_time = int(time.time()) + int(timeout)
try:
conn.execute(_sql("insert into system_session values (:key, :value, :time) "),
key=key,value=value,time=_time)
except:
conn.execute(_sql("""update system_session
set _value=:value, _time=:time
where _key=:key"""),
key=key,value=value,time=_time)
示例4: _unlock_one
def _unlock_one():
ticket = None
with self.db_engine.begin() as conn:
sql = _sql('select * from slc_rad_online where nas_addr = :nas_addr and acct_session_id = :session_id')
cur = conn.execute(sql,nas_addr=nas_addr,session_id=acct_session_id)
online = cur.fetchone()
if online:
ticket = _ticket(online)
dsql = _sql('delete from slc_rad_online where nas_addr = :nas_addr and acct_session_id = :session_id')
conn.execute(dsql,nas_addr=nas_addr,session_id=acct_session_id)
conn.execute(bsql,**ticket)
示例5: _delete
def _delete(self, key):
with self.dbengine.begin() as conn:
try:
conn.execute(_sql("delete from system_session where _key = :key "),key=key)
except:
import traceback
traceback.print_exc()
示例6: get
def get(self, key):
self.get_total += 1
raw_data = None
_del_func = self.delete
with self.dbengine.begin() as conn:
try:
cur = conn.execute(_sql("select _value, _time from %s where _key = :key " % self.cache_table), key=key)
_cache = cur.fetchone()
if _cache:
self.hit_total += 1
_time = int(_cache["_time"])
if _time > 0 and time.time() > _time:
reactor.callLater(0.01, _del_func, key)
else:
raw_data = _cache["_value"]
except:
import traceback
traceback.print_exc()
try:
if raw_data:
return self.decode_data(raw_data)
except:
self.delete(key)
return None
示例7: delete
def delete(self,key):
with self.dbengine.begin() as conn:
try:
conn.execute(_sql("delete from %s where _key = :key " % self.cache_table),key=key)
except:
import traceback
traceback.print_exc()
示例8: create_logtable
def create_logtable(db_engine):
create_sql_tpl = """
CREATE TABLE {0} (
id INTEGER NOT NULL PRIMARY KEY autoincrement,
host VARCHAR(32) NOT NULL,
time VARCHAR(19) NOT NULL,
facility VARCHAR(16) NOT NULL,
priority VARCHAR(16) NOT NULL,
username VARCHAR(16) NULL,
message VARCHAR(1024) NOT NULL
);
"""
mysql_create_sql_tpl = """
CREATE TABLE {0} (
id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT ,
host VARCHAR(32) NOT NULL,
time VARCHAR(19) NOT NULL,
facility VARCHAR(16) NOT NULL,
priority VARCHAR(16) NOT NULL,
username VARCHAR(16) NULL,
message VARCHAR(1024) NOT NULL
)
COMMENT='syslog table'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=1;
"""
sql_tpl = 'mysql' in db_engine.driver and mysql_create_sql_tpl or create_sql_tpl
table_name = "log_{0}".format(datetime.datetime.now().strftime("%Y%m%d%H"))
sqlstr = sql_tpl.format(table_name)
with db_engine.begin() as conn:
try:
conn.execute(_sql(sqlstr))
except:
logging.exception("create logtable error")
示例9: _raw_get
def _raw_get(self, key, **kwargs):
raw_data = None
with self.dbengine.begin() as conn:
try:
cur = conn.execute(_sql("select _value, _time from system_session where _key = :key "),key=key)
session = cur.fetchone()
if session:
_time = int(session['_time'])
if (time.time() - _time) > self.session_timeout:
conn.execute(_sql("delete from system_session where _key = :key "),key=key)
else:
raw_data = session['_value']
except:
import traceback
traceback.print_exc()
return raw_data
示例10: count
def count(self):
with self.dbengine.begin() as conn:
try:
cur = conn.execute(_sql("select count(_key) as count from %s " % self.cache_table))
return int(cur.fetchone()["count"])
except:
self.log.error("cache count error")
return 0
示例11: get_user_attr
def get_user_attr(self, username,attr_name):
with self.db_engine.begin() as conn:
cur = conn.execute(_sql("""select attr_value from slc_rad_account_attr
where account_number = :account
and attr_name = :attr_name"""),
account=username,attr_name=attr_name)
b = cur.fetchone()
return b and b['attr_value'] or None
示例12: check_expire
def check_expire(self, first_delay=0):
if first_delay > 0:
reactor.callLater(first_delay, self.check_expire)
with self.dbengine.begin() as conn:
try:
conn.execute(_sql("delete from %s where _time > 0 and _time < :time" % self.cache_table),time=int(time.time()))
except:
pass
reactor.callLater(120.0, self.check_expire)
示例13: getRadius
def getRadius(self, host):
cache_key = 'RadiusLoader.radius.%s' % (host)
cache = self.cache.get(cache_key)
if cache:
return cache
with self.dbengine.begin() as conn:
cur = conn.execute(_sql("""select * from tt_radius where ip_addr = :ip_addr """),ip_addr=host)
radius = self.warp(cur.fetchone())
self.cache.set(cache_key,radius, expire=60)
return radius
示例14: execute_sqls
def execute_sqls(config, sqlstr):
sh.info("exec sql >> %s" % sqlstr)
results = []
with get_engine(config).begin() as conn:
try:
results = conn.execute(_sql(sqlstr))
except Exception as err:
return sh.err("exec sql error: %s" % str(err))
sh.info("exec sql done")
print_result(results)
示例15: getMasterRadius
def getMasterRadius(self):
cache_key = 'RadiusLoader.master_radius'
cache = self.cache.get(cache_key)
if cache:
return cache
with self.dbengine.begin() as conn:
cur = conn.execute(_sql("select * from trw_radius where serv_type = 1"))
radius = self.warp(cur.fetchone())
self.cache.set(cache_key,radius, expire=600)
return radius