Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 20 additions & 66 deletions adodbapi/adodbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/

This module source should run correctly in CPython versions 2.7 and later,
Comment thread
Avasam marked this conversation as resolved.
or IronPython version 2.7 and later,
or, after running through 2to3.py, CPython 3.4 or later.
Comment thread
Avasam marked this conversation as resolved.
Outdated
"""

Expand All @@ -48,45 +47,24 @@

# --- define objects to smooth out IronPython <-> CPython differences
onWin32 = False # assume the worst
if api.onIronPython:
from clr import Reference
from System import (
Activator,
Array,
Byte,
DateTime,
DBNull,
Decimal as SystemDecimal,
Type,
)

def Dispatch(dispatch):
type = Type.GetTypeFromProgID(dispatch)
return Activator.CreateInstance(type)

def getIndexedValue(obj, index):
return obj.Item[index]
try:
import pythoncom
import pywintypes
import win32com.client

else: # try pywin32
try:
import pythoncom
import pywintypes
import win32com.client
onWin32 = True

onWin32 = True
def Dispatch(dispatch):
return win32com.client.Dispatch(dispatch)

def Dispatch(dispatch):
return win32com.client.Dispatch(dispatch)
except ImportError:
import warnings

except ImportError:
import warnings
warnings.warn("pywin32 package required for adodbapi.", ImportWarning)

warnings.warn(
"pywin32 package (or IronPython) required for adodbapi.", ImportWarning
)

def getIndexedValue(obj, index):
return obj(index)
def getIndexedValue(obj, index):
return obj(index)


from collections.abc import Mapping
Expand Down Expand Up @@ -210,12 +188,7 @@ def _configure_parameter(p, value, adotype, settings_known):
p.Size = L # v2.1 Jevon

elif isinstance(value, decimal.Decimal):
if api.onIronPython:
s = str(value)
p.Value = s
p.Size = len(s)
else:
p.Value = value
p.Value = value
exponent = value.as_tuple()[2]
digit_count = len(value.as_tuple()[1])
p.Precision = digit_count
Expand All @@ -238,10 +211,6 @@ def _configure_parameter(p, value, adotype, settings_known):
p.Value = s
p.Size = len(s)

elif api.onIronPython and isinstance(value, longType): # Iron Python Long
s = str(value) # feature workaround for IPy 2.0
p.Value = s

elif adotype == adc.adEmpty: # ADO will not let you specify a null column
p.Type = (
adc.adInteger
Expand Down Expand Up @@ -653,7 +622,7 @@ def build_column_info(self, recordset):
self.numberOfColumns = 0
return
self.rs = recordset # v2.1.1 bkline
self.recordset_format = api.RS_ARRAY if api.onIronPython else api.RS_WIN_32
self.recordset_format = api.RS_WIN_32
self.numberOfColumns = recordset.Fields.Count
try:
varCon = self.connection.variantConversions
Expand Down Expand Up @@ -790,12 +759,7 @@ def _execute_command(self):
print('Executing command="%s"' % self.commandText)
try:
# ----- the actual SQL is executed here ---
if api.onIronPython:
ra = Reference[int]()
recordset = self.cmd.Execute(ra)
count = ra.Value
else: # pywin32
recordset, count = self.cmd.Execute()
recordset, count = self.cmd.Execute()
# ----- ------------------------------- ---
except Exception as e:
_message = ""
Expand Down Expand Up @@ -1180,21 +1144,11 @@ def nextset(self):
)
return None

if api.onIronPython:
try:
recordset = self.rs.NextRecordset()
except TypeError:
recordset = None
except api.Error as exc:
self._raiseCursorError(api.NotSupportedError, exc.args)
else: # pywin32
try: # [begin 2.1 ekelund]
rsTuple = self.rs.NextRecordset() #
except pywintypes.com_error as exc: # return appropriate error
self._raiseCursorError(
api.NotSupportedError, exc.args
) # [end 2.1 ekelund]
recordset = rsTuple[0]
try: # [begin 2.1 ekelund]
rsTuple = self.rs.NextRecordset() #
except pywintypes.com_error as exc: # return appropriate error
self._raiseCursorError(api.NotSupportedError, exc.args) # [end 2.1 ekelund]
recordset = rsTuple[0]
if recordset is None:
return None
self.build_column_info(recordset)
Expand Down
29 changes: 2 additions & 27 deletions adodbapi/apibase.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@

verbose = False # debugging flag

onIronPython = sys.platform == "cli"
if onIronPython: # we need type definitions for odd data we may need to convert
# noinspection PyUnresolvedReferences
from System import DateTime, DBNull

NullTypes = (type(None), DBNull)
else:
DateTime = type(NotImplemented) # should never be seen on win32
NullTypes = type(None)

# --- define objects to smooth out Python3 <-> Python 2.x differences
unicodeType = str
longType = int
Expand All @@ -34,7 +24,7 @@
memoryViewType = memoryview
_BaseException = Exception

try: # jdhardy -- handle bytes under IronPython & Py3
try: # jdhardy -- handle bytes under Py3
bytes
except NameError:
bytes = str # define it for old Pythons
Expand Down Expand Up @@ -283,8 +273,6 @@ def DateObjectFromCOMDate(self, comDate):
new = datetime.datetime.combine(datetime.datetime.fromordinal(odn), tim)
return new
# return comDate.replace(tzinfo=None) # make non aware
elif isinstance(comDate, DateTime):
fComDate = comDate.ToOADate() # ironPython clr Date/Time
else:
fComDate = float(comDate) # ComDate is number of days since 1899-12-31
integerPart = int(fComDate)
Expand Down Expand Up @@ -316,8 +304,6 @@ def DateObjectFromCOMDate(self, comDate):
"Returns ticks since 1970"
if isinstance(comDate, datetime.datetime):
return comDate.timetuple()
elif isinstance(comDate, DateTime): # ironPython clr date/time
fcomDate = comDate.ToOADate()
else:
fcomDate = float(comDate)
secondsperday = 86400 # 24*60*60
Expand Down Expand Up @@ -469,11 +455,6 @@ def variantConvertDate(v):


def cvtString(variant): # use to get old action of adodbapi v1 if desired
if onIronPython:
try:
return variant.ToString()
except:
pass
return str(variant)


Expand Down Expand Up @@ -523,17 +504,11 @@ def identity(x):
def cvtUnusual(variant):
if verbose > 1:
sys.stderr.write("Conversion called for Unusual data=%s\n" % repr(variant))
if isinstance(variant, DateTime): # COMdate or System.Date
from .adodbapi import ( # this will only be called when adodbapi is in use, and very rarely
dateconverter,
)

return dateconverter.DateObjectFromCOMDate(variant)
return variant # cannot find conversion function -- just give the data to the user


def convert_to_python(variant, func): # convert DB value into Python value
if isinstance(variant, NullTypes): # IronPython Null or None
if isinstance(variant, type(None)):
Comment thread
Avasam marked this conversation as resolved.
Outdated
return None
return func(variant) # call the appropriate conversion function

Expand Down
13 changes: 4 additions & 9 deletions adodbapi/is64bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@


def Python():
if sys.platform == "cli": # IronPython
import System

return System.IntPtr.Size == 8
else:
try:
return sys.maxsize > 2147483647
except AttributeError:
return sys.maxint > 2147483647
try:
return sys.maxsize > 2147483647
except AttributeError:
return sys.maxint > 2147483647
Comment thread
Avasam marked this conversation as resolved.
Outdated


def os():
Expand Down
6 changes: 2 additions & 4 deletions adodbapi/quick_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
Adodbapi quick reference
========================

Adodbapi is a Python DB-API 2.0 module that makes it easy to use
Microsoft ADO
for connecting with databases and other data sources
using either CPython or IronPython.
Adodbapi is a Python DB-API 2.0 module that makes it easy to use Microsoft ADO
for connecting with databases and other data sources using CPython.

Source home page:
https://github.com/mhammond/pywin32/tree/master/adodbapi
Expand Down
12 changes: 3 additions & 9 deletions adodbapi/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ Project
adodbapi

A Python DB-API 2.0 (PEP-249) module that makes it easy to use Microsoft ADO
for connecting with databases and other data sources
using either CPython or IronPython.
for connecting with databases and other data sources using CPython.

Home page: <http://sourceforge.net/projects/adodbapi>

Features:
* 100% DB-API 2.0 (PEP-249) compliant (including most extensions and recommendations).
* Includes pyunit testcases that describe how to use the module.
* Fully implemented in Python. -- runs in Python 2.5+ Python 3.0+ and IronPython 2.6+
* Fully implemented in Python. -- runs in Python 2.5+ and Python 3.0+
Comment thread
Avasam marked this conversation as resolved.
Outdated
* Licensed under the LGPL license, which means that it can be used freely even in commercial programs subject to certain restrictions.
* The user can choose between paramstyles: 'qmark' 'named' 'format' 'pyformat' 'dynamic'
* Supports data retrieval by column name e.g.:
Expand All @@ -22,14 +21,9 @@ Features:
Prerequisites:
* C Python 2.7 or 3.5 or higher
and pywin32 (Mark Hammond's python for windows extensions.)
or
Iron Python 2.7 or higher. (works in IPy2.0 for all data types except BUFFER)
Comment thread
Avasam marked this conversation as resolved.

Installation:
* (C-Python on Windows): Install pywin32 ("pip install pywin32") which includes adodbapi.
* (IronPython on Windows): Download adodbapi from http://sf.net/projects/adodbapi. Unpack the zip.
Comment thread
Avasam marked this conversation as resolved.
Open a command window as an administrator. CD to the folder containing the unzipped files.
Run "setup.py install" using the IronPython of your choice.

NOTE: ...........
If you do not like the new default operation of returning Numeric columns as decimal.Decimal,
Expand Down Expand Up @@ -87,6 +81,6 @@ and look at the test cases in adodbapi/test directory.
Mailing lists
-------------
The adodbapi mailing lists have been deactivated. Submit comments to the
pywin32 or IronPython mailing lists.
pywin32 mailing lists.
-- the bug tracker on sourceforge.net/projects/adodbapi may be checked, (infrequently).
-- please use: https://github.com/mhammond/pywin32/issues
1 change: 0 additions & 1 deletion adodbapi/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/

This module source should run correctly in CPython versions 2.5 and later,
or IronPython version 2.7 and later,
Comment thread
Avasam marked this conversation as resolved.
or, after running through 2to3.py, CPython 3.0 or later.
"""

Expand Down
1 change: 0 additions & 1 deletion adodbapi/remote/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
DB-API 2.0 specification: http://www.python.org/dev/peps/pep-0249/

This module source should run correctly in CPython versions 2.6 and later,
or IronPython version 2.6 and later,
or, after running through 2to3.py, CPython 3.2 or later.
"""

Expand Down
1 change: 0 additions & 1 deletion adodbapi/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""adodbapi -- a pure Python PEP 249 DB-API package using Microsoft ADO

Adodbapi can be run on CPython 3.5 and later.
or IronPython version 2.6 and later (in theory, possibly no longer in practice!)
"""
CLASSIFIERS = """\
Development Status :: 5 - Production/Stable
Expand Down
13 changes: 4 additions & 9 deletions adodbapi/test/is64bit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@


def Python():
if sys.platform == "cli": # IronPython
import System

return System.IntPtr.Size == 8
else:
try:
return sys.maxsize > 2147483647
except AttributeError:
return sys.maxint > 2147483647
try:
return sys.maxsize > 2147483647
except AttributeError:
return sys.maxint > 2147483647


def os():
Expand Down
9 changes: 3 additions & 6 deletions adodbapi/test/setuptestframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,9 @@ def makemdb(testfolder, mdb_name):
from win32com.client.gencache import EnsureDispatch

win32 = True
except ImportError: # perhaps we are running IronPython
Comment thread
Avasam marked this conversation as resolved.
win32 = False # iron Python
try:
from System import Activator, Type
except:
pass
except ImportError:
win32 = False # assume the worst
pass

# Create a brand-new database - what is the story with these?
dbe = None
Expand Down