コード例 #1
0
ファイル: mysqlconnection.py プロジェクト: thraxil/gtreed
 def __init__(self, db, user, password='', host='localhost', port=0, **kw):
     global MySQLdb
     if MySQLdb is None:
         import MySQLdb, MySQLdb.constants.CR, MySQLdb.constants.ER
     self.module = MySQLdb
     self.host = host
     self.port = port
     self.db = db
     self.user = user
     self.password = password
     self.kw = {}
     if MySQLdb.version_info[:3] >= (1, 2, 1):
         self.need_unicode = True
     else:
         self.need_unicode = False
     for key in ("unix_socket", "init_command",
             "read_default_file", "read_default_group", "conv"):
         if key in kw:
             self.kw[key] = col.popKey(kw, key)
     for key in ("connect_timeout", "compress", "named_pipe", "use_unicode",
             "client_flag", "local_infile"):
         if key in kw:
             self.kw[key] = int(col.popKey(kw, key))
     if "charset" in kw:
         self.dbEncoding = self.kw["charset"] = col.popKey(kw, "charset")
     else:
         self.dbEncoding = None
     if "sqlobject_encoding" in kw:
         self.encoding = col.popKey(kw, "sqlobject_encoding")
     else:
         self.encoding = 'ascii'
     DBAPI.__init__(self, **kw)
コード例 #2
0
ファイル: mssqlconnection.py プロジェクト: thraxil/gtreed
    def __init__(self, db, user, password='', host='localhost',
                 autoCommit=0, **kw):
        global sqlmodule
        if not sqlmodule:
            try:
                import adodbapi as sqlmodule
            except ImportError:
                import pymssql as sqlmodule

        if sqlmodule.__name__ == 'adodbapi':
            import adodbapi as sqlmodule
            self.dbconnection = sqlmodule.connect
            # ADO uses unicode only (AFAIK)
            self.usingUnicodeStrings = True

            # Need to use SQLNCLI provider for SQL Server Express Edition
            if kw.get("ncli"):
                conn_str = "Provider=SQLNCLI;"
            else:
                conn_str = "Provider=SQLOLEDB;"

            conn_str += "Data Source=%s;Initial Catalog=%s;"

            # MSDE does not allow SQL server login 
            if kw.get("sspi"):
                conn_str += "Integrated Security=SSPI;Persist Security Info=False"
                self.make_conn_str = lambda keys: [conn_str % (keys.host, keys.db)]
            else:
                conn_str += "User Id=%s;Password=%s"
                self.make_conn_str = lambda keys: [conn_str % (keys.host, keys.db, keys.user, keys.password)]

            col.popKey(kw, "sspi")
            col.popKey(kw, "ncli")

        else: # pymssql
            self.dbconnection = sqlmodule.connect
            sqlmodule.Binary = lambda st: str(st)
            # don't know whether pymssql uses unicode
            self.usingUnicodeStrings = False
            self.make_conn_str = lambda keys:  \
                   ["", keys.user, keys.password, keys.host, keys.db]

        self.autoCommit=int(autoCommit)
        self.host = host
        self.db = db
        self.user = user
        self.password = password
        self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
        self.password = password
        self.module = sqlmodule
        DBAPI.__init__(self, **kw)
コード例 #3
0
ファイル: mysqlconnection.py プロジェクト: bieschke/nuffle
 def __init__(self, db, user, passwd='', host='localhost', port=None, **kw):
     global MySQLdb
     if MySQLdb is None:
         import MySQLdb
     self.module = MySQLdb
     self.host = host
     self.port = port
     self.db = db
     self.user = user
     self.password = passwd
     self.kw = {}
     for key in ("unix_socket", "named_pipe", "init_command",
             "read_default_file", "read_default_group"):
         if key in kw:
             self.kw[key] = col.popKey(kw, key)
     for key in ("connect_time", "compress", "named_pipe", "use_unicode",
             "client_flag", "local_infile"):
         if key in kw:
             self.kw[key] = int(col.popKey(kw, key))
     DBAPI.__init__(self, **kw)
コード例 #4
0
ファイル: sqliteconnection.py プロジェクト: bieschke/nuffle
    def __init__(self, filename, autoCommit=1, **kw):
        global sqlite
        global using_sqlite2
        if sqlite is None:
            try:
                from pysqlite2 import dbapi2 as sqlite

                using_sqlite2 = True
            except ImportError:
                import sqlite

                using_sqlite2 = False
        self.module = sqlite
        self.filename = filename  # full path to sqlite-db-file
        # connection options
        opts = {}
        if using_sqlite2:
            if autoCommit:
                opts["isolation_level"] = None
            if "encoding" in kw:
                import warnings

                warnings.warn(DeprecationWarning("pysqlite2 does not support the encoding option"))
            opts["detect_types"] = sqlite.PARSE_DECLTYPES
            for col_type in "text", "char", "varchar":
                sqlite.register_converter(col_type, stop_pysqlite2_converting_strings_to_unicode)
                sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings_to_unicode)
        else:
            opts["autocommit"] = autoCommit
            if "encoding" in kw:
                opts["encoding"] = popKey(kw, "encoding")
            if "mode" in kw:
                opts["mode"] = int(popKey(kw, "mode"), 0)
        if "timeout" in kw:
            opts["timeout"] = float(popKey(kw, "timeout"))
        # use only one connection for sqlite - supports multiple)
        # cursors per connection
        self._conn = sqlite.connect(self.filename, **opts)
        DBAPI.__init__(self, **kw)
コード例 #5
0
ファイル: sqliteconnection.py プロジェクト: fregaham/DISP
 def __init__(self, filename, autoCommit=1, **kw):
     global sqlite
     global using_sqlite2
     if sqlite is None:
         try:
             from pysqlite2 import dbapi2 as sqlite
             using_sqlite2 = True
         except ImportError:
             import sqlite
             using_sqlite2 = False
     self.module = sqlite
     self.filename = filename  # full path to sqlite-db-file
     self._memory = filename == ':memory:'
     if self._memory:
         if not using_sqlite2:
             raise ValueError(
                 "You must use sqlite2 to use in-memory databases")
     # connection options
     opts = {}
     if using_sqlite2:
         if autoCommit:
             opts["isolation_level"] = None
         if 'encoding' in kw:
             import warnings
             warnings.warn(DeprecationWarning("pysqlite2 does not support the encoding option"))
         opts["detect_types"] = sqlite.PARSE_DECLTYPES
         for col_type in "text", "char", "varchar":
             sqlite.register_converter(col_type, stop_pysqlite2_converting_strings_to_unicode)
             sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings_to_unicode)
         try:
             from sqlite import encode, decode
         except ImportError:
             import base64
             sqlite.encode = base64.encodestring
             sqlite.decode = base64.decodestring
         else:
             sqlite.encode = encode
             sqlite.decode = decode
         global sqlite2_Binary
         if sqlite2_Binary is None:
             sqlite2_Binary = sqlite.Binary
             sqlite.Binary = lambda s: sqlite2_Binary(sqlite.encode(s))
     else:
         opts['autocommit'] = bool(autoCommit)
         if 'encoding' in kw:
             opts['encoding'] = popKey(kw, 'encoding')
         if 'mode' in kw:
             opts['mode'] = int(popKey(kw, 'mode'), 0)
     if 'timeout' in kw:
         opts['timeout'] = float(popKey(kw, 'timeout'))
     if 'check_same_thread' in kw:
         opts["check_same_thread"] = bool(popKey(kw, 'check_same_thread'))
     # use only one connection for sqlite - supports multiple)
     # cursors per connection
     self._connOptions = opts
     DBAPI.__init__(self, **kw)
     self._threadPool = {}
     self._threadOrigination = {}
     if self._memory:
         self._memoryConn = sqlite.connect(
             self.filename, **self._connOptions)