@@ -560,6 +560,9 @@ class Connection(object):
560
560
:param db: Alias for database. (for compatibility to MySQLdb)
561
561
:param passwd: Alias for password. (for compatibility to MySQLdb)
562
562
:param binary_prefix: Add _binary prefix on bytes and bytearray. (default: False)
563
+
564
+ See `Connection <https://www.python.org/dev/peps/pep-0249/#connection-objects>`_ in the
565
+ specification.
563
566
"""
564
567
565
568
_sock = None
@@ -716,7 +719,14 @@ def _create_ssl_ctx(self, sslp):
716
719
return ctx
717
720
718
721
def close (self ):
719
- """Send the quit message and close the socket"""
722
+ """
723
+ Send the quit message and close the socket.
724
+
725
+ See `Connection.close() <https://www.python.org/dev/peps/pep-0249/#Connection.close>`_
726
+ in the specification.
727
+
728
+ :raise Error: If the connection is already closed.
729
+ """
720
730
if self ._closed :
721
731
raise err .Error ("Already closed" )
722
732
self ._closed = True
@@ -732,6 +742,7 @@ def close(self):
732
742
733
743
@property
734
744
def open (self ):
745
+ """Return True if the connection is open"""
735
746
return self ._sock is not None
736
747
737
748
def _force_close (self ):
@@ -776,24 +787,38 @@ def begin(self):
776
787
self ._read_ok_packet ()
777
788
778
789
def commit (self ):
779
- """Commit changes to stable storage"""
790
+ """
791
+ Commit changes to stable storage.
792
+
793
+ See `Connection.commit() <https://www.python.org/dev/peps/pep-0249/#commit>`_
794
+ in the specification.
795
+ """
780
796
self ._execute_command (COMMAND .COM_QUERY , "COMMIT" )
781
797
self ._read_ok_packet ()
782
798
783
799
def rollback (self ):
784
- """Roll back the current transaction"""
800
+ """
801
+ Roll back the current transaction.
802
+
803
+ See `Connection.rollback() <https://www.python.org/dev/peps/pep-0249/#rollback>`_
804
+ in the specification.
805
+ """
785
806
self ._execute_command (COMMAND .COM_QUERY , "ROLLBACK" )
786
807
self ._read_ok_packet ()
787
808
788
809
def show_warnings (self ):
789
- """SHOW WARNINGS"""
810
+ """Send the " SHOW WARNINGS" SQL command. """
790
811
self ._execute_command (COMMAND .COM_QUERY , "SHOW WARNINGS" )
791
812
result = MySQLResult (self )
792
813
result .read ()
793
814
return result .rows
794
815
795
816
def select_db (self , db ):
796
- """Set current db"""
817
+ """
818
+ Set current db.
819
+
820
+ :param db: The name of the db.
821
+ """
797
822
self ._execute_command (COMMAND .COM_INIT_DB , db )
798
823
self ._read_ok_packet ()
799
824
@@ -831,7 +856,13 @@ def _quote_bytes(self, s):
831
856
return converters .escape_bytes (s )
832
857
833
858
def cursor (self , cursor = None ):
834
- """Create a new cursor to execute queries with"""
859
+ """
860
+ Create a new cursor to execute queries with.
861
+
862
+ :param cursor: The type of cursor to create; one of :py:class:`Cursor`,
863
+ :py:class:`SSCursor`, :py:class:`DictCursor`, or :py:class:`SSDictCursor`.
864
+ None means use Cursor.
865
+ """
835
866
if cursor :
836
867
return cursor (self )
837
868
return self .cursorclass (self )
@@ -873,7 +904,12 @@ def kill(self, thread_id):
873
904
return self ._read_ok_packet ()
874
905
875
906
def ping (self , reconnect = True ):
876
- """Check if the server is alive"""
907
+ """
908
+ Check if the server is alive.
909
+
910
+ :param reconnect: If the connection is closed, reconnect.
911
+ :raise Error: If the connection is closed and reconnect=False.
912
+ """
877
913
if self ._sock is None :
878
914
if reconnect :
879
915
self .connect ()
@@ -985,6 +1021,9 @@ def write_packet(self, payload):
985
1021
def _read_packet (self , packet_type = MysqlPacket ):
986
1022
"""Read an entire "mysql packet" in its entirety from the network
987
1023
and return a MysqlPacket type that represents the results.
1024
+
1025
+ :raise OperationalError: If the connection to the MySQL server is lost.
1026
+ :raise InternalError: If the packet sequence number is wrong.
988
1027
"""
989
1028
buff = b''
990
1029
while True :
@@ -1071,6 +1110,11 @@ def insert_id(self):
1071
1110
return 0
1072
1111
1073
1112
def _execute_command (self , command , sql ):
1113
+ """
1114
+ :raise InterfaceError: If the connection is closed.
1115
+ :raise ValueError: If no username was specified.
1116
+ """
1117
+
1074
1118
if not self ._sock :
1075
1119
raise err .InterfaceError ("(0, '')" )
1076
1120
@@ -1358,6 +1402,10 @@ def read(self):
1358
1402
self .connection = None
1359
1403
1360
1404
def init_unbuffered_query (self ):
1405
+ """
1406
+ :raise OperationalError: If the connection to the MySQL server is lost.
1407
+ :raise InternalError:
1408
+ """
1361
1409
self .unbuffered_active = True
1362
1410
first_packet = self .connection ._read_packet ()
1363
1411
0 commit comments