Connection Class¶
- class attachsql.connection(hostname, user, password, database, port)¶
Parameters: - hostname (str) – The hostname to the server
- user (str) – The user name to connect with
- password (str) – The password to connect with
- database (str) – The default database for the connection
- port (int) – The port to connect on or 0 for a Unix Domain Socket connection
- connection_id()¶
Returns the connection ID of the connection. If there is no established connection this will return 0.
Returns: The ID for the connection Return type: int
- connect()¶
Start connection to the server. poll() needs to be called (usually more than once) for the connection to actually occur.
Returns: True on success Return type: bool
- poll()¶
Poll a connection to see if there is more data.
Returns: A numeric status to be compared with Return Constants Return type: int
- get_server_version()¶
Returns the version string for the server
Returns: The version string Return type: str
- query(query[, parameters])¶
Send a query to the server. Parameters can be given to fill in ? markers in a query. This should be in a Python list containing dictionaries formatted as follows as follows:
[{'type': attachsql.ESCAPE_TYPE_CHAR, 'data':'hello'}, {'type': attachsql.ESCAPE_TYPE_INT, 'data': 123456, is_unsigned: True}]
For a full list of types see Escape Constants
Parameters: - query (str) – The query statement to send
- parameters (list) –
Returns: A query class
Return type: query
- set_ssl(key, cert, ca, capath, cipher[, verify])¶
Sets the SSL certifications and enables SSL connections
Parameters: - key (str) – The path for the key file
- cert (str) – The path for the certificate
- ca (str) – The path for the CA
- capath (str) – The path containing many CAs
- cipher (str) – A list of ciphers to allow
- verify (bool) – Set to verify the SSL connection
Returns: True on success
Return type: boolean
- set_option(option[, unused])¶
Sets a connection option, the list of possible options can be found in Option Constants
Parameters: - option (int) – The option to set
- unused – This parameter is for future use
Returns: True on success
Return type: boolean