Python, ADO, VC++ 6

Keith Farmer farmerk at pacbell.net
Mon Jan 8 23:00:59 EST 2001


As described below, the problem seems to have been located.  I have since
changed the relevant code to:

 _bstr_t sql("select count(*) as cnt from ");

 char *table;
 if (!PyArg_ParseTuple(args, "s", &table))
  return NULL;

 sql += table;

 HRESULT   hr  = S_OK;
 _RecordsetPtr Rs1  = NULL;

 _bstr_t Connect("DSN=Astronomy");
 _bstr_t Source(sql);


... I can't seem to access the (traditional) string class, even when
importing <string.h>, which does exist and which VC++ can locate.  I don't
know why this is.  In any case, this code now works and I should be able to
use the _bstr_t objects just fine for what I need them to do.

If anyone has further insights on this, I'd appreciate the clue.  In
particular, I'm wondering what holes I'm leaving open for memory leaks?

Thanks -- Keith

> -----Original Message-----
> From: Beat Bolli (dware) [mailto:beat.bolli at dware.ch]
> Sent: Friday 08 December 2000 07:37
> To: Keith Farmer
> Subject: Re: Python, ADO, VC++ 6
>
>
> [Sorry, was not able to post to the newsgroup, maybe you could
> post this reply for others to read?]
>
>
> > static PyObject *AstroMath_countRows(PyObject *self, PyObject *args)
> > /* ADO example to pass whole SQL clause */
> > {
> >
> > long cnt; /* Define return variable */
> >
> > char *table;
> > if (!PyArg_ParseTuple(args, "s", &table))
> > return NULL;
> >
> > HRESULT hr = S_OK;
> > _RecordsetPtr Rs1 = NULL;
> >
> > _bstr_t Connect("DSN=Astronomy");
> > _bstr_t Source(strcat("select count(*) as cnt from ", table));
>
> You'd have to use something different than strcat here, since in
> overwrites
> whatever lies "after" (at the next higher memory address) the constant
> string "select ...".
>
> #include <string>
>
> ...
>
> string source = "select count(*) as cnt from ";
> source += table;
> _bstr_t Source(source);
>
> or something along these lines... (I'm not up to speed when it
> comes to all
> this OLE stuff... ;-)
>

[snip my included code]

> Beat Bolli
> --
> dware design & software GmbH
> Mattenstrasse 11, CH-2555 Brügg b. Biel
> Telefon: +41 (32) 374 27 00, Telefax: +41 (32) 374 27 01
> E-Mail: beat.bolli at dware.ch
>
>
>
>
>





More information about the Python-list mailing list