Re: OLE DB Consumer Templates

Kjell Arild Tangen <[email protected]> Thu, 9 Jan 2003 06:59:30 +0100
Newsgroups gmane.comp.windows.devel.oledb.devel
Message-ID <[email protected]>
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

------_=_NextPart_001_01C2B7A4.464C99E0
Content-Type: text/plain

You can use the the COLUMN_ENTRY_TYPE_SIZE macro, but the size must refer to a member variable that contains the size, e.g.

COLUMN_ENTRY_TYPE_SIZE(2,DBTYPE_STR,m_lWorkRequestLen, m_WorkRequest)

What you need to do before the command is executed is to set the variable to the length of the buffer that holds the corresponding value.

Regards,
Kjell Tangen

-----Original Message-----
From: Erik Valdes [mailto:[email protected]]
Sent: 8. januar 2003 23:22
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_001_01C2B7A4.464C99E0
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<DEFANGED_META
CONTENT="text/html; charset=us-ascii" HTTP-EQUIV="Content-Type"><DEFANGED_META
content="Microsoft Word 10 (filtered)" name="Generator"><!-- <DEFANGED_STYLE>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
<META content="MSHTML 6.00.2600.0" name=GENERATOR></HEAD>
<BODY lang=EN-US vLink=purple link=blue>
<DIV><SPAN class=587365205-09012003><FONT face=Arial color=#0000ff size=2>You
can use the the COLUMN_ENTRY_TYPE_SIZE macro, but the size must refer to a
member variable that contains the size, e.g.</FONT></SPAN></DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial color=#0000ff
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial
size=2>COLUMN_ENTRY_TYPE_SIZE(2,DBTYPE_STR,m_lWorkRequestLen,
m_WorkRequest)</FONT></SPAN></DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial size=2>What you need to do
before the command is executed is to set the variable to the length of the
buffer that holds the corresponding value.</FONT></SPAN></DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial
size=2>Regards,</FONT></SPAN></DIV>
<DIV><SPAN class=587365205-09012003><FONT face=Arial size=2>Kjell
Tangen</FONT></SPAN></DIV>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
  <DIV></DIV>
  <DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left><FONT
  face=Tahoma size=2>-----Original Message-----<BR><B>From:</B> Erik Valdes
  [mailto:[email protected]] <BR><B>Sent:</B> 8. januar 2003
  23:22<BR><B>To:</B> [email protected]<BR><B>Subject:</B>
  [OLEDB_DEV] OLE DB Consumer Templates<BR><BR></FONT></DIV>--&gt;
  </DEFANGED_STYLE>
  <DIV class=Section1>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">I'm having
  trouble implementing an accessor. &nbsp;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).&nbsp; &nbsp;The reason I need
  it to be dynamic is that it is XML and can be any length.&nbsp; The stored
  proc's parameter is of ntext type to handle the variable length.&nbsp;
  However, I don't know at compile time how big to make the buffer for my
  parameter in my accessor.&nbsp; What's the proper way to do this?&nbsp; 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).&nbsp; I'm running
  out of ideas now.&nbsp; The code below is just one of many, many variations
  I've tried.</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">class
  CAddWorkRequest</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">{</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">public:</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  CAddWorkRequest() STD_INIT</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  ~CAddWorkRequest()</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp; {
  </SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  if (m_WorkRequest)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  delete [] m_WorkRequest;</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  }</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  LONG m_RETURNVALUE;</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  LPTSTR m_WorkRequest;</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  LONG m_lLength;</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  void SetStringParam(LPCTSTR szString,int cBytes)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  {</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  m_WorkRequest = (LPTSTR) new TCHAR[cBytes];</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  _tcsncpy(m_WorkRequest,szString,cBytes);</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  m_lLength = _tcslen(m_WorkRequest);</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  })</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">BEGIN_PARAM_MAP(CAddWorkRequest)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  SET_PARAM_TYPE(DBPARAMIO_OUTPUT)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  COLUMN_ENTRY(1, m_RETURNVALUE)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">&nbsp;&nbsp;
  SET_PARAM_TYPE(DBPARAMIO_INPUT)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">//&nbsp;&nbsp;
  COLUMN_ENTRY_TYPE_SIZE(2,DBTYPE_STR,_tcslen(m_WorkRequest),
  m_WorkRequest)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">END_PARAM_MAP()</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">DEFINE_COMMAND(CAddWorkRequest,
  _T("{ ? = CALL dbo.AddWorkRequest;1 (?) }"))</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial">};</SPAN></FONT></P>
  <P class=MsoNormal><FONT face=Arial size=2><SPAN
  DEFANGED_STYLE="font-size:10.0pt;&#13;&#10;font-family:Arial"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">class CAddWorkRequestCommand :
  public CBsDbCommand&lt;CAddWorkRequest&gt;</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">{</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">};</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt"></SPAN></FONT>&nbsp;</P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">foo (LPTSTR
  szWor)</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">{</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  CAddWorkRequestCommand cmd;</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  cmd.SetStringParam(szWor,_tcslen(szWor)+1);</SPAN></FONT></P>
  <P class=MsoNormal DEFANGED_STYLE="text-indent:.5in"><FONT
  face="Times New Roman" size=3><SPAN
  style="FONT-SIZE: 12pt">cmd.Open();</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt">}</SPAN></FONT></P>
  <P class=MsoNormal><FONT face="Times New Roman" size=3><SPAN
  DEFANGED_STYLE="font-size:&#13;&#10;12.0pt"></SPAN></FONT>&nbsp;</P></DIV>You
  can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV, or
  subscribe to other 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_001_01C2B7A4.464C99E0--