示例#1
0
文件: cache.py 项目: mmaps/msdn-tools
    def _load_by_name(self, name):
        """
        Returns one
        :type name:str
        :param name:undecorated function name
        :rtype msdn.document.MsdnFunction
        """
        func = MsdnFunction()
        logging.debug(name)
        cur = self.conn.cursor()
        cur.execute("select fid, name, decorated, dll, rva, sid from Function where name=?", (name,))
        row = cur.fetchone()
        if not row:
            logging.debug("cache miss")
            return MsdnFunction()

        func.name = row["name"]
        func.decorated = row["decorated"]
        func.dll = row["dll"]
        func.rva = row["rva"]
        sid = row["sid"]

        cur.execute("select shortid from ShortId where sid=?", (sid,))
        row = cur.fetchone()
        if not row:
            logging.debug("no ShortID found: %s" % func)
            return MsdnFunction()

        func.shortid = row["shortid"]
        return func
示例#2
0
文件: cache.py 项目: mmaps/msdn-tools
    def _load_by_sid(self, shortid):
        """
        Can return multiple
        :type shortid: str
        :rtype msdn.document.MsdnFunction
        """
        rv = []
        func = MsdnFunction(shortid)
        logging.debug(func)
        cur = self.conn.cursor()

        cur.execute(
            "select fid, name, decorated, dll, rva, shortid from Function, Shortid where ShortId.shortid=? and Function.sid=ShortId.sid",
            (shortid,))
        rows = cur.fetchall()
        if not rows:
            logging.debug("cache miss")
            rv.append(func)
            return rv

        for row in rows:
            func = MsdnFunction(shortid)
            func.name = row["name"]
            func.decorated = row["decorated"]
            func.dll = row["dll"]
            func.rva = row["rva"]
            func.shortid = row["shortid"]
            fid = row["fid"]

            cur.execute(
                "select Locale, Version, Alt.scid, Src.scid, code from Alternate as Alt, SourceCode as Src where fid=? and Alt.scid=Src.scid",
                (fid,))
            alts = cur.fetchall()
            if not alts:
                logging.debug("no alternate versions of function %s" % func)
                return MsdnFunction(shortid)

            for alt in alts:
                logging.debug("func %s alternate %s" % (func, ",".join(str(i) for i in iter(alt))))
                func.add_code_snippet(func.name, alt["locale"], alt["version"], alt["code"], func.dll)

            rv.append(func)

        cur.close()
        return rv