当前位置: 首页>>代码示例>>Python>>正文


Python db.DB类代码示例

本文整理汇总了Python中webp.utils.db.DB的典型用法代码示例。如果您正苦于以下问题:Python DB类的具体用法?Python DB怎么用?Python DB使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: list

def list(request):
    db = DB()
    tac_name = request.GET['tac_name']
    func_flag = request.GET['func_flag']
    sql = strtpl("select a.id,c.name taca_name,d.name tacb_name,e.name user_name,a.dt,a.status,a.description from func_tac_rel a,func b,tac c,tac d,user e where a.func_id=b.id and a.taca_id=c.id and a.tacb_id=d.id and a.user_id=e.id and b.flag='$func_flag' and (c.name like '%$tac_name%' or d.name like '%$tac_name%') order by a.dt desc").substitute(
            tac_name = tac_name,
            func_flag = func_flag)

    _debug_print('sql ' + sql)
    db.execute(sql)
    _list = []
    res = db.fetchall()
    _debug_print( 'res'+ str(res))
    data = {}
    for data['id'], data['taca_name'], data['tacb_name'], \
            data['user_name'], data['dt'], data['status'], data['description'] in res:

        _debug_print('data:' + str(data))
        ft = FuncTac( **data )
        _list.append(ft)
        data = {}

    dic = user_utils.user_info_context(request)

    user = dic['user']
    module = user.get_module('nonmarked')
    func = module.get_func('fieldcase')

    dic.update({
        'func': func,
        'list': _list,
        })
    return render_to_response("html/nonmarked/fieldcase/list.html", dic)
开发者ID:Superjom,项目名称:webp,代码行数:33,代码来源:fieldcase.py

示例2: from_db_by_func_tac_id

    def from_db_by_func_tac_id(tac='taca_id', func_tac_id=-1):
        db = DB()
        sql = "select id,name,key_1,value_1,key_2,value_2,key_3,value_3,key_4,value_4,key_5,value_5 from tac where id=(select %s from func_tac_rel where id=%d)" % (tac, func_tac_id)
        db.execute(sql)

        res = db.fetchone()
        tac = Tac()

        if res:
            (id, name, 
                key_1, value_1,
                key_2, value_2,
                key_3, value_3,
                key_4, value_4,
                key_5, value_5,) = res

            tac = Tac( id = id, name = name)

            for (key, value) in [
                    (key_1, value_1),
                    (key_2, value_2),
                    (key_3, value_3),
                    (key_4, value_4),
                    (key_5, value_5),]:

                if key or value:
                    tac.map[key] = value
            return tac
开发者ID:Superjom,项目名称:webp,代码行数:28,代码来源:Tac.py

示例3: from_db

    def from_db(id):
        db = DB()
        sql = "select id,name,key_1,value_1,key_2,value_2,key_3,value_3,key_4,value_4,key_5,value_5 from tac where id=%d" % id
        db.execute(sql)

        res = db.fetchone()
        tac = Tac()
        if res:
            (id, name, key_1, value_1, 
                key_2, value_2, key_3, value_3, 
                key_4, value_4, key_5, value_5) = res

            tac.id = id
            tac.name = name

            for (key, value) in [
                    (key_1, value_1),
                    (key_2, value_2),
                    (key_3, value_3),
                    (key_4, value_4),
                    (key_5, value_5),]:
                key = key.strip()
                value = value.strip()
                if  key or value:
                    tac.map[key] = value
        return tac
开发者ID:Superjom,项目名称:webp,代码行数:26,代码来源:Tac.py

示例4: delete

def delete(request):
    module_flag = request.GET["module_flag"]
    func_flag = request.GET["func_flag"]
    func_tac_id = int(request.GET["func_tac_id"])
    db = DB()
    
    tac = Tac.from_db_by_func_tac_id("taca_id", func_tac_id)

    Tac.del_func_tac_rel(func_tac_id = func_tac_id)

    a_keys, a_values = tac.keys_values

    shell = Shell(
        module_flag = module_flag,
        func_flag = func_flag,
        tac_name = tac.name,
        args = {
            'k': a_keys, 'v': a_values,
            't': 2,
            }
        )

    log_path = shell.gen_log_path()

    db.exe_commit("insert into func_tac_log(func_tac_id,path,kind) values(%d,'%s',0)" % (func_tac_id, log_path))

    res = shell.execute()
    if not res:
        db.exe_commit("update func_tac_rel set status=-1,description='Interface error' where id=%d" % func_tac_id)
    return HttpResponse("1")
开发者ID:Superjom,项目名称:webp,代码行数:30,代码来源:fieldstat.py

示例5: search_by_tac_id

 def search_by_tac_id(tac_id):
     db = DB()
     sql = "select a.id,a.name,a.description,a.dt,a.key_1,a.value_1,a.key_2,a.value_2,a.key_3,a.value_3,a.key_4,a.value_4,a.key_5,a.value_5,b.name module_name from tac a,module b where a.module_id=b.id and a.id=%d"  % tac_id
     #print 'search_by_tacid', sql
     db.execute(sql)
     res = db.fetchall()
     return res
开发者ID:Superjom,项目名称:webp,代码行数:7,代码来源:tac.py

示例6: search_by_module_id

    def search_by_module_id(module_id, tac_name):
        db = DB()
        if tac_name:
            sql = " select a.id,a.name,a.description,a.dt,a.key_1,a.value_1,a.key_2,a.value_2,a.key_3,a.value_3,a.key_4,a.value_4,a.key_5,a.value_5,b.name module_name from tac a,module b where a.module_id=b.id and b.id=%d and a.name like '%s' order by a.dt desc" % (module_id, tac_name)
        else:
            sql = " select a.id,a.name,a.description,a.dt,a.key_1,a.value_1,a.key_2,a.value_2,a.key_3,a.value_3,a.key_4,a.value_4,a.key_5,a.value_5,b.name module_name from tac a,module b where a.module_id=b.id and b.id=%d order by a.dt desc" % (module_id, )

        print 'search_by_module_id', sql
        db.cursor.execute(sql)
        res = db.fetchall()
        _list = []

        for id, name, description, dt, \
            key_1, value_1, key_2, value_2, key_3, value_3, \
            key_4, value_4, key_5, value_5, module_name in res:

            keyvalues = [(key, value) for (key, value) in (
                    (key_1, value_1),
                    (key_2, value_2),
                    (key_3, value_3),
                    (key_4, value_4),
                    (key_5, value_5),
                ) if key ]
            _list.append({
                'id': id,
                'name': name,
                'description': description,
                'dt': dt,
                'keyvalues': keyvalues,
                'module_name': module_name,
                })
        return _list
开发者ID:Superjom,项目名称:webp,代码行数:32,代码来源:tac.py

示例7: has

 def has( tac_id):
     db = DB()
     sql = "select count(*) from func_tac_rel where taca_id=%d or tacb_id=%d" % (tac_id, tac_id)
     db.execute(sql)
     res = db.fetchone()
     print 'count', res
     count = res[0]
     return count > 0
开发者ID:Superjom,项目名称:webp,代码行数:8,代码来源:tac.py

示例8: get_id

 def get_id(flag):
     db = DB()
     sql = "select id from module where flag='%s'" % flag
     print 'sql:', sql
     db.execute(sql)
     res = db.fetchone()
     id = res[0]
     return id
开发者ID:Superjom,项目名称:webp,代码行数:8,代码来源:module.py

示例9: delete

    def delete(tac_id):
        db = DB()
        if Tac.has(tac_id):
            return "a task is running!"

        sql = "delete from tac where id=%d" % tac_id
        db.execute(sql)
        db.commit()
        return True
开发者ID:Superjom,项目名称:webp,代码行数:9,代码来源:tac.py

示例10: create

    def create(dic):
        db = DB()
        keys = tuple([ dic[key] for key in ('module_id', 'name', 'description', 
                'key_1', 'value_1', 'key_2', 'value_2',
                'key_3', 'value_3', 'key_4', 'value_4',
                'key_5', 'value_5',) ])

        sql = u"insert into tac(module_id,name,description,key_1,value_1,key_2,value_2,key_3,value_3,key_4,value_4,key_5,value_5) values(%d,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % keys
        db.exe_commit(sql)
        return True
开发者ID:Superjom,项目名称:webp,代码行数:10,代码来源:tac.py

示例11: Module

class Module(object):

    def __init__(self, id=-1):
        self.id = id
        self.moduleobject = ModuleObject()
        self.db = DB()

    def fill(self, module_flag, module_name, roleId):
        '''
        query db and get all data to fill the object
        '''
        self.moduleobject.id = self.id
        self.moduleobject.flag = module_flag
        self.moduleobject.name = module_name
        self.roleId = roleId
        self._fill_funcs()

    def get_object(self):
        return self.moduleobject

    #TODO some bugs here
    def _fill_funcs(self):
        print 'module init len', len(self.moduleobject.list)
        sql = "select a.id func_id,a.flag func_flag,a.name func_name,c.flag purview_flag from func a,func_purview_role_rel b,purview c where a.id=b.func_id and b.purview_id=c.id and a.module_id=%d and b.role_id=%d order by a.sequence asc,a.id desc" % (self.id, self.roleId)
        self.db.execute(sql)
        res = self.db.fetchall()

        func_ids = set()
        last_f = None

        print 'module res:', res

        for func_id, func_flag, func_name, purview_flag in res:
            func_flag = func_flag
            func_name = func_name
            purview_flag = func_name

            if func_id in func_ids:
                last_f.purview.add(purview_flag)

            else:
                func_ids.add(func_id)
                f = Func(
                    id = func_id, 
                    flag = func_flag,
                    name = func_name
                )
                f.purview.add(purview_flag)
                self.moduleobject.list.add(f)
                last_f = f

    def __str__(self):
        return str(self.moduleobject)
开发者ID:Superjom,项目名称:webp,代码行数:53,代码来源:__init__.py

示例12: create

def create(request):
    db = DB()
    dic = user_utils.user_info_context(request)
    user = dic['user']
    module_flag = request.GET['module_flag']
    func_flag = request.GET['func_flag']
    taca_id = int(request.GET['taca_id'])
    tacb_id = int(request.GET['tacb_id'])
    func_id = db.get_value("select id from func where flag='%s'" % func_flag)
    count = db.get_value("select count(*) from func_tac_rel where func_id=%d and taca_id=%d and tacb_id=%d" % (func_id, taca_id, tacb_id))

    if count > 0: return HttpResponse("该策略任务已经存在")

    taca = Tac.from_db(id=taca_id)
    tacb = Tac.from_db(id=tacb_id)

    sql = "insert into func_tac_rel(func_id,taca_id,tacb_id,user_id,status) values(%d,%d,%d,%d,0)" % (func_id, taca_id, tacb_id, user.id)
    _debug_print(sql)
    db.exe_commit(sql)

    tac_name = "%s_%s" % (taca.name, tacb.name)

    sql = "select id from func_tac_rel where func_id=%d and taca_id=%d and tacb_id=%d" % (func_id, taca_id, tacb_id)
    _debug_print(sql)
    func_tac_id = db.get_value(sql)

    a_keys, a_values = taca.keys_values
    b_keys, b_values = tacb.keys_values
    
    shell = Shell(
        module_flag = module_flag,
        func_flag = func_flag,
        tac_name = tac_name,
        args = {
            'k': a_keys, 'v': a_values,
            'x': b_keys, 'y': b_values,
            't': 1,
            }
        )

    log_path = shell.gen_log_path()

    sql = "insert into func_tac_log(func_tac_id,path,kind) values(%d,'%s',1)" % (func_tac_id, log_path) 
    _debug_print(sql)
    db.exe_commit(sql)

    res = shell.execute()
    if res:
        return HttpResponse('1')
    else:
        sql = "update func_tac_rel set status=-1,description='Interface error' where id=%d" % func_tac_id
        _debug_print(sql)
        db.exe_commit(sql)
开发者ID:Superjom,项目名称:webp,代码行数:53,代码来源:fieldcase.py

示例13: create

 def create(dic):
     db = DB()
     g = dic
     module_id = g['module_id']
     sql = "insert into tac(module_id,name,description,key_1,value_1,key_2,value_2,key_3,value_3,key_4,value_4,key_5,value_5) values(%d,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" \
         % (module_id, g['name'], g['description'], 
             g['key_1'], g['value_1'], g['key_2'], g['value_2'], 
             g['key_3'], g['value_3'], g['key_4'], g['value_4'], 
             g['key_5'], g['value_5'], )
     try:
         db.execute(sql)
         return True
     except Exception,e:
         print 'error of create:', e
开发者ID:Superjom,项目名称:webp,代码行数:14,代码来源:module.py

示例14: update

    def update(dic):
        db = DB()
        sql = "update tac set name='%s',description='%s',key_1='%s',value_1='%s',key_2='%s',value_2='%s',key_3='%s',value_3='%s',key_4='%s',value_4='%s',key_5='%s',value_5='%s' where id=%d" \
            % tuple([ dic[key] for key in (
                 'name', 'description',
                'key_1', 'value_1', 
                'key_2', 'value_2',
                'key_3', 'value_3',
                'key_4', 'value_4',
                'key_5', 'value_5',
                'tac_id',
            )])

        db.execute(sql)
        db.commit()
        return True
开发者ID:Superjom,项目名称:webp,代码行数:16,代码来源:tac.py

示例15: create_schedule

def create_schedule(request):
    db = DB()
    func_tac_id = int(request.GET["func_tac_id"])
    db.execute("select a.path,c.name taca_name,d.name tacb_name from func_tac_log a join func_tac_rel b on a.func_tac_id=b.id left join tac c on b.taca_id=c.id left join tac d on b.tacb_id=d.id where b.id=%d" % func_tac_id)
    res = db.fetchone()
    if res: log_path, taca_name, tacb_name = res
    dic = user_utils.user_info_context(request)
    try:
        dic.update( dict(
            schedule = filetool.read(log_path) + "<br/>",
            tacName = "%s_%s"%(taca_name, tacb_name) if tacb_name != None else taca_name,
            ))
        return render_to_response("/html/nonmarked/fieldcase/createschedule.html", dic)

    except:
        return HttpResponse("日志文件不存在")
开发者ID:Superjom,项目名称:webp,代码行数:16,代码来源:fieldcase.py


注:本文中的webp.utils.db.DB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。