Example #1
0
def makemdb(testfolder, mdb_name):
    # following setup code borrowed from pywin32 odbc test suite
    # kindly contributed by Frank Millman.
    import os

    _accessdatasource = os.path.join(testfolder, mdb_name)
    if os.path.isfile(_accessdatasource):
        print("using JET database=", _accessdatasource)
    else:
        try:
            from win32com.client.gencache import EnsureDispatch
            from win32com.client import constants

            win32 = True
        except ImportError:  # perhaps we are running IronPython
            win32 = False  # iron Python
            try:
                from System import Activator, Type
            except:
                pass

        # Create a brand-new database - what is the story with these?
        dbe = None
        for suffix in (".36", ".35", ".30"):
            try:
                if win32:
                    dbe = EnsureDispatch("DAO.DBEngine" + suffix)
                else:
                    type = Type.GetTypeFromProgID("DAO.DBEngine" + suffix)
                    dbe = Activator.CreateInstance(type)
                break
            except:
                pass
        if dbe:
            print("    ...Creating ACCESS db at " + _accessdatasource)
            if win32:
                workspace = dbe.Workspaces(0)
                newdb = workspace.CreateDatabase(
                    _accessdatasource, constants.dbLangGeneral, constants.dbVersion40
                )
            else:
                newdb = dbe.CreateDatabase(
                    _accessdatasource, ";LANGID=0x0409;CP=1252;COUNTRY=0"
                )
            newdb.Close()
        else:
            print("    ...copying test ACCESS db to " + _accessdatasource)
            mdbName = os.path.abspath(
                os.path.join(os.path.dirname(__file__), "..", "examples", "test.mdb")
            )
            import shutil

            shutil.copy(mdbName, _accessdatasource)

    return _accessdatasource
Example #2
0
def makemdb(testfolder):
    # following setup code borrowed from pywin32 odbc test suite
    # kindly contributed by Frank Millman.
    import tempfile
    import os

    _accessdatasource = tempfile.mktemp(suffix='.mdb',
                                        prefix='ado_test_',
                                        dir=testfolder)
    if os.path.isfile(_accessdatasource):
        os.unlink(_accessdatasource)
    try:
        from win32com.client.gencache import EnsureDispatch
        from win32com.client import constants
        win32 = True
    except ImportError:  #perhaps we are running IronPython
        win32 = False  #iron Python
        from System import Activator, Type

    # Create a brand-new database - what is the story with these?
    dbe = None
    for suffix in (".36", ".35", ".30"):
        try:
            if win32:
                dbe = EnsureDispatch("DAO.DBEngine" + suffix)
            else:
                type = Type.GetTypeFromProgID("DAO.DBEngine" + suffix)
                dbe = Activator.CreateInstance(type)
            break
        except:
            pass
    if dbe:
        print(('    ...Creating ACCESS db at ' + _accessdatasource))
        if win32:
            workspace = dbe.Workspaces(0)
            newdb = workspace.CreateDatabase(_accessdatasource,
                                             constants.dbLangGeneral,
                                             constants.dbEncrypt)
        else:
            newdb = dbe.CreateDatabase(_accessdatasource,
                                       ';LANGID=0x0409;CP=1252;COUNTRY=0')
        newdb.Close()
    else:
        print(('    ...copying test ACCESS db to ' + _accessdatasource))
        mdbName = os.path.normpath(os.getcwd() + '/../examples/test.mdb')
        import shutil
        shutil.copy(mdbName, _accessdatasource)

    return _accessdatasource
Example #3
0
                else:
                    type = Type.GetTypeFromProgID("DAO.DBEngine" + suffix)
                    dbe = Activator.CreateInstance(type)
                break
            except:
                pass
        else:
            raise RuntimeError("Can't find a DB engine")
        print '    ...Creating ACCESS db at', _accessdatasource
        if win32:
            workspace = dbe.Workspaces(0)
            newdb = workspace.CreateDatabase(_accessdatasource,
                                             constants.dbLangGeneral,
                                             constants.dbEncrypt)
        else:
            newdb = dbe.CreateDatabase(_accessdatasource,
                                       ';LANGID=0x0409;CP=1252;COUNTRY=0')
        newdb.Close()
    connStrAccess = r"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _accessdatasource

if doSqlServerTest:
    _computername = r".\SQLEXPRESS"  #or name of computer with SQL Server
    _databasename = "Northwind"  #or something else
    #_username="******"
    #_password="******"
    connStrSQLServer = r"Provider=SQLOLEDB.1; Integrated Security=SSPI; Initial Catalog=%s;Data Source=%s" % (
        _databasename, _computername)
    #connStrSQLServer = r"Provider=SQLOLEDB.1; User ID=%s; Password=%s; Initial Catalog=%s;Data Source=%s" %(_username,_password,_databasename, _computername)
    print '    ...Testing MS-SQL login...'
    try:
        s = adodbapi.connect(connStrSQLServer)  #connect to server
        s.close()