File size: 6,112 Bytes
375a1cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
print("This module depends on the dbapi20 compliance tests created by Stuart Bishop")
print("(see db-sig mailing list history for info)")
import platform
import sys
import unittest

import dbapi20
import setuptestframework

testfolder = setuptestframework.maketemp()
if "--package" in sys.argv:
    pth = setuptestframework.makeadopackage(testfolder)
    sys.argv.remove("--package")
else:
    pth = setuptestframework.find_ado_path()
if pth not in sys.path:
    sys.path.insert(1, pth)
# function to clean up the temporary folder -- calling program must run this function before exit.
cleanup = setuptestframework.getcleanupfunction()

import adodbapi
import adodbapi.is64bit as is64bit

db = adodbapi

if "--verbose" in sys.argv:
    db.adodbapi.verbose = 3

print(adodbapi.version)
print("Tested with dbapi20 %s" % dbapi20.__version__)

try:
    onWindows = bool(sys.getwindowsversion())  # seems to work on all versions of Python
except:
    onWindows = False

node = platform.node()

conn_kws = {}
host = "testsql.2txt.us,1430"  # if None, will use macro to fill in node name
instance = r"%s\SQLEXPRESS"
conn_kws["name"] = "adotest"

conn_kws["user"] = "adotestuser"  # None implies Windows security
conn_kws["password"] = "Sq1234567"
# macro definition for keyword "security" using macro "auto_security"
conn_kws["macro_auto_security"] = "security"

if host is None:
    conn_kws["macro_getnode"] = ["host", instance]
else:
    conn_kws["host"] = host

conn_kws[
    "provider"
] = "Provider=MSOLEDBSQL;DataTypeCompatibility=80;MARS Connection=True;"
connStr = "%(provider)s; %(security)s; Initial Catalog=%(name)s;Data Source=%(host)s"

if onWindows and node != "z-PC":
    pass  # default should make a local SQL Server connection
elif node == "xxx":  # try Postgres database
    _computername = "25.223.161.222"
    _databasename = "adotest"
    _username = "adotestuser"
    _password = "12345678"
    _driver = "PostgreSQL Unicode"
    _provider = ""
    connStr = "%sDriver={%s};Server=%s;Database=%s;uid=%s;pwd=%s;" % (
        _provider,
        _driver,
        _computername,
        _databasename,
        _username,
        _password,
    )
elif node == "yyy":  # ACCESS data base is known to fail some tests.
    if is64bit.Python():
        driver = "Microsoft.ACE.OLEDB.12.0"
    else:
        driver = "Microsoft.Jet.OLEDB.4.0"
    testmdb = setuptestframework.makemdb(testfolder)
    connStr = r"Provider=%s;Data Source=%s" % (driver, testmdb)
else:  # try a remote connection to an SQL server
    conn_kws["proxy_host"] = "25.44.77.176"
    import adodbapi.remote

    db = adodbapi.remote

print("Using Connection String like=%s" % connStr)
print("Keywords=%s" % repr(conn_kws))


class test_adodbapi(dbapi20.DatabaseAPI20Test):
    driver = db
    connect_args = (connStr,)
    connect_kw_args = conn_kws

    def __init__(self, arg):
        dbapi20.DatabaseAPI20Test.__init__(self, arg)

    def getTestMethodName(self):
        return self.id().split(".")[-1]

    def setUp(self):
        # Call superclass setUp In case this does something in the
        # future
        dbapi20.DatabaseAPI20Test.setUp(self)
        if self.getTestMethodName() == "test_callproc":
            con = self._connect()
            engine = con.dbms_name
            ## print('Using database Engine=%s' % engine) ##
            if engine != "MS Jet":
                sql = """

                    create procedure templower

                        @theData varchar(50)

                    as

                        select lower(@theData)

                """
            else:  # Jet
                sql = """

                    create procedure templower

                        (theData varchar(50))

                    as

                        select lower(theData);

                """
            cur = con.cursor()
            try:
                cur.execute(sql)
                con.commit()
            except:
                pass
            cur.close()
            con.close()
            self.lower_func = "templower"

    def tearDown(self):
        if self.getTestMethodName() == "test_callproc":
            con = self._connect()
            cur = con.cursor()
            try:
                cur.execute("drop procedure templower")
            except:
                pass
            con.commit()
        dbapi20.DatabaseAPI20Test.tearDown(self)

    def help_nextset_setUp(self, cur):
        "Should create a procedure called deleteme"
        'that returns two result sets, first the number of rows in booze then "name from booze"'
        sql = """

            create procedure deleteme as

            begin

                select count(*) from %sbooze

                select name from %sbooze

            end

        """ % (
            self.table_prefix,
            self.table_prefix,
        )
        cur.execute(sql)

    def help_nextset_tearDown(self, cur):
        "If cleaning up is needed after nextSetTest"
        try:
            cur.execute("drop procedure deleteme")
        except:
            pass

    def test_nextset(self):
        con = self._connect()
        try:
            cur = con.cursor()

            stmts = [self.ddl1] + self._populate()
            for sql in stmts:
                cur.execute(sql)

            self.help_nextset_setUp(cur)

            cur.callproc("deleteme")
            numberofrows = cur.fetchone()
            assert numberofrows[0] == 6
            assert cur.nextset()
            names = cur.fetchall()
            assert len(names) == len(self.samples)
            s = cur.nextset()
            assert s == None, "No more return sets, should return None"
        finally:
            try:
                self.help_nextset_tearDown(cur)
            finally:
                con.close()

    def test_setoutputsize(self):
        pass


if __name__ == "__main__":
    unittest.main()
    cleanup(testfolder, None)