Concept Error

chris lyon chris.lyon at spritenote.co.uk
Sun Jul 7 05:28:51 EDT 2002


Apologies the variable 'a' below should be 'conn'

"chris lyon" <chris.lyon at spritenote.co.uk> wrote in message
news:3d27d274$0$24427$afc38c87 at news.easynet.co.uk...
> I've been at it all night and I don't understand why this does work:-
> (Its derived from www.e-coli.net/pyado.html , ok it's a straight copy )
>
>
> import win32com.client
>
> class RecordSet:
>     def __init__(self, DBConnection):
>         """Initialize a Record Set Object"""
>         self.rs = win32com.client.Dispatch(r'ADODB.Recordset')
>         self.conn = DBConnection
>
>     def listfields(self):
>         for x in range (self.rs.Fields.Count):
>             print 'Name:-',self.rs.Fields.Item(x).Name
>             print 'DefinedSize:-',self.rs.Fields.Item(x).DefinedSize
>             print 'Type:-',self.rs.Fields.Item(x).Type
>             print 'Value:-',self.rs.Fields.Item(x).Value
>
> conn = win32com.client.Dispatch(r'ADODB.Connection')
> DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:/octavia/c4i.mdb;'
> conn.Open(DSN)
>
>  fred = RecordSet(a)
>  fred.rs.CursorLocation = 3
>  fred.rs.Open('[Categories]',a.conn,1,3)
>  fred.listfields()
>
>
>
> But this fails to run.
>
> import win32com.client
>
> class RecordSet:
>     def __init__(self, DBConnection):
>         """Initialize a Record Set Object"""
>         self.rs = win32com.client.Dispatch(r'ADODB.Recordset')
>         self.conn = DBConnection
>
>     def listfields(self):
>         for x in range (self.rs.Fields.Count):
>             print 'Name:-',self.rs.Fields.Item(x).Name
>             print 'DefinedSize:-',self.rs.Fields.Item(x).DefinedSize
>             print 'Type:-',self.rs.Fields.Item(x).Type
>             print 'Value:-',self.rs.Fields.Item(x).Value
>
>     def getalltable(self , tablename, conn):
>         self.rs.CursorLocation = 3      #adUseClient
>         self.rs.Open('[Categories]', conn , 1 ,3)   #adOpenKeySet
> adLockOptimistic
>
> conn = win32com.client.Dispatch(r'ADODB.Connection')
> DSN = 'PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=c:/octavia/c4i.mdb;'
> conn.Open(DSN)
>
> fred = RecordSet(a)
> fred.rs.CursorLocation = 3
> fred.getalltable('Categories', a)
> fred.listfields()
>
>
> It Fails with:-
>
>   File
>
"C:\Python21\win32com\gen_py\00000205-0000-0010-8000-00AA006D2EA4x0x2x5.py",
> line 2008, in Open
>     return self._oleobj_.InvokeTypes(0x3fe, LCID, 1, (24, 0), ((12, 17),
> (12, 17), (3, 49), (3, 49), (3, 49)),Source, ActiveConnection, CursorType,
> LockType, Options)
> TypeError: Objects for SAFEARRAYS must be sequences (of sequences), or a
> buffer object.
>
> Why can't I just treat rs as a property of the class RecordSet ?
> Obviously I can get functionality I require but I do not understand why I
> can't treat the RecordSet this way.
>
> I've examined as much of the underlying code as I can but I'm quickly
lost,
> and I notice that win32com.client.Dispatch is a function not a class so I
> can't sub-class it so that way seems closed.
>
> It feels that I am missunderstanding some aspect of the class mechanism so
I
> would dearly like to know what I'm doing wrong.
>
> ( And I will NOT write this app in VBScript :-)
>
> Chris Lyon
>
>
>
>
>
>





More information about the Python-list mailing list