k2tools.threaddb (version 1.00.000 $Rev: 8 $, $Date: 2012-12-26 16:34:11 +0100 (Mi, 26 Dez 2012) $)
index
y:\server\csgo\csgo\addons\source-python\_libs\k2tools\threaddb.py

Path     addons/source-python/_libs/k2tools/threaddb.py
Name     Threaded DBPAI helper libary
Version  1.00.000
Revision $Rev: 8 $
Author   (C) [#OMEGA] - K2
 
 
IMPORTANT
 
This requires a DBAPI 2.0 compatible driver.
Specifically tested with pymysql
 
 
INFO
 
This libary is intended to provide some more suitable way of using MySQL queries on a srcds gameserver without interfering with the main server thread.
 
If you encounter any errors, and they are not handled (and preventing the plugin from running) please contact me and I'll see what I can do.
 
You can find information about MySQL error codes here:
http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
http://dev.mysql.com/doc/refman/5.5/en/error-messages-client.html
 
 
AGREEMENT
 
See addons/source-python/_libs/k2tools/license.txt

 
Modules
       
encodings
logging
socket
threading
time

 
Classes
       
builtins.object
CBWrapper
threading.Thread(builtins.object)
DBAPI
_DBAPIManager

 
class CBWrapper(builtins.object)
    Wrapper class just in case DB callback occurs after the script is unloaded. To use just create an object of this class and set unloaded to True upon unload.
 
  Methods defined here:
__init__(self)
cb(self, cb)
Use this function to wrap a class.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

 
class DBAPI(threading.Thread)
    
Method resolution order:
DBAPI
threading.Thread
builtins.object

Methods defined here:
__init__(self, driver=None, sleep=1, traise=False, loglevel=40, logfile=None, on_connect_queries=(), debug=1, *args, **kwargs)
Creates a threaded MySQL helper class.
 
@driver             - DBAPI Driver to use. (Default: auto)
                      Supported drivers (others might work too):
                      sqlite3
                      pymysql
@sleep              - How often it should check whether new queries were added to the queue in seconds. (Default: 1)
@traise             - If false, don't raise exceptions in threads but send the error to the console. (Default: False)
@loglevel           - Errorlevel to use
@on_connect_queries - Iterable of queries to execute when connected to the server
@debug              - Extended error checking
 
Raises ImportError if no valid driver is detected.
change_logfile(self, newfile)
connect(self, *args, **kwargs)
Connects to the MySQL server. 
 
This function will directly pass any arguments or keyword arguments to the driver's connect function.
See help on pymysql.connect or MySQLdb.connect for more info.
disconnect(self)
Disconnects from the database. 
 
This will continue executing any remaining queries in the queue before actually closing the connection.
execute(self, query, *args)
Executes a query. 
 
This is NOT threaded.
 
@query    - The SQL query to execute
@args     - Arguments to insert into the query
get_connection(self)
get_cursor(self)
get_driver(self)
# Intended for public use
run(self)
Do not call this function
texecute(self, query, args=(), callback=None, params=(), kwparams={})
Appends a query to the query queue. This is threaded and will not halt the server. 
 
Does extensive type checks with debug enabled. Otherwise make sure the params are of the correct type or
the queue might break.
 
 
 
@query       - The SQL query to execute
@args        - Arguments to insert into the query (Default: empty list)
@callback    - Function to be called once the query was successful.
               The function must have at least 1 paramater in which the results of the query will be stored (as received by fetchall()).
               (Default: None)
@params      - Additional function parameters (Default: empty list)
@kwparams    - Additional keyword function parameters (Default: empty dictionary)

Methods inherited from threading.Thread:
__repr__(self)
getName(self)
isAlive = is_alive(self)
isDaemon(self)
is_alive(self)
join(self, timeout=None)
setDaemon(self, daemonic)
setName(self, name)
start(self)

Data descriptors inherited from threading.Thread:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
daemon
ident
name

 
class _DBAPIManager(threading.Thread)
    Don't call any of the thread methods. It may cause unexpected behaviour.
 
 
Method resolution order:
_DBAPIManager
threading.Thread
builtins.object

Methods defined here:
__init__(self)
create_object(self, name, *args, **kwargs)
Creates a named DBAPI object.
 
Creating a named DBAPI object is useful to retrive it upon script reloading and if running 2 sperate threads is an issue. For example, upon reload your script might rely on properly writing the old data to the database, however if 2 threads are running you might end up writing and getting data from the db at the same time.
To circumvent this issue you can a named object; at a later point you can retrive the object as long it is still alive and executing SQL queries.
 
@name   - internal name of the DBAPI object, must be unique
 
Raises KeyError if the object already exists
delete_object(self, name)
Reduces the refcount to the specified DBAPI object by one.
If the refcount hits 0 it will be deleleted automatically once all commands are executed and the connection will be seperated
 
@name - internal name of the DBAPI object
 
Raises KeyError if the object is not found
get_object(self, name)
Increases the refcount to the specified DBAPI object by one.
 
@name - internal name of the DBAPI object
 
Returns the sql object if found
Returns False if the sql object is dead
Returns False otherwise
run(self)
DO NOT CALL THIS METHOD!
 
Removes dead MySQL objects.
Sets MySQL objects inactive / disconnects them if ref count reaches 0.

Methods inherited from threading.Thread:
__repr__(self)
getName(self)
isAlive = is_alive(self)
isDaemon(self)
is_alive(self)
join(self, timeout=None)
setDaemon(self, daemonic)
setName(self, name)
start(self)

Data descriptors inherited from threading.Thread:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)
daemon
ident
name

 
Data
        DBAPIManager = <_DBAPIManager(Thread-2, started 5916)>
__all__ = ['DBAPI', 'CBWrapper', 'DBAPIManager', '_DBAPIManager']

 
Author
        [#OMEGA] - K2