Update of /cvsroot/jtoolkit/jToolkit/data
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8481
Modified Files:
PyADO.py database.py
Added Files:
_PyADO.py
Log Message:
moved all COM stuff from PyADO into _PyADO (to prepare for doing it in C)
--- NEW FILE: _PyADO.py ---
"""PyADO: a Python Database API driver that wraps around Microsoft ADO
For Python DB-API Reference, see http://www.python.org/topics/database/DatabaseAPI-2.0.html
_PyADO is a module that wraps the COM calls to speed them up
"""
# Copyright 2002, 2003 St James Software
#
# This file is part of jToolkit.
#
# jToolkit is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# jToolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with jToolkit; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import pythoncom
import win32com.client
CoInitialize = win32com.client.pythoncom.CoInitialize
error = pythoncom.error
def makeConn():
try:
Conn = win32com.client.Dispatch("ADODB.Connection")
return Conn
except win32com.client.pythoncom.com_error, com_error:
if com_error.args[0] == 0x800401f0:
# this is the COM not initialized problem
raise WindowsError("COM not initialized")
else:
raise
def makeRS():
return win32com.client.Dispatch("ADODB.Recordset")
Index: PyADO.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/data/PyADO.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** PyADO.py 9 Feb 2004 13:14:29 -0000 1.5
--- PyADO.py 9 Feb 2004 14:03:31 -0000 1.6
***************
*** 21,28 ****
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- import pythoncom
- import win32com.client
from ADOTypes import *
from ADOProviders import *
# TODO:
--- 21,27 ----
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from ADOTypes import *
from ADOProviders import *
+ import _PyADO
# TODO:
***************
*** 35,38 ****
--- 34,40 ----
# --------------------------------------------------------------------
+ CoInitialize = _PyADO.CoInitialize
+ error = _PyADO.error
+
def connect(dsn,user=None,password=None,host=None,database=None,provider=None):
"""Constructor for creating a connection to the database. Returns a Connection Object.
***************
*** 71,75 ****
__init__()
! Initialises the internal connection object using win32com
connect(dsn,user,password,host,database,provider)
open the connection. this is called from the connect function outside this class
--- 73,77 ----
__init__()
! Initialises the internal connection object using _PyADO
connect(dsn,user,password,host,database,provider)
open the connection. this is called from the connect function outside this class
***************
*** 92,104 ****
def __init__(self):
! """Initialises the internal connection object using win32com"""
! try:
! self.Conn = win32com.client.Dispatch("ADODB.Connection")
! except win32com.client.pythoncom.com_error, com_error:
! if com_error.args[0] == 0x800401f0:
! # this is the COM not initialized problem
! raise WindowsError("COM not initialized")
! else:
! raise
def connect(self, dsn,user=None,password=None,host=None,database=None,provider=None):
--- 94,99 ----
def __init__(self):
! """Initialises the internal connection object using _PyADO"""
! self.Conn = _PyADO.makeConn()
def connect(self, dsn,user=None,password=None,host=None,database=None,provider=None):
***************
*** 215,219 ****
"""
def __init__(self, Conn):
! """Initialises the internal Recordset object from the Connection using win32com"""
self.arraysize = 1
self.PassConn = Conn
--- 210,214 ----
"""
def __init__(self, Conn):
! """Initialises the internal Recordset object from the Connection using _PyADO"""
self.arraysize = 1
self.PassConn = Conn
***************
*** 228,232 ****
Parameters may be provided as sequence or mapping
and will be bound to variables in the operation."""
! self.rs = win32com.client.Dispatch("ADODB.Recordset")
self.rsList = [self.rs]
self.rsListPos = 0
--- 223,227 ----
Parameters may be provided as sequence or mapping
and will be bound to variables in the operation."""
! self.rs = _PyADO.makeRS()
self.rsList = [self.rs]
self.rsListPos = 0
***************
*** 346,350 ****
self.rsListPos = 0
for rownumber in range(size):
! rs = win32com.client.Dispatch("ADODB.Recordset")
Query = operation % parameters[rownumber]
rs.Open(Query, ActiveConnection = self.PassConn)
--- 341,345 ----
self.rsListPos = 0
for rownumber in range(size):
! rs = _PyADO.makeRS()
Query = operation % parameters[rownumber]
rs.Open(Query, ActiveConnection = self.PassConn)
Index: database.py
===================================================================
RCS file: /cvsroot/jtoolkit/jToolkit/data/database.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** database.py 9 Feb 2004 13:49:13 -0000 1.14
--- database.py 9 Feb 2004 14:03:31 -0000 1.15
***************
*** 37,42 ****
"""imports the PyADO module. returns module, error class"""
from jToolkit.data import PyADO
! PyADO.win32com.client.pythoncom.CoInitialize()
! return PyADO, PyADO.pythoncom.error
def importpg():
--- 37,42 ----
"""imports the PyADO module. returns module, error class"""
from jToolkit.data import PyADO
! PyADO.CoInitialize()
! return PyADO, PyADO.error
def importpg():
|