⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pysqlrclient.py

📁 适合于Unix/Linux下的一个持久数据库连接池
💻 PY
📖 第 1 页 / 共 2 页
字号:
# Copyright (c) 2000 Roman Milner# See the file COPYING for more informationfrom SQLRelay import CSQLRelayclass sqlrconnection:    """    A wrapper for the sqlrelay connection API.  Closely follows the C++ API.    """    def __init__(self, host, port, socket, user, password, retrytime=0, tries=1):        """         Opens a connection to the sqlrelay server and authenticates with        user and password.  Failed connections are retried for tries times        at retrytime interval.  If tries is 0 then retries will continue        forever.  If retrytime is 0 then retries will be attempted on a        default interval.        """        self.connection = CSQLRelay.sqlrcon_alloc(host, port, socket, user, password, retrytime, tries)    def __del__(self):        CSQLRelay.sqlrcon_free(self.connection)    def endSession(self):        """        Ends the current session.        """        return CSQLRelay.endSession(self.connection)    def suspendSession(self):        """        Disconnects this connection from the current        session but leaves the session open so         that another connection can connect to it         using resumeSession().        """        return CSQLRelay.suspendSession(self.connection)    def getConnectionPort(self):        """        Returns the inet port that the connection is         communicating over. This parameter may be         passed to another connection for use in        the resumeSession() method.        Note: the value returned by this method is        only valid after a call to suspendSession().        """        return CSQLRelay.getConnectionPort(self.connection)    def getConnectionSocket(self):        """        Returns the unix socket that the connection is         communicating over. This parameter may be         passed to another connection for use in        the resumeSession() method.        Note: the value returned by this method is        only valid after a call to suspendSession().        """        return CSQLRelay.getConnectionSocket(self.connection)    def resumeSession(self, port, socket):        """        Resumes a session previously left open         using suspendSession().        Returns 1 on success and 0 on failure.        """        return CSQLRelay.resumeSession(self.connection, port, socket)    def ping(self):        """        Returns 1 if the database is up and 0        if it's down.        """        return CSQLRelay.ping(self.connection)    def identify(self):        """        Returns the type of database:           oracle8, postgresql, mysql, etc.        """        return CSQLRelay.identify(self.connection)    def dbVersion(self):        """        Returns the version of the database        """        return CSQLRelay.dbVersion(self.connection)    def bindFormat(self):        """        Returns a string representing the format        of the bind variables used in the db.        """        return CSQLRelay.bindFormat(self.connection)    def autoCommitOn(self):        """        Instructs the database to perform a commit        after every successful query.        """        return CSQLRelay.autoCommitOn(self.connection)    def autoCommitOff(self):        """        Instructs the database to wait for the         client to tell it when to commit.        """        return CSQLRelay.autoCommitOff(self.connection)    def commit(self):        """        Issues a commit, returns 1 if the commit        succeeded, 0 if it failed and -1 if an        error occurred.        """        return CSQLRelay.commit(self.connection)    def rollback(self):        """        Issues a rollback, returns 1 if the rollback        succeeded, 0 if it failed and -1 if an        error occurred.        """        return CSQLRelay.rollback(self.connection)    def debugOn(self):        """        Turn verbose debugging on.        """        return CSQLRelay.debugOn(self.connection)    def debugOff(self):        """        Turn verbose debugging off.        """        return CSQLRelay.debugOff(self.connection)    def getDebug(self):        """        Returns 1 if debugging is turned on and 0 if debugging is turned off.        """        return CSQLRelay.getDebug(self.connection)class sqlrcursor:    """    A wrapper for the sqlrelay cursor API.  Closely follows the C++ API.    """    def __init__(self, sqlrcon):        self.connection = sqlrcon        self.cursor = CSQLRelay.sqlrcur_alloc(sqlrcon.connection)    def __del__(self):        CSQLRelay.sqlrcur_free(self.cursor)    def setResultSetBufferSize(self, rows):        """        Sets the number of rows of the result set        to buffer at a time.  0 (the default)        means buffer the entire result set.        """        return CSQLRelay.setResultSetBufferSize(self.cursor, rows)    def getResultSetBufferSize(self):        """        Returns the number of result set rows that         will be buffered at a time or 0 for the        entire result set.        """        return CSQLRelay.getResultSetBufferSize(self.cursor)    def dontGetColumnInfo(self):        """        Tells the server not to send any column        info (names, types, sizes).  If you don't        need that info, you should call this        method to improve performance.        """        return CSQLRelay.dontGetColumnInfo(self.cursor)    def mixedCaseColumnNames(self):        """        Columns names are returned in the same        case as they are defined in the database.        This is the default.        """        return CSQLRelay.mixedCaseColumnNames(self.cursor)    def upperCaseColumnNames(self):        """        Columns names are converted to upper case.        """        return CSQLRelay.upperCaseColumnNames(self.cursor)    def lowerCaseColumnNames(self):        """        Columns names are converted to lower case.        """        return CSQLRelay.lowerCaseColumnNames(self.cursor)    def getColumnInfo(self):        """        Tells the server to send column info.        """        return CSQLRelay.getColumnInfo(self.cursor)    def cacheToFile(self, filename):        """        Sets query caching on.  Future queries        will be cached to the file "filename".        The full pathname of the file can be        retrieved using getCacheFileName().                A default time-to-live of 10 minutes is        also set.                Note that once cacheToFile() is called,        the result sets of all future queries will        be cached to that file until another call         to cacheToFile() changes which file to        cache to or a call to cacheOff() turns off        caching.        """        return CSQLRelay.cacheToFile(self.cursor,filename)    def setCacheTtl(self, ttl):        """        Sets the time-to-live for cached result        sets. The sqlr-cachemanger will remove each         cached result set "ttl" seconds after it's         created.        """        return CSQLRelay.setCacheTtl(self.cursor,ttl)    def getCacheFileName(self):        """        Returns the name of the file containing the most        recently cached result set.        """        return CSQLRelay.getCacheFileName(self.cursor)    def cacheOff(self):        """        Sets query caching off.        """        return CSQLRelay.cacheOff(self.cursor)    """    If you don't need to use substitution or bind variables    in your queries, use these two methods.    """    def sendQuery(self, query):        """        Send a SQL query to the server and        gets a result set.        """        return CSQLRelay.sendQuery(self.cursor, query)    def sendQueryWithLength(self, query, length):        """        Sends "query" with length "length" and gets        a result set. This method must be used if        the query contains binary data.        """        return CSQLRelay.sendQueryWithLength(self.cursor, query, length)    def sendFileQuery(self, path, file):        """        Send the SQL query in path/file to the server and        gets a result set.        """        return CSQLRelay.sendFileQuery(self.cursor, path, file)    """    If you need to use substitution or bind variables, in your    queries use the following methods.  See the API documentation    for more information about substitution and bind variables.    """    def prepareQuery(self, query):        """        Prepare to execute query.        """        return CSQLRelay.prepareQuery(self.cursor, query)    def prepareQueryWithLength(self, query, length):        """        Prepare to execute "query" with length         "length".  This method must be used if the        query contains binary data.        """        return CSQLRelay.prepareQueryWithLength(self.cursor, query, length)    def prepareFileQuery(self, path, file):        """        Prepare to execute the contents of path/filename.        """        return CSQLRelay.prepareFileQuery(self.cursor, path, file)    def substitution(self, variable, value, precision=0, scale=0):        """        Define a substitution variable.        Returns true if the variable was successfully substituted or false if        the variable isn't a string, integer or floating point number, or if        precision and scale aren't provided for a floating point number.        """        return CSQLRelay.substitution(self.cursor,variable,value,precision,scale)    def clearBinds(self):        """        Clear all binds variables.        """        return CSQLRelay.clearBinds(self.cursor)    def countBindVariables(self):        """        Parses the previously prepared query,        counts the number of bind variables defined        in it and returns that number.        """        return CSQLRelay.countBindVariables(self.cursor)    def inputBind(self, variable, value, precision=0, scale=0):        """        Define an input bind varaible.        Returns true if the variable was successfully bound or false if the        variable isn't a string, integer or floating point number, or if        precision and scale aren't provided for a floating point number.        """        return CSQLRelay.inputBind(self.cursor, variable, value, precision, scale)    def inputBindBlob(self, variable, value, length):        """        Define an input bind varaible.        """        return CSQLRelay.inputBindBlob(self.cursor, variable, value, length)    def inputBindClob(self, variable, value, length):        """        Define an input bind varaible.        """        return CSQLRelay.inputBindClob(self.cursor, variable, value, length)    def defineOutputBindString(self, variable, length):        """        Define a string output bind varaible.        """        return CSQLRelay.defineOutputBindString(self.cursor, variable, length)    def defineOutputBindInteger(self, variable):        """        Define an integer output bind varaible.        """        return CSQLRelay.defineOutputBindInteger(self.cursor, variable)    def defineOutputBindDouble(self, variable):        """        Define a double precision floating point output bind varaible.        """        return CSQLRelay.defineOutputBindDouble(self.cursor, variable)    def defineOutputBindBlob(self, variable):        """        Define an output bind varaible.        """        return CSQLRelay.defineOutputBindBlob(self.cursor, variable)    def defineOutputBindClob(self, variable):        """        Define an output bind varaible.        """        return CSQLRelay.defineOutputBindClob(self.cursor, variable)    def defineOutputBindCursor(self, variable):        """        Define an output bind varaible.        """        return CSQLRelay.defineOutputBindCursor(self.cursor, variable)    def substitutions(self, variables, values, precisions=None, scales=None):        """        Define substitution variables.        Returns true if the variables were successfully substituted or false if        one of the variables wasn't a string, integer or floating point number,        or if precision and scale weren't provided for a floating point number.        """

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -