Skip to content

Commit 47ca11d

Browse files
committed
Documentation update
1 parent ebb09cf commit 47ca11d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2304
-2437
lines changed

doc/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#
1313
import os
1414
import sys
15+
import mariadb
16+
print(mariadb.__path__)
1517
sys.path.insert(0, os.path.abspath('../..'))
1618
sys.setrecursionlimit(1500)
1719

doc/source/connection.rst

Lines changed: 43 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -4,298 +4,105 @@ The connection class
44

55
.. sectionauthor:: Georg Richter <georg@mariadb.com>
66

7-
.. class:: mariadb.connection
8-
9-
Handles the connection to a MariaDB or MySQL database server. It encapsulates a database session.
10-
11-
Connections are created using the method :func:`~mariadb.connect()`.
7+
.. autoclass:: mariadb.connections.Connection
128

139
-----------------------
1410
Connection constructors
1511
-----------------------
1612

17-
.. method:: cursor(\*\*kwargs)
18-
19-
Returns a new cursor object using the current connection.
20-
21-
By default the result will be unbuffered, which means before executing another statement with the same connection the entire result set must be fetched.
22-
23-
fetch methods of the cursor class by default return result set values as a tuple, unless named_tuple or dictionary was specified. The latter one exists for compatibility reasons and should be avoided due to possible inconsistency in case two or more fields in a result set have the same name.
24-
25-
If cursor_type is set to mariadb.CURSOR_TYPE_READ_ONLY, a cursor is opened for the statement invoked with cursors execute() method.
26-
27-
Supported keywords:
28-
29-
- **named_tuple** (bool): When set to `True` results from fetch methods will be returned as named tuple.
30-
- **cursor_type** (type): When set to `CURSOR_TYPE_READ_ONLY`, server side cursor will be used.
31-
- **prefetch_size** (integer): The number of rows prefetched. This option will be ignored, if *cursor_type* is not `CURSOR_TYPE_READ_ONLY`
32-
- **buffered** (bool): When set to `True` the entire result set from a SELECT/SHOW statement will be stored in client memory
33-
- **prepared** (bool): When set to `True` cursor will remain in prepared state after the first :func:`~cursor.execute` method was called. Further calls to *execute()* method will ignore the sql statement.
34-
- **binary** (bool): When set to `True` cursor will be executed using the MariaDB client/server binary protocol.
35-
36-
:return: Returns a cursor object or raises an exception if an error occurred.
13+
.. automethod:: mariadb.connections.Connection.cursor
3714

3815
.. versionadded:: 1.0.1
3916

40-
.. method:: xid(format_id, global_transaction_id, branch_qualifier)
41-
42-
Returns a transaction ID object suitable for passing to the tpc methods of this connection
43-
44-
:param format_id: Format id. If not set default value `0` will be used.
45-
:type format_id: integer
46-
:param global_transaction_id: Global transaction qualifier, which must be unique. The maximum length of the global transaction id is limited to 64 characters.
47-
:type global transaction_id: string
48-
:param branch_qualifier: Branch qualifier which represents a local transaction identifier. The maximum length of the branch qualifier is limited to 64 characters.
49-
:type branch_qualifier: string
17+
.. automethod:: mariadb.connections.Connection.xid(format_id: int, global_transaction_id: str, brach_qualifier: str)
5018

5119
------------------
5220
Connection methods
5321
------------------
5422

5523
.. versionadded:: 1.1.0
56-
.. method:: begin()
57-
58-
Start a new transaction which can be committed by .commit() method,
59-
or cancelled by .rollback() method.
60-
61-
.. method:: commit()
62-
63-
Commit any pending transaction to the database.
64-
65-
.. note::
66-
67-
This method has no effect, when autocommit was set to True, or the storage engine in use doesn't support transactions.
68-
69-
.. method:: change_user(user, password, database)
24+
.. automethod:: mariadb.connections.Connection.begin
7025

71-
Changes the *user* and default *database* of the current connection.
72-
In order to successfully change users a valid username and password
73-
parameters must be provided and that user must have sufficient
74-
permissions to access the desired database.
26+
.. automethod:: mariadb.connections.Connection.commit
7527

76-
:param user: The user name for server authentication
77-
:type user: string
78-
:param password: The passoword of the user
79-
:type password: string
80-
:param database: The default database
81-
:type database: string
28+
.. automethod:: mariadb.connections.Connection.change_user(user, password, database)
8229

8330
If for any reason authorization fails an exception will be raised and the current user authentication will remain.
8431

85-
.. method:: close()
32+
.. automethod:: mariadb.connections.Connection.close
8633

87-
Close the connection now (rather than whenever .__del__() is called).
88-
89-
The connection will be unusable from this point forward; an Error
90-
(or subclass) exception will be raised if any operation is attempted
91-
with the connection. The same applies to all cursor objects trying to
92-
use the connection. If the connection was obtained by *ConnectionPool*,
93-
the connection will not be closed but returned to the pool.
94-
95-
.. method:: get_server_version()
96-
97-
Returns numeric version of connected database server as tuple.
98-
The form of the tuple is (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH).
99-
100-
The get_server_version() method was added for compatibility. New applications should use the connection attribute server_version_info.
34+
.. automethod:: mariadb.connections.Connection.get_server_version
10135

10236
.. versionadded:: 1.0.5
10337

104-
.. method:: escape_string(escape_str)
38+
.. automethod:: mariadb.connections.Connection.escape_string(escape_str)
10539

106-
This function is used to create a legal SQL string that you can use in
107-
an SQL statement. The given string is encoded and returned as an escaped string.
108-
109-
:param escape_str: The string that is to be escaped.
110-
:type escape_str: string
111-
112-
:returns: the escaped string or NULL on error.
113-
114-
.. method:: kill(thread_id)
115-
116-
This function is used to ask the server to terminate a database connection, specified
117-
by the *thread_id* parameter.
118-
119-
:param thread_id: An id which represents a database connection.
120-
:type thread_id: integer
40+
.. automethod:: mariadb.connections.Connection.kill(thread_id)
12141

122-
.. note::
123-
A thread_id from other connections can be determined by executing the SQL statement ``SHOW PROCESSLIST``
124-
The thread_id of the current connection the current connection is stored in :data:`connection_id` attribute.
42+
.. note::
43+
A thread_id from other connections can be determined by executing the SQL statement ``SHOW PROCESSLIST``
44+
The thread_id of the current connection the current connection is stored in :data:`connection_id` attribute.
12545

126-
.. method:: ping()
46+
.. automethod:: mariadb.connections.Connection.ping()
12747

128-
Checks if the connection to the database server is still available.
48+
.. automethod:: mariadb.connections.Connection.reconnect
12949

130-
.. note::
131-
If :data:`~auto_reconnect` was set to True, an attempt will be made to reconnect to the database server in case the connection was lost
132-
133-
If the connection is not available an InterfaceError will be raised.
134-
135-
.. method:: reconnect()
136-
137-
Tries to reconnect to a server in case the connection died due to timeout
138-
or other errors. It uses the same credentials which were specified in
139-
:func:`module.connect()` method.
140-
141-
.. method:: reset()
142-
143-
Tries to reconnect to a server in case the connection died due to timeout
144-
or other errors. It uses the same credentials which were specified in
145-
connect() method.
146-
147-
.. method:: rollback()
148-
149-
Causes the database to roll back to the start of any pending transaction
150-
151-
Closing a connection without committing the changes first will cause an
152-
implicit rollback to be performed.
50+
.. automethod:: mariadb.connections.Connection.reset
15351

154-
.. note::
52+
.. automethod:: mariadb.connections.Connection.rollback()
15553

156-
rollback() will not work as expected if autocommit mode was set to True or the storage engine does not support transactions.
157-
158-
.. method:: tpc_begin([xid])
159-
160-
Begins a TPC transaction with the given transaction ID xid, which
161-
was created by xid() method.
162-
163-
This method should be called outside of a transaction
164-
(i.e. nothing may have executed since the last .commit()
165-
or .rollback()).
166-
167-
Furthermore, it is an error to call commit() or rollback() within
168-
the TPC transaction. A ProgrammingError is raised, if the application
169-
calls commit() or rollback() during an active TPC transaction.
170-
171-
:param xid: A transaction id which was previously created by :func:`xid` method.
172-
:type xid: Dictionary
173-
174-
.. method:: tpc_commit([xid])
175-
176-
When called with no arguments, tpc_commit() commits a TPC transaction
177-
previously prepared with tpc_prepare().
178-
179-
If tpc_commit() is called prior to tpc_prepare(), a single phase commit
180-
is performed. A transaction manager may choose to do this if only a
181-
single resource is participating in the global transaction.
182-
183-
When called with a transaction ID xid, the database commits the given
184-
transaction. If an invalid transaction ID is provided, a ProgrammingError
185-
will be raised. This form should be called outside of a transaction, and
186-
is intended for use in recovery.
187-
188-
.. method:: tpc_prepare([ xid])
54+
.. versionadded:: 1.1.0
55+
.. automethod:: mariadb.connections.Connection.select_db
18956

190-
Performs the first phase of a transaction started with tpc_begin().
57+
.. automethod:: mariadb.connections.Connection.show_warnings
19158

192-
A ProgrammingError will be raised if this method outside of a TPC
193-
transaction.
59+
.. automethod:: mariadb.connections.Connection.tpc_begin
19460

195-
After calling tpc_prepare(), no statements can be executed until
196-
:func:`~tpc_commit` or :func:`~tpc_rollback` have been called.
61+
.. automethod:: mariadb.connections.Connection.tpc_commit
19762

198-
.. method:: tpc_recover()
63+
.. automethod:: mariadb.connections.Connection.tpc_prepare
19964

200-
Returns a list of pending transaction IDs suitable for use with
201-
tpc_commit(xid) or tpc_rollback(xid).
65+
.. automethod:: mariadb.connections.Connection.tpc_recover
20266

203-
.. method:: tpc_rollback([ xid])
67+
.. automethod:: mariadb.connections.Connection.tpc_rollback
20468

205-
When called with no arguments, tpc_rollback() rolls back a TPC
206-
transaction. It may be called before or after :func:`tpc_prepare`.
207-
208-
When called with a transaction ID xid, it rolls back the given
209-
transaction.
210-
21169
---------------------
21270
Connection attributes
21371
---------------------
21472

215-
.. data:: auto_reconnect
216-
217-
Enable or disable automatic reconnection to the server if the connection
218-
is found to have been lost.
219-
220-
When enabled, client tries to reconnect to a database server in case
221-
the connection to a database server died due to timeout or other errors.
222-
223-
.. data:: autocommit
224-
225-
Toggles autocommit mode on or off for the current database connection.
226-
227-
Autocommit mode only affects operations on transactional table types.
228-
Be aware that :func:`~rollback` will not work, if autocommit mode was switched on.
229-
230-
By default autocommit mode is set to False.
73+
.. autoattribute:: mariadb.connections.Connection.auto_reconnect
23174

232-
.. data:: character_set
75+
.. autoattribute:: mariadb.connections.Connection.autocommit
23376

234-
Returns the character set used for the connection
77+
.. autoattribute:: mariadb.connections.Connection.character_set
23578

236-
.. data:: collation
79+
.. autoattribute:: mariadb.connections.Connection.collation
23780

238-
Returns character set collation used for the connection
239-
240-
.. data:: connection_id
81+
.. autoattribute:: mariadb.connections.Connection.connection_id
24182

242-
Returns the (thread) id for the current connection.
243-
244-
If :data:`~auto_reconnect` was set to True, the id might change if the client reconnects to the database server
245-
246-
.. data:: database
83+
.. autoattribute:: mariadb.connections.Connection.database
24784

248-
Returns or sets the default database for the current connection
249-
250-
If the used database will not change, the preferred way is to specify
251-
the default database when establishing the connection.
252-
253-
.. data:: server_info
85+
.. autoattribute:: mariadb.connections.Connection.server_info
25486

255-
Returns the alphanumeric version of connected database. The numeric version
256-
can be obtained via server_version() property.
87+
.. autoattribute:: mariadb.connections.Connection.server_name
25788

258-
.. data:: server_name
89+
.. autoattribute:: mariadb.connections.Connection.server_port
25990

260-
Returns name or IP address of database server
261-
262-
.. data:: server_port
263-
264-
Returns the database server TCP/IP port
91+
.. versionadded:: 1.1.0
92+
.. autoattribute:: mariadb.connections.Connection.server_status
26593

266-
.. data:: server_version
94+
.. autoattribute:: mariadb.connections.Connection.server_version
26795

268-
Returns numeric version of connected database server. The form of the version
269-
number is VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH
270-
271-
.. data:: server_version_info
272-
273-
Returns numeric version of connected database server as tuple.
274-
The form of the tuple is (VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH)
96+
.. autoattribute:: mariadb.connections.Connection.server_version_info
27597

27698
.. versionadded:: 1.0.5
27799

278-
.. data:: tls_cipher
279-
280-
Returns TLS cipher suite in use by connection
281-
282-
.. data:: tls_version
283-
284-
Returns TLS protocol version used by connection
100+
.. autoattribute:: mariadb.connections.Connection.tls_cipher
285101

286-
.. data:: unix_socket
102+
.. autoattribute:: mariadb.connections.Connection.tls_version
287103

288-
Returns Unix socket name
104+
.. autoattribute:: mariadb.connections.Connection.unix_socket
289105

290-
.. data:: user
291-
292-
Returns user name for the current connection
293-
294-
.. data:: warnings
295-
296-
Returns the number of warnings from the last executed statement, or zero
297-
if there are no warnings.
298-
299-
.. note::
106+
.. autoattribute:: mariadb.connections.Connection.user
300107

301-
If the sql mode ``TRADITIONAL`` is enabled an error instead of a warning will be returned. To retrieve warnings the SQL statement ``SHOW WARNINGS`` has to be used.
108+
.. autoattribute:: mariadb.connections.Connection.warnings

0 commit comments

Comments
 (0)