• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python dbapi.prepare_query_bind_vars函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: _execute_on_shard

  def _execute_on_shard(self, query, bind_vars, shard_idx):
    query, bind_vars = dbapi.prepare_query_bind_vars(query, bind_vars)
    for x in xrange(self.max_attempts):
      try:
        conn = self.conns[shard_idx]
        if conn is None:
          conn = self._dial_shard(shard_idx)

        if self.txn:
          self.txn.stmts.append(query)
          if conn not in self.txt.conns:
            # Defer the begin until we actually issue a statement.
            conn.begin()
            self.txt.conns.append(conn)

        return conn._execute(query, bind_vars)
      except dbexceptions.OperationalError as e:
        # Tear down regardless of the precise failure.
        self.conns[shard_idx] = None
        if isinstance(e, tablet3.TimeoutError):
          # On any timeout let the error bubble up and just redial next time.
          raise e

        if isinstance(e, tablet3.RetryError):
          # Give the tablet a moment to restart itself. This isn't
          # strictly necessary since there is a significant chance you
          # will end up talking to another host.
          time.sleep(self.reconnect_delay)
    raise dbexceptions.OperationalError('tablets unreachable', self.keyspace_name, shard_idx, self.db_type)
开发者ID:521wangzhifeng,项目名称:vitess,代码行数:29,代码来源:sharded.py


示例2: _execute_batch

  def _execute_batch(self, query_list, bind_vars_list, shard_idx):
    new_query_list = []
    new_bind_vars_list = []
    for query, bind_vars in zip(query_list, bind_vars_list):
      query, bind_vars = dbapi.prepare_query_bind_vars(query, bind_vars)
      new_query_list.append(query)
      new_bind_vars_list.append(bind_vars)
    query_list = new_query_list
    bind_vars_list = new_bind_vars_list

    for x in xrange(self.max_attempts):
      try:
        conn = self.conns[shard_idx]
        if conn is None:
          conn = self._dial_shard(shard_idx)

        return conn._execute_batch(query_list, bind_vars_list)
      except dbexceptions.OperationalError as e:
        # Tear down regardless of the precise failure.
        self.conns[shard_idx] = None
        if isinstance(e, tablet3.TimeoutError):
          # On any timeout let the error bubble up and just redial next time.
          raise e

        if isinstance(e, tablet3.RetryError):
          # Give the tablet a moment to restart itself. This isn't
          # strictly necessary since there is a significant chance you
          # will end up talking to another host.
          time.sleep(self.reconnect_delay)
    raise dbexceptions.OperationalError('tablets unreachable', self.keyspace_name, shard_idx, self.db_type)
开发者ID:521wangzhifeng,项目名称:vitess,代码行数:30,代码来源:sharded.py


示例3: _create_v2_request_with_keyspace_ids

def _create_v2_request_with_keyspace_ids(sql, new_binds, keyspace_name, tablet_type, keyspace_ids, not_in_transaction):
    """Make a request dict from arguments.

  Args:
    sql: Str sql with format tokens.
    new_binds: Dict of bind variables.
    keyspace_name: Str keyspace name.
    tablet_type: Str tablet_type.
    keyspace_ids: Bytes list of keyspace IDs.
    not_in_transaction: Bool True if a transaction should not be started
      (generally used when sql is not a write).

  Returns:
    A (str: value) dict.
  """
    # keyspace_ids are Keyspace Ids packed to byte[]
    sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
    new_binds = field_types.convert_bind_vars(new_binds)
    req = {
        "Sql": sql,
        "BindVariables": new_binds,
        "Keyspace": keyspace_name,
        "TabletType": topodata_pb2.TabletType.Value(tablet_type.upper()),
        "KeyspaceIds": keyspace_ids,
        "NotInTransaction": not_in_transaction,
    }
    return req
开发者ID:shawnps,项目名称:vitess,代码行数:27,代码来源:vtgatev2.py


示例4: _create_v2_request_with_keyranges

def _create_v2_request_with_keyranges(
    sql, new_binds, keyspace_name, tablet_type, keyranges, not_in_transaction):
  """Make a request dict from arguments.

  Args:
    sql: Str sql with format tokens.
    new_binds: Dict of bind variables.
    keyspace_name: Str keyspace name.
    tablet_type: Str tablet_type.
    keyranges: A list of keyrange.KeyRange objects.
    not_in_transaction: Bool True if a transaction should not be started
      (generally used when sql is not a write).

  Returns:
    A (str: value) dict.
  """
  sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
  new_binds = field_types.convert_bind_vars(new_binds)
  req = {
      'Sql': sql,
      'BindVariables': new_binds,
      'Keyspace': keyspace_name,
      'TabletType': topodata_pb2.TabletType.Value(tablet_type.upper()),
      'KeyRanges': keyranges,
      'NotInTransaction': not_in_transaction,
  }
  return req
开发者ID:BobbWu,项目名称:vitess,代码行数:27,代码来源:vtgatev2.py


示例5: _execute

 def _execute(self, sql, bind_variables):
   sql, bind_variables = dbapi.prepare_query_bind_vars(sql, bind_variables)
   try:
     result = self.conn._execute(sql, bind_variables)
   except dbexceptions.IntegrityError as e:
     vtdb_logger.get_logger().integrity_error(e)
     raise
   return result
开发者ID:Carney,项目名称:vitess,代码行数:8,代码来源:vtclient.py


示例6: _execute_batch

  def _execute_batch(self, sql_list, bind_variables_list):
    sane_sql_list = []
    sane_bind_vars_list = []
    for sql, bind_variables in zip(sql_list, bind_variables_list):
      sane_sql, sane_bind_vars = dbapi.prepare_query_bind_vars(sql, bind_variables)
      sane_sql_list.append(sane_sql)
      sane_bind_vars_list.append(sane_bind_vars)

    result = self.conn._execute_batch(sane_sql_list, sane_bind_vars_list)
    return result
开发者ID:Acidburn0zzz,项目名称:vitess,代码行数:10,代码来源:vtclient.py


示例7: _execute_batch

  def _execute_batch(self, sql_list, bind_variables_list):
    sane_sql_list = []
    sane_bind_vars_list = []
    for sql, bind_variables in zip(sql_list, bind_variables_list):
      sane_sql, sane_bind_vars = dbapi.prepare_query_bind_vars(sql, bind_variables)
      sane_sql_list.append(sane_sql)
      sane_bind_vars_list.append(sane_bind_vars)

    result = tablet2.TabletConnection._execute_batch(self, sane_sql_list, sane_bind_vars_list)
    self._time_failed = 0
    return result
开发者ID:Eric-Chen,项目名称:vitess,代码行数:11,代码来源:vt_occ2.py


示例8: _execute_batch

  def _execute_batch(
      self, sql_list, bind_variables_list, keyspace_list, keyspace_ids_list,
      tablet_type, as_transaction, effective_caller_id=None):
    query_list = []
    for sql, bind_vars, keyspace, keyspace_ids in zip(
        sql_list, bind_variables_list, keyspace_list, keyspace_ids_list):
      sql, bind_vars = dbapi.prepare_query_bind_vars(sql, bind_vars)
      query = {}
      query['Sql'] = sql
      query['BindVariables'] = field_types.convert_bind_vars(bind_vars)
      query['Keyspace'] = keyspace
      query['KeyspaceIds'] = keyspace_ids
      query_list.append(query)

    rowsets = []

    try:
      req = {
          'Queries': query_list,
          'TabletType': tablet_type,
          'AsTransaction': as_transaction,
      }
      self._add_caller_id(req, effective_caller_id)
      self._add_session(req)
      response = self._get_client().call('VTGate.ExecuteBatchKeyspaceIds', req)
      self._update_session(response)
      if response.reply.get('Error'):
        raise gorpc.AppError(
            response.reply['Error'], 'VTGate.ExecuteBatchKeyspaceIds')
      for reply in response.reply['List']:
        fields = []
        conversions = []
        results = []
        rowcount = 0

        for field in reply['Fields']:
          fields.append((field['Name'], field['Type']))
          conversions.append(field_types.conversions.get(field['Type']))

        for row in reply['Rows']:
          results.append(tuple(_make_row(row, conversions)))

        rowcount = reply['RowsAffected']
        lastrowid = reply['InsertId']
        rowsets.append((results, rowcount, lastrowid, fields))
    except gorpc.GoRpcError as e:
      self.logger_object.log_private_data(bind_variables_list)
      raise self._convert_exception(
          e, sql_list, keyspace_ids_list,
          keyspace='', tablet_type=tablet_type)
    except Exception:
      logging.exception('gorpc low-level error')
      raise
    return rowsets
开发者ID:xgwubin,项目名称:vitess,代码行数:54,代码来源:vtgatev2.py


示例9: _create_req_with_keyranges

def _create_req_with_keyranges(sql, new_binds, keyspace, tablet_type, keyranges):
  sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
  new_binds = field_types.convert_bind_vars(new_binds)
  req = {
        'Sql': sql,
        'BindVariables': new_binds,
        'Keyspace': keyspace,
        'TabletType': tablet_type,
        'KeyRanges': [keyrange.KeyRange(kr) for kr in keyranges],
        }
  return req
开发者ID:poorman,项目名称:vitess,代码行数:11,代码来源:vtgatev2.py


示例10: _create_req_with_keyspace_ids

def _create_req_with_keyspace_ids(sql, new_binds, keyspace, tablet_type, keyspace_ids):
  sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
  new_binds = field_types.convert_bind_vars(new_binds)
  req = {
        'Sql': sql,
        'BindVariables': new_binds,
        'Keyspace': keyspace,
        'TabletType': tablet_type,
        'KeyspaceIds': [str(kid) for kid in keyspace_ids],
        }
  return req
开发者ID:poorman,项目名称:vitess,代码行数:11,代码来源:vtgatev2.py


示例11: _execute_entity_ids

  def _execute_entity_ids(
      self, sql, bind_variables, keyspace, tablet_type,
      entity_keyspace_id_map, entity_column_name, not_in_transaction=False,
      effective_caller_id=None):
    sql, new_binds = dbapi.prepare_query_bind_vars(sql, bind_variables)
    new_binds = field_types.convert_bind_vars(new_binds)
    req = {
        'Sql': sql,
        'BindVariables': new_binds,
        'Keyspace': keyspace,
        'TabletType': tablet_type,
        'EntityKeyspaceIDs': [
            {'ExternalID': xid, 'KeyspaceID': kid}
            for xid, kid in entity_keyspace_id_map.iteritems()],
        'EntityColumnName': entity_column_name,
        'NotInTransaction': not_in_transaction,
        }

    self._add_caller_id(req, effective_caller_id)
    self._add_session(req)

    fields = []
    conversions = []
    results = []
    rowcount = 0
    lastrowid = 0
    try:
      response = self._get_client().call('VTGate.ExecuteEntityIds', req)
      self._update_session(response)
      reply = response.reply
      if response.reply.get('Error'):
        raise gorpc.AppError(response.reply['Error'], 'VTGate.ExecuteEntityIds')

      if reply.get('Result'):
        res = reply['Result']
        for field in res['Fields']:
          fields.append((field['Name'], field['Type']))
          conversions.append(field_types.conversions.get(field['Type']))

        for row in res['Rows']:
          results.append(tuple(_make_row(row, conversions)))

        rowcount = res['RowsAffected']
        lastrowid = res['InsertId']
    except gorpc.GoRpcError as e:
      self.logger_object.log_private_data(bind_variables)
      raise self._convert_exception(
          e, sql, entity_keyspace_id_map,
          keyspace=keyspace, tablet_type=tablet_type)
    except Exception:
      logging.exception('gorpc low-level error')
      raise
    return results, rowcount, lastrowid, fields
开发者ID:xgwubin,项目名称:vitess,代码行数:53,代码来源:vtgatev2.py


示例12: _create_req_with_keyspace_ids

def _create_req_with_keyspace_ids(sql, new_binds, keyspace, tablet_type, keyspace_ids):
  # keyspace_ids are Keyspace Ids packed to byte[]
  sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
  new_binds = field_types.convert_bind_vars(new_binds)
  req = {
        'Sql': sql,
        'BindVariables': new_binds,
        'Keyspace': keyspace,
        'TabletType': tablet_type,
        'KeyspaceIds': keyspace_ids,
        }
  return req
开发者ID:gwmullin,项目名称:vitess,代码行数:12,代码来源:vtgatev2.py


示例13: _create_req_with_keyranges

def _create_req_with_keyranges(sql, new_binds, keyspace, tablet_type, keyranges):
  # keyranges are keyspace.KeyRange objects with start/end packed to byte[]
  sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
  new_binds = field_types.convert_bind_vars(new_binds)
  req = {
        'Sql': sql,
        'BindVariables': new_binds,
        'Keyspace': keyspace,
        'TabletType': tablet_type,
        'KeyRanges': keyranges,
        }
  return req
开发者ID:gwmullin,项目名称:vitess,代码行数:12,代码来源:vtgatev2.py


示例14: _create_req_with_keyranges

def _create_req_with_keyranges(sql, new_binds, keyspace, tablet_type, keyranges, not_in_transaction):
    # keyranges are keyspace.KeyRange objects with start/end packed to byte[]
    sql, new_binds = dbapi.prepare_query_bind_vars(sql, new_binds)
    new_binds = field_types.convert_bind_vars(new_binds)
    req = {
        "Sql": sql,
        "BindVariables": new_binds,
        "Keyspace": keyspace,
        "TabletType": tablet_type,
        "KeyRanges": keyranges,
        "NotInTransaction": not_in_transaction,
    }
    return req
开发者ID:hadoop835,项目名称:vitess,代码行数:13,代码来源:vtgatev2.py


示例15: _execute_batch

  def _execute_batch(self, sql_list, bind_variables_list):
    sane_sql_list = []
    sane_bind_vars_list = []
    for sql, bind_variables in zip(sql_list, bind_variables_list):
      sane_sql, sane_bind_vars = dbapi.prepare_query_bind_vars(sql, bind_variables)
      sane_sql_list.append(sane_sql)
      sane_bind_vars_list.append(sane_bind_vars)

    try:
      result = self.conn._execute_batch(sane_sql_list, sane_bind_vars_list)
    except dbexceptions.IntegrityError as e:
      vtdb_logger.get_logger().integrity_error(e)
      raise

    return result
开发者ID:Carney,项目名称:vitess,代码行数:15,代码来源:vtclient.py


示例16: _execute_batch

  def _execute_batch(self, sql_list, bind_variables_list, keyspace, tablet_type, keyspace_ids):
    query_list = []
    for sql, bind_vars in zip(sql_list, bind_variables_list):
      sql, bind_vars = dbapi.prepare_query_bind_vars(sql, bind_vars)
      query = {}
      query['Sql'] = sql
      query['BindVariables'] = field_types.convert_bind_vars(bind_vars)
      query_list.append(query)

    rowsets = []

    try:
      req = {
          'Queries': query_list,
          'Keyspace': keyspace,
          'TabletType': tablet_type,
          'KeyspaceIds': keyspace_ids,
      }
      self._add_session(req)
      response = self.client.call('VTGate.ExecuteBatchKeyspaceIds', req)
      self._update_session(response)
      if 'Error' in response.reply and response.reply['Error']:
        raise gorpc.AppError(response.reply['Error'], 'VTGate.ExecuteBatchKeyspaceIds')
      for reply in response.reply['List']:
        fields = []
        conversions = []
        results = []
        rowcount = 0

        for field in reply['Fields']:
          fields.append((field['Name'], field['Type']))
          conversions.append(field_types.conversions.get(field['Type']))

        for row in reply['Rows']:
          results.append(tuple(_make_row(row, conversions)))

        rowcount = reply['RowsAffected']
        lastrowid = reply['InsertId']
        rowsets.append((results, rowcount, lastrowid, fields))
    except gorpc.GoRpcError as e:
      raise convert_exception(e, str(self), sql_list, bind_variables_list)
    except:
      logging.exception('gorpc low-level error')
      raise
    return rowsets
开发者ID:gwmullin,项目名称:vitess,代码行数:45,代码来源:vtgatev2.py


示例17: _execute_entity_ids

  def _execute_entity_ids(self, sql, bind_variables, keyspace, tablet_type, entity_keyspace_id_map, entity_column_name):
    sql, new_binds = dbapi.prepare_query_bind_vars(sql, bind_variables)
    new_binds = field_types.convert_bind_vars(new_binds)
    req = {
        'Sql': sql,
        'BindVariables': new_binds,
        'Keyspace': keyspace,
        'TabletType': tablet_type,
        'EntityKeyspaceIDs': [
            {'ExternalID': xid, 'KeyspaceID': kid}
            for xid, kid in entity_keyspace_id_map.iteritems()],
        'EntityColumnName': entity_column_name,
        }

    self._add_session(req)

    fields = []
    conversions = []
    results = []
    try:
      response = self.client.call('VTGate.ExecuteEntityIds', req)
      self._update_session(response)
      reply = response.reply
      if 'Error' in response.reply and response.reply['Error']:
        raise gorpc.AppError(response.reply['Error'], 'VTGate.ExecuteEntityIds')

      if 'Result' in reply:
        res = reply['Result']
        for field in res['Fields']:
          fields.append((field['Name'], field['Type']))
          conversions.append(field_types.conversions.get(field['Type']))

        for row in res['Rows']:
          results.append(tuple(_make_row(row, conversions)))

        rowcount = res['RowsAffected']
        lastrowid = res['InsertId']
    except gorpc.GoRpcError as e:
      raise convert_exception(e, str(self), sql, bind_variables)
    except:
      logging.exception('gorpc low-level error')
      raise
    return results, rowcount, lastrowid, fields
开发者ID:gwmullin,项目名称:vitess,代码行数:43,代码来源:vtgatev2.py


示例18: build_query_list

 def build_query_list():
     query_list = []
     for sql, bind_vars, keyspace, keyspace_ids, shards in zip(
         sql_list, bind_variables_list, keyspace_list, keyspace_ids_list, shards_list
     ):
         sql, bind_vars = dbapi.prepare_query_bind_vars(sql, bind_vars)
         query = {}
         query["Sql"] = sql
         query["BindVariables"] = field_types.convert_bind_vars(bind_vars)
         query["Keyspace"] = keyspace
         if keyspace_ids:
             if shards:
                 raise dbexceptions.ProgrammingError(
                     "Keyspace_ids and shards cannot both be defined " "for the same executemany query."
                 )
             query["KeyspaceIds"] = keyspace_ids
         else:
             query["Shards"] = shards
         query_list.append(query)
     return query_list
开发者ID:hadoop835,项目名称:vitess,代码行数:20,代码来源:vtgatev2.py


示例19: _execute_batch

    def _execute_batch(self, sql_list, bind_variables_list, tablet_type):
        query_list = []
        for sql, bind_vars in zip(sql_list, bind_variables_list):
            sql, bind_vars = dbapi.prepare_query_bind_vars(sql, bind_vars)
            query = {}
            query["Sql"] = sql
            query["BindVariables"] = field_types.convert_bind_vars(bind_vars)
            query_list.append(query)

        rowsets = []

        try:
            req = {"Queries": query_list, "TabletType": tablet_type}
            self._add_session(req)
            response = self.client.call("VTGate.ExecuteBatch", req)
            self._update_session(response)
            if "Error" in response.reply and response.reply["Error"]:
                raise gorpc.AppError(response.reply["Error"], "VTGate.ExecuteBatch")
            for reply in response.reply["List"]:
                fields = []
                conversions = []
                results = []
                rowcount = 0

                for field in reply["Fields"]:
                    fields.append((field["Name"], field["Type"]))
                    conversions.append(field_types.conversions.get(field["Type"]))

                for row in reply["Rows"]:
                    results.append(tuple(_make_row(row, conversions)))

                rowcount = reply["RowsAffected"]
                lastrowid = reply["InsertId"]
                rowsets.append((results, rowcount, lastrowid, fields))
        except gorpc.GoRpcError as e:
            self.logger_object.log_private_data(bind_variables_list)
            raise convert_exception(e, str(self), sql_list)
        except:
            logging.exception("gorpc low-level error")
            raise
        return rowsets
开发者ID:henryanand,项目名称:vitess,代码行数:41,代码来源:vtgatev3.py


示例20: build_query_list

 def build_query_list():
   """Create a query dict list from parameters."""
   query_list = []
   for sql, bind_vars, keyspace_name, keyspace_ids, shards in zip(
       sql_list, bind_variables_list, keyspace_list, keyspace_ids_list,
       shards_list):
     sql, bind_vars = dbapi.prepare_query_bind_vars(sql, bind_vars)
     query = {}
     query['Sql'] = sql
     query['BindVariables'] = field_types.convert_bind_vars(bind_vars)
     query['Keyspace'] = keyspace_name
     if keyspace_ids:
       if shards:
         raise dbexceptions.ProgrammingError(
             'Keyspace_ids and shards cannot both be defined '
             'for the same executemany query.')
       query['KeyspaceIds'] = keyspace_ids
     else:
       query['Shards'] = shards
     query_list.append(query)
   return query_list
开发者ID:BobbWu,项目名称:vitess,代码行数:21,代码来源:vtgatev2.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python field_types.convert_bind_vars函数代码示例发布时间:2022-05-26
下一篇:
Python vtctl_client.connect函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap