Spec-Zone.ru › MySQL Connectors 1.0

10.5.2 Метод MySQLCursor.add_attribute()

Синтаксис:

cursor.add_attribute(name, value)

Добавляет новое именованное атрибут запроса в список, как часть функциональности MySQL сервера.

name: Имя должно быть строкой, но другие проверки валидации не выполняются; атрибуты отправляются на сервер как есть, и любые ошибки будут обнаружены и сообщены сервером.

value: значение преобразуется в двоичный протокол MySQL, аналогично тому, как преобразуются параметры подготовленных заявок. Об ошибке сообщается, если преобразование не выполняется.

Атрибуты запросов должны быть включены на сервере и по умолчанию отключены. При установке атрибутов запроса для подключения к серверу, которое их не поддерживает, регистрируется предупреждение. См. также для включения компоненты MySQL сервера query_attributes.

Пример использования атрибутов запроса:

#  Each invocation of `add_attribute` method will add a new query attribute:
    cur.add_attribute("foo", 2)
    cur.execute("SELECT first_name, last_name FROM clients")
	# The query above sent attibute "foo" with value 2.

    cur.add_attribute(*("bar", "3"))
    cur.execute("SELECT * FROM products WHERE price < ?", 10)
	# The query above sent attibutes ("foo", 2)  and ("bar", "3").

	my_attributes = [("page_name", "root"), ("previous_page", "login")]
    for attribute_tuple in my_attributes:
		cur.add_attribute(*attribute_tuple)
    cur.execute("SELECT * FROM offers WHERE publish = ?", 0)
	# The query above sent 4 attibutes.

# To check the current query attributes:

	print(cur.get_attributes())
	# prints:
	[("foo", 2), ("bar", "3"), ("page_name", "root"), ("previous_page", "login")]

# Query attributes are not cleared until the cursor is closed or
# of the clear_attributes() method is invoked:

	cur.clear_attributes()
    print(cur.get_attributes())
	# prints:
	[]
    cur.execute("SELECT first_name, last_name FROM clients")
    # The query above did not send any attibute.

Этот метод был добавлен в Connector/Python 8.0.26.

© 2025 Oracle
Licensed under the GPLv2 License.
https://docs.oracle.com/cd/E17952_01/connector-python-en/connector-python-api-mysqlcursor-add-attribute.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API