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


Python kinterbasdb.query方法代码示例

本文整理汇总了Python中kinterbasdb.query方法的典型用法代码示例。如果您正苦于以下问题:Python kinterbasdb.query方法的具体用法?Python kinterbasdb.query怎么用?Python kinterbasdb.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kinterbasdb的用法示例。


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

示例1: query

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def query(self, paramstyle=None):
        """
        Returns the query part of the sql query.
            >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
            >>> q.query()
            'SELECT * FROM test WHERE name=%s'
            >>> q.query(paramstyle='qmark')
            'SELECT * FROM test WHERE name=?'
        """
        s = []
        for x in self.items:
            if isinstance(x, SQLParam):
                x = x.get_marker(paramstyle)
                s.append(safestr(x))
            else:
                x = safestr(x)
                # automatically escape % characters in the query
                # For backward compatability, ignore escaping when the query looks already escaped
                if paramstyle in ['format', 'pyformat']:
                    if '%' in x and '%%' not in x:
                        x = x.replace('%', '%%')
                s.append(x)
        return "".join(s) 
开发者ID:mqingyn,项目名称:torngas,代码行数:25,代码来源:basedb.py

示例2: _db_execute

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _db_execute(self, cur, sql_query):
        """executes an sql query"""
        self.ctx.dbq_count += 1

        try:
            a = time.time()
            query, params = self._process_query(sql_query)
            out = cur.execute(query, params)
            b = time.time()
        except:
            if self.printing:
                print >> debug, 'ERR:', str(sql_query)
            if self.ctx.transactions:
                self.ctx.transactions[-1].rollback()
            else:
                self.ctx.rollback()
            raise

        if self.printing:
            print >> debug, '%s (%s): %s' % (round(b - a, 2), self.ctx.dbq_count, str(sql_query))
        return out 
开发者ID:mqingyn,项目名称:torngas,代码行数:23,代码来源:basedb.py

示例3: _db_execute

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _db_execute(self, cur, sql_query): 
        """executes an sql query"""
        self.ctx.dbq_count += 1
        
        try:
            a = time.time()
            query, params = self._process_query(sql_query)
            out = cur.execute(query, params)
            b = time.time()
        except:
            if self.printing:
                print >> debug, 'ERR:', str(sql_query)
            if self.ctx.transactions:
                self.ctx.transactions[-1].rollback()
            else:
                self.ctx.rollback()
            raise

        if self.printing:
            print >> debug, '%s (%s): %s' % (round(b-a, 2), self.ctx.dbq_count, str(sql_query))
        return out 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:23,代码来源:db.py

示例4: _db_execute

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _db_execute(self, cur, sql_query): 
        """executes an sql query"""
        self.ctx.dbq_count += 1
        
        try:
            a = time.time()
            query, params = self._process_query(sql_query)
            out = cur.execute(query, params)
            b = time.time()
        except:
            if self.printing:
                print('ERR:', str(sql_query), file=debug)
            if self.ctx.transactions:
                self.ctx.transactions[-1].rollback()
            else:
                self.ctx.rollback()
            raise

        if self.printing:
            print('%s (%s): %s' % (round(b-a, 2), self.ctx.dbq_count, str(sql_query)), file=debug)
        return out 
开发者ID:Naayouu,项目名称:Hatkey,代码行数:23,代码来源:db.py

示例5: __init__

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def __init__(self, items=None):
        r"""Creates a new SQLQuery.

            >>> SQLQuery("x")
            <sql: 'x'>
            >>> q = SQLQuery(['SELECT * FROM ', 'test', ' WHERE x=', SQLParam(1)])
            >>> q
            <sql: 'SELECT * FROM test WHERE x=1'>
            >>> q.query(), q.values()
            ('SELECT * FROM test WHERE x=%s', [1])
            >>> SQLQuery(SQLParam(1))
            <sql: '1'>
        """
        if items is None:
            self.items = []
        elif isinstance(items, list):
            self.items = items
        elif isinstance(items, SQLParam):
            self.items = [items]
        elif isinstance(items, SQLQuery):
            self.items = list(items.items)
        else:
            self.items = [items]

        # Take care of SQLLiterals
        for i, item in enumerate(self.items):
            if isinstance(item, SQLParam) and isinstance(item.value, SQLLiteral):
                self.items[i] = item.value.v 
开发者ID:mqingyn,项目名称:torngas,代码行数:30,代码来源:basedb.py

示例6: __len__

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def __len__(self):
        return len(self.query()) 
开发者ID:mqingyn,项目名称:torngas,代码行数:4,代码来源:basedb.py

示例7: values

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def values(self):
        """
        Returns the values of the parameters used in the sql query.
            >>> q = SQLQuery(["SELECT * FROM test WHERE name=", SQLParam('joe')])
            >>> q.values()
            ['joe']
        """
        return [i.value for i in self.items if isinstance(i, SQLParam)] 
开发者ID:mqingyn,项目名称:torngas,代码行数:10,代码来源:basedb.py

示例8: _str

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _str(self):
        try:
            return self.query() % tuple([sqlify(x) for x in self.values()])
        except (ValueError, TypeError):
            return self.query() 
开发者ID:mqingyn,项目名称:torngas,代码行数:7,代码来源:basedb.py

示例9: sqlquote

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def sqlquote(a):
    """
    Ensures `a` is quoted properly for use in a SQL query.

        >>> 'WHERE x = ' + sqlquote(True) + ' AND y = ' + sqlquote(3)
        <sql: "WHERE x = 't' AND y = 3">
        >>> 'WHERE x = ' + sqlquote(True) + ' AND y IN ' + sqlquote([2, 3])
        <sql: "WHERE x = 't' AND y IN (2, 3)">
    """
    if isinstance(a, list):
        return _sqllist(a)
    else:
        return sqlparam(a).sqlquery() 
开发者ID:mqingyn,项目名称:torngas,代码行数:15,代码来源:basedb.py

示例10: _process_query

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _process_query(self, sql_query):
        """Takes the SQLQuery object and returns query string and parameters.
        """
        paramstyle = getattr(self, 'paramstyle', 'pyformat')
        query = sql_query.query(paramstyle)
        params = sql_query.values()
        return query, params 
开发者ID:mqingyn,项目名称:torngas,代码行数:9,代码来源:basedb.py

示例11: update

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def update(self, tables, where, vars=None, _test=False, **values):
        """
        Update `tables` with clause `where` (interpolated using `vars`)
        and setting `values`.

            >>> db = DB(None, {})
            >>> name = 'Joseph'
            >>> q = db.update('foo', where='name = $name', name='bob', age=2,
            ...     created=SQLLiteral('NOW()'), vars=locals(), _test=True)
            >>> q
            <sql: "UPDATE foo SET age = 2, name = 'bob', created = NOW() WHERE name = 'Joseph'">
            >>> q.query()
            'UPDATE foo SET age = %s, name = %s, created = NOW() WHERE name = %s'
            >>> q.values()
            [2, 'bob', 'Joseph']
        """
        if vars is None: vars = {}
        where = self._where(where, vars)

        query = (
            "UPDATE " + sqllist(tables) +
            " SET " + sqlwhere(values, ', ') +
            " WHERE " + where)

        if _test: return query

        db_cursor = self._db_cursor()
        self._db_execute(db_cursor, query)
        if not self.ctx.transactions:
            self.ctx.commit()
        return db_cursor.rowcount 
开发者ID:mqingyn,项目名称:torngas,代码行数:33,代码来源:basedb.py

示例12: _process_insert_query

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _process_insert_query(self, query, tablename, seqname):
        return query 
开发者ID:mqingyn,项目名称:torngas,代码行数:4,代码来源:basedb.py

示例13: _get_all_sequences

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _get_all_sequences(self):
        """Query postgres to find names of all sequences used in this database."""
        if self._sequences is None:
            q = "SELECT c.relname FROM pg_class c WHERE c.relkind = 'S'"
            self._sequences = set([c.relname for c in self.query(q)])
        return self._sequences 
开发者ID:mqingyn,项目名称:torngas,代码行数:8,代码来源:basedb.py

示例14: __init__

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def __init__(self, items=None):
        r"""Creates a new SQLQuery.
        
            >>> SQLQuery("x")
            <sql: 'x'>
            >>> q = SQLQuery(['SELECT * FROM ', 'test', ' WHERE x=', SQLParam(1)])
            >>> q
            <sql: 'SELECT * FROM test WHERE x=1'>
            >>> q.query(), q.values()
            ('SELECT * FROM test WHERE x=%s', [1])
            >>> SQLQuery(SQLParam(1))
            <sql: '1'>
        """
        if items is None:
            self.items = []
        elif isinstance(items, list):
            self.items = items
        elif isinstance(items, SQLParam):
            self.items = [items]
        elif isinstance(items, SQLQuery):
            self.items = list(items.items)
        else:
            self.items = [items]
            
        # Take care of SQLLiterals
        for i, item in enumerate(self.items):
            if isinstance(item, SQLParam) and isinstance(item.value, SQLLiteral):
                self.items[i] = item.value.v 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:30,代码来源:db.py

示例15: _str

# 需要导入模块: import kinterbasdb [as 别名]
# 或者: from kinterbasdb import query [as 别名]
def _str(self):
        try:
            return self.query() % tuple([sqlify(x) for x in self.values()])            
        except (ValueError, TypeError):
            return self.query() 
开发者ID:joxeankoret,项目名称:nightmare,代码行数:7,代码来源:db.py


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