|
| 1 | +.. "reference.rst" file |
| 2 | +.. moduleauthor:: NerdyNick < [email protected]> |
| 3 | +.. sectionauthor:: NerdyNick < [email protected]> |
| 4 | +.. sectionauthor:: NerdyNick < [email protected]> |
| 5 | +.. module:: PySQLPool |
| 6 | + :synopsis: MySQL Connection Pooling |
| 7 | + |
| 8 | +=========================== |
| 9 | +PySQLPool Object Reference |
| 10 | +=========================== |
| 11 | + |
| 12 | +This is a standard object reference for PySQLPool. Being that PySQLPool is a connection pooling wrapper |
| 13 | +around MySQLdb many of the same methods and parameters are support. You can kind hints or further docs |
| 14 | +by reading the MySQLdb Documentation at http://mysql-python.sourceforge.net/MySQLdb-1.2.2/ |
| 15 | + |
| 16 | +:mod:`PySQLPool` |
| 17 | +================== |
| 18 | + |
| 19 | +.. attribute:: __version__ |
| 20 | + |
| 21 | + PySQLPool Version Number |
| 22 | + |
| 23 | +.. attribute:: __author__ |
| 24 | + |
| 25 | + PySQLPool Author String |
| 26 | + |
| 27 | +.. function:: getNewConnection(*args, **kargs) |
| 28 | + |
| 29 | + Fast function to generate a new PySQLConnection instance. Arguments are those of :class:`PySQLConnection` |
| 30 | + |
| 31 | +.. function:: getNewQuery([connection[, commitOnEnd[, **kargs]]]) |
| 32 | + |
| 33 | + Fast method to generate a new PySQLQuery instance. |
| 34 | + |
| 35 | + If an instance of a PySQLConnection object is passes for the connection parameter. It will be used for the |
| 36 | + connection. Otherwise \**kargs will be used to generate a PySQLConnection instance via the :meth:`getNewConnection` method. |
| 37 | + |
| 38 | +.. function:: getNewPool() |
| 39 | + |
| 40 | + Returns a reference to the current PySQLPool object |
| 41 | + |
| 42 | +.. function:: terminatePool() |
| 43 | + |
| 44 | + Causes PySQLPool to commit and terminate all your current MySQL connections |
| 45 | + |
| 46 | +.. function:: commitPool() |
| 47 | + |
| 48 | + Causes PySQLPool to commit all your current MySQL connections |
| 49 | + |
| 50 | +.. function:: cleanupPool() |
| 51 | + |
| 52 | + Causes PySQLPool to analyse all current MySQL connections, and clean up an dead connections. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +:mod:`PySQLPool.PySQLQuery` |
| 57 | +============================= |
| 58 | + |
| 59 | +The PySQLQuery class is by far one of the biggest work horses in the whole PySQLPool library, next to the PySQLPool class. |
| 60 | +It is responsable for handaling the execution of your query(s). Which in itself is a lot of work. PySQLQuery handles talking |
| 61 | +to the heart of PySQLPool, The PySQLPool class. To fetch a new connection or one that has been estabished. It then creates a |
| 62 | +MySQL cursor object to handle the execution of your sql statement against your MySQL database. |
| 63 | + |
| 64 | +.. class:: PySQLQuery(PySQLConnectionObj[, commitOnEnd]) |
| 65 | + |
| 66 | + .. attribute:: Pool |
| 67 | + |
| 68 | + Used to store a reference to the PySQLPool object |
| 69 | + |
| 70 | + .. attribute:: connInfo |
| 71 | + |
| 72 | + Used to store the connection information to be used for talking to the db. This is a PySQLConnection instance. |
| 73 | + |
| 74 | + .. attribute:: commitOnEnd |
| 75 | + |
| 76 | + A boolean flag used to tell the connection that it should auto commit your statement at the end of its execution. |
| 77 | + |
| 78 | + .. attribute:: record |
| 79 | + |
| 80 | + A storage reference to your results that where returned from your last select statement. |
| 81 | + |
| 82 | + .. attribute:: rowcount |
| 83 | + |
| 84 | + The number of rows returned by your last select statement. |
| 85 | + |
| 86 | + .. attribute:: affectedRows |
| 87 | + |
| 88 | + The number of affected rows that your last delete/insert/update statement affected. |
| 89 | + |
| 90 | + .. attribute:: conn |
| 91 | + |
| 92 | + An internaly used reference to the current locked connection as returned by the PySQLPool class. This is an |
| 93 | + instance of a PySQLConnectionManager object. |
| 94 | + |
| 95 | + .. attribute:: lastError |
| 96 | + |
| 97 | + A reference to the last MySQL error as returned by the under lying MySQLdb library. You can reference this if you need. |
| 98 | + But PySQLQuery will raise this error forward for you to catch yourself. |
| 99 | + |
| 100 | + .. attribute:: lastInsertID |
| 101 | + |
| 102 | + The last auto incrament ID that an insert statement create. |
| 103 | + |
| 104 | + .. method:: __del__() |
| 105 | + |
| 106 | + The destructor method used for freeing up any locked connections that may not have be release do to some reason. |
| 107 | + |
| 108 | + .. method:: Query(query[, args]) |
| 109 | + |
| 110 | + Depricated alias for :meth:`query` |
| 111 | + |
| 112 | + .. method:: query(query[, args]) |
| 113 | + |
| 114 | + Executes the given query. |
| 115 | + |
| 116 | + query - string, query to execute on server |
| 117 | + args - optional sequence or mapping, parameters to use with query |
| 118 | + |
| 119 | + Note: If args is a sequence, then %s must be used as the parameter placeholder in the query. |
| 120 | + If a mapping is used, %(key)s must be used as the placeholder. |
| 121 | + |
| 122 | + Returns the number of affected rows. |
| 123 | + |
| 124 | + .. method:: QueryOne(query[, args]) |
| 125 | + |
| 126 | + Depricated alias for :meth:`queryOne` |
| 127 | + |
| 128 | + .. method:: queryOne(query[, args]) |
| 129 | + |
| 130 | + A generator style version of :meth:`query`. |
| 131 | + |
| 132 | + Parameters are the same as :meth:`query`, but instead of fetching all the data from the server at once. |
| 133 | + It is returned one row at a time for every iteration. Each row will be returned as well as record can |
| 134 | + still be used to access the current row. |
| 135 | + |
| 136 | + .. method:: queryMany(query, args) |
| 137 | + .. method:: executeMany(query, args) |
| 138 | + |
| 139 | + Execute a multi-row query. |
| 140 | + |
| 141 | + query - string, query to execute on server |
| 142 | + args - sequence of sequences or mappings, parameters to use with query. |
| 143 | + |
| 144 | + Returns the number of affected rows |
| 145 | + |
| 146 | + .. method:: queryMulti(queries) |
| 147 | + .. method:: executeMulti(queries) |
| 148 | + |
| 149 | + Executes a sequence of query strings |
| 150 | + |
| 151 | + Each sequence item and be a sequence or a string. If item is a sequence the 1st item but be the query. |
| 152 | + The 2nd must be the replacement sequence or mapping to use with the query. |
| 153 | + |
| 154 | + Returns the total number of affected rows |
| 155 | + |
| 156 | + .. method:: _GetConnection() |
| 157 | + |
| 158 | + Private method used to fetch a connection from the central pool of connections |
| 159 | + |
| 160 | + .. method:: _ReturnConnection() |
| 161 | + |
| 162 | + Private method used to return a connection to the central pool of connections |
| 163 | + |
| 164 | + .. method:: escape() |
| 165 | + |
| 166 | + Varius string escape methods as provided by MySQLdb. Each matchs a function of the same name in MySQLdb |
| 167 | + |
| 168 | + .. method:: escapeString() |
| 169 | + |
| 170 | + See :meth:`escape` |
| 171 | + |
| 172 | + .. method:: escape_string() |
| 173 | + |
| 174 | + See :meth:`escape` |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | +:mod:`PySQLPool.PySQLPool` |
| 179 | +=========================== |
| 180 | + |
| 181 | +.. class:: PySQLPool() |
| 182 | + |
| 183 | + .. attribute:: __pool |
| 184 | + |
| 185 | + .. attribute:: maxActiveConnections |
| 186 | + |
| 187 | + .. attribute:: maxActivePerConnection |
| 188 | + |
| 189 | + .. method:: Terminate() |
| 190 | + |
| 191 | + .. method:: Cleanup() |
| 192 | + |
| 193 | + .. method:: Commit() |
| 194 | + |
| 195 | + .. method:: GetConnection(PySQLConnectionObj) |
| 196 | + |
| 197 | + .. method:: returnConnection(connObj) |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | +:mod:`PySQLPool.PySQLConnection` |
| 202 | +================================= |
| 203 | + |
| 204 | +.. attribute:: connection_timeout |
| 205 | + |
| 206 | +A `datetime.timedelta` representing your default MySQL connection_timeout. This is used |
| 207 | +to improve performance with checking to see if connections are valid and reconnecting if needed. Each |
| 208 | +connection instance maintains a timestamp of its last activity. That is updated for every query or test. |
| 209 | +The connection is auto tested for every new instance of a PySQLQuery created on its initial fetching |
| 210 | +of a connection. |
| 211 | + |
| 212 | +.. class:: PySQLConnection([host, [user, [passwd, [db, [port]]]]], **kargs) |
| 213 | + |
| 214 | + Command Pattern Object to store connection information for use in PySQLPool |
| 215 | + |
| 216 | + Supported kargs are: |
| 217 | + * **host** - string, host to connect |
| 218 | + * **user,username** - string, user to connect as |
| 219 | + * **passwd,password** - string, password to use |
| 220 | + * **db,schema** - string, database to use |
| 221 | + * **port** - integer, TCP/IP port to connect to |
| 222 | + * **unix_socket** - string, location of unix_socket to use |
| 223 | + * **conv** - conversion dictionary, see MySQLdb.converters |
| 224 | + * **connect_timeout** - number of seconds to wait before the connection attempt fails. |
| 225 | + * **compress** - if set, compression is enabled |
| 226 | + * **named_pipe** - if set, a named pipe is used to connect (Windows only) |
| 227 | + * **init_command** - command which is run once the connection is created |
| 228 | + * **read_default_file** - file from which default client values are read |
| 229 | + * **read_default_group** - configuration group to use from the default file |
| 230 | + * **cursorclass** - class object, used to create cursors (keyword only) |
| 231 | + * **use_unicode** - If True, text-like columns are returned as unicode objects using the |
| 232 | + connection's character set. Otherwise, text-like columns are returned as strings. |
| 233 | + columns are returned as normal strings. Unicode objects will always be encoded to |
| 234 | + the connection's character set regardless of this setting. |
| 235 | + * **charset** - If supplied, the connection character set will be changed to this character set (MySQL-4.1 and newer). |
| 236 | + This implies use_unicode=True |
| 237 | + * **sql_mode** - If supplied, the session SQL mode will be changed to this setting (MySQL-4.1 and newer). |
| 238 | + For more details and legal values, see the MySQL documentation. |
| 239 | + * **client_flag** - integer, flags to use or 0 (see MySQL docs or constants/CLIENTS.py) |
| 240 | + * **ssl** - dictionary or mapping, contains SSL connection parameters; see the MySQL documentation for more details (mysql_ssl_set()). |
| 241 | + If this is set, and the client does not support SSL, NotSupportedError will be raised. |
| 242 | + * **local_inifile** - integer, non-zero enables LOAD LOCAL INFILE; zero disables |
| 243 | + |
| 244 | + Note: There are a number of undocumented, non-standard methods. |
| 245 | + See the documentation for the MySQL C API for some hints on what they do. |
| 246 | + |
| 247 | + .. attribute:: info |
| 248 | + |
| 249 | + Dictionary containing the connection info to be passed off to the MySQLdb layer |
| 250 | + |
| 251 | + .. attribute:: key |
| 252 | + |
| 253 | + An auto generated md5 checksum to represent your connection in the pool. This is generated off of the |
| 254 | + username, password, host, and db/schema. |
| 255 | + |
| 256 | + .. method:: __getattr__(name) |
| 257 | + |
| 258 | + Accessor to :attr:`info` |
| 259 | + |
| 260 | + |
| 261 | +.. class:: PySQLConnectionManager |
| 262 | + |
| 263 | + .. method:: __init__(PySQLConnectionObj) |
| 264 | + |
| 265 | + .. method:: updateCheckTime() |
| 266 | + |
| 267 | + .. method:: Connect() |
| 268 | + |
| 269 | + .. method:: ReConnect() |
| 270 | + |
| 271 | + .. method:: TestConnection(forceCheck = False) |
| 272 | + |
| 273 | + .. method:: Commit() |
| 274 | + |
| 275 | + .. method:: Close() |
0 commit comments