Re: OLE DB Consumer Templates

Peter Moss <[email protected]> Thu, 9 Jan 2003 09:57:50 -0500
Newsgroups gmane.comp.windows.devel.oledb.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.

------=_NextPart_000_0012_01C2B7C5.920A8B00
Content-Type: text/plain;
        charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

If I remember right, you can't use the macros for heap-allocated variables.
If you dig into the macro definitions, I believe you will find that pointers
offset from the beginning of 'this' are used.  Thus, a heap-allocated
variable like m_WorkRequest will not work.

Why can't you just allocate a TCHAR on the stack frame of the object, ie,

TCHAR m_WorkRequest[257];     // Or 1 + the size of your SP parameter size

Then you can just use COLUMN_ENTRY.

HTH,
Peter
  -----Original Message-----
  From: OLEDB_DEV [mailto:[email protected]]On Behalf Of Erik
Valdes
  Sent: Wednesday, January 08, 2003 5:22 PM
  To: [email protected]
  Subject: [OLEDB_DEV] OLE DB Consumer Templates


  I'm having trouble implementing an accessor.  I'm trying to use a variable
(m_WorkRequest) that's dynamically allocated as the variable that's bound to
a parameter in my accessor (commented line below).   The reason I need it to
be dynamic is that it is XML and can be any length.  The stored proc's
parameter is of ntext type to handle the variable length.  However, I don't
know at compile time how big to make the buffer for my parameter in my
accessor.  What's the proper way to do this?  I've tried COLUMN_ENTRY
(access violation), COLUMN_ENTRY_LENGTH (different variations produce
different errors, but basically I can't set the length),
COLUMN_ENTRY_TYPE_SIZE (similar problems as the previous).  I'm running out
of ideas now.  The code below is just one of many, many variations I've
tried.





  class CAddWorkRequest

  {

  public:

     CAddWorkRequest() STD_INIT

     ~CAddWorkRequest()

     {

        if (m_WorkRequest)

           delete [] m_WorkRequest;

     }

     LONG m_RETURNVALUE;

     LPTSTR m_WorkRequest;

     LONG m_lLength;



     void SetStringParam(LPCTSTR szString,int cBytes)

     {

        m_WorkRequest = (LPTSTR) new TCHAR[cBytes];

        _tcsncpy(m_WorkRequest,szString,cBytes);

        m_lLength = _tcslen(m_WorkRequest);

     })



  BEGIN_PARAM_MAP(CAddWorkRequest)

     SET_PARAM_TYPE(DBPARAMIO_OUTPUT)

     COLUMN_ENTRY(1, m_RETURNVALUE)

     SET_PARAM_TYPE(DBPARAMIO_INPUT)

  //   COLUMN_ENTRY_TYPE_SIZE(2,DBTYPE_STR,_tcslen(m_WorkRequest),
m_WorkRequest)





  END_PARAM_MAP()



  DEFINE_COMMAND(CAddWorkRequest, _T("{ ? = CALL dbo.AddWorkRequest;1
(?) }"))



  };



  class CAddWorkRequestCommand : public CBsDbCommand<CAddWorkRequest>

  {

  };



  foo (LPTSTR szWor)

  {

              CAddWorkRequestCommand cmd;

              cmd.SetStringParam(szWor,_tcslen(szWor)+1);

  cmd.Open();

  }



  You can read messages from the OLEDB_DEV archive, unsubscribe from
OLEDB_DEV, or subscribe to other DevelopMentor lists at
http://discuss.develop.com.

You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

------=_NextPart_000_0012_01C2B7C5.920A8B00
Content-Type: text/html;
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2722.900" name=3DGENERATOR>
<STYLE>@page Section1 {size: 8.5in 11.0in; margin: 1.0in 1.25in 1.0in =
1.25in; }
P.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
LI.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
DIV.MsoNormal {
        FONT-SIZE: 12pt; MARGIN: 0in 0in 0pt; FONT-FAMILY: "Times New Roman"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: Arial
}
DIV.Section1 {
        page: Section1
}
</STYLE>
</HEAD>
<BODY lang=3DEN-US vLink=3Dpurple link=3Dblue>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =
size=3D2>If I=20
remember right, you can't use the macros for heap-allocated =
variables.&nbsp; If=20
you dig into the macro definitions, I believe you will find that =
pointers offset=20
from the beginning of 'this' are used.&nbsp; Thus, a heap-allocated =
variable=20
like m_WorkRequest will not work.</FONT></SPAN></DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =
size=3D2>Why=20
can't you just allocate a TCHAR on the stack frame of the object,=20
ie,</FONT></SPAN></DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =
size=3D2>TCHAR=20
m_WorkRequest[257];&nbsp;&nbsp;&nbsp;&nbsp; // Or 1 + the size of your =
SP=20
parameter size</FONT></SPAN></DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =
size=3D2>Then=20
you can just use COLUMN_ENTRY.</FONT></SPAN></DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =

size=3D2>HTH,</FONT></SPAN></DIV>
<DIV><SPAN class=3D031385314-09012003><FONT face=3DArial color=3D#0000ff =

size=3D2>Peter</FONT></SPAN></DIV>
<BLOCKQUOTE>
  <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
  size=3D2>-----Original Message-----<BR><B>From:</B> OLEDB_DEV=20
  [mailto:[email protected]]<B>On Behalf Of </B>Erik=20
  Valdes<BR><B>Sent:</B> Wednesday, January 08, 2003 5:22 =
PM<BR><B>To:</B>=20
  [email protected]<BR><B>Subject:</B> [OLEDB_DEV] OLE DB =
Consumer=20
  Templates<BR><BR></FONT></DIV>
  <DIV class=3DSection1>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">I'm having trouble =
implementing an=20
  accessor. &nbsp;I'm trying to use a variable (m_WorkRequest) that's=20
  dynamically allocated as the variable that's bound to a parameter in =
my=20
  accessor (commented line below).&nbsp; &nbsp;The reason I need it to =
be=20
  dynamic is that it is XML and can be any length.&nbsp; The stored =
proc's=20
  parameter is of ntext type to handle the variable length.&nbsp; =
However, I=20
  don't know at compile time how big to make the buffer for my parameter =
in my=20
  accessor.&nbsp; What's the proper way to do this?&nbsp; I've tried=20
  COLUMN_ENTRY (access violation), COLUMN_ENTRY_LENGTH (different =
variations=20
  produce different errors, but basically I can't set the length),=20
  COLUMN_ENTRY_TYPE_SIZE (similar problems as the previous).&nbsp; I'm =
running=20
  out of ideas now.&nbsp; The code below is just one of many, many =
variations=20
  I've tried.</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">class=20
  CAddWorkRequest</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">{</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">public:</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; =
CAddWorkRequest()=20
  STD_INIT</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp;=20
  ~CAddWorkRequest()</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; { =
</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if=20
  (m_WorkRequest)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  delete [] m_WorkRequest;</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; =
}</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; LONG=20
  m_RETURNVALUE;</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; LPTSTR=20
  m_WorkRequest;</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; LONG=20
  m_lLength;</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; void=20
  SetStringParam(LPCTSTR szString,int cBytes)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; =
{</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  m_WorkRequest =3D (LPTSTR) new TCHAR[cBytes];</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  _tcsncpy(m_WorkRequest,szString,cBytes);</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  m_lLength =3D _tcslen(m_WorkRequest);</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; =
})</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">BEGIN_PARAM_MAP(CAddWorkRequest)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp;=20
  SET_PARAM_TYPE(DBPARAMIO_OUTPUT)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp; =
COLUMN_ENTRY(1,=20
  m_RETURNVALUE)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">&nbsp;&nbsp;=20
  SET_PARAM_TYPE(DBPARAMIO_INPUT)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">//&nbsp;&nbsp;=20
  COLUMN_ENTRY_TYPE_SIZE(2,DBTYPE_STR,_tcslen(m_WorkRequest),=20
  m_WorkRequest)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">END_PARAM_MAP()</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: =
Arial">DEFINE_COMMAND(CAddWorkRequest,=20
  _T("{ ? =3D CALL dbo.AddWorkRequest;1 (?) }"))</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial">};</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3DArial size=3D2><SPAN=20
  style=3D"FONT-SIZE: 10pt; FONT-FAMILY: Arial"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt">class CAddWorkRequestCommand : public=20
  CBsDbCommand&lt;CAddWorkRequest&gt;</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt">{</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt">};</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt"></SPAN></FONT>&nbsp;</P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt">foo (LPTSTR szWor)</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt">{</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: =
12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

  CAddWorkRequestCommand cmd;</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: =
12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

  cmd.SetStringParam(szWor,_tcslen(szWor)+1);</SPAN></FONT></P>
  <P class=3DMsoNormal style=3D"TEXT-INDENT: 0.5in"><FONT face=3D"Times =
New Roman"=20
  size=3D3><SPAN style=3D"FONT-SIZE: 12pt">cmd.Open();</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt">}</SPAN></FONT></P>
  <P class=3DMsoNormal><FONT face=3D"Times New Roman" size=3D3><SPAN=20
  style=3D"FONT-SIZE: 12pt"></SPAN></FONT>&nbsp;</P></DIV>You can read =
messages=20
  from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV, or subscribe =
to other=20
  DevelopMentor lists at http://discuss.develop.com. =
</BLOCKQUOTE></BODY></HTML>
You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.

------=_NextPart_000_0012_01C2B7C5.920A8B00--