Re: OLE DB Consumer Templates

Erik Valdes <[email protected]> Thu, 9 Jan 2003 09:21:31 -0700
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_01C2B7FB.2BA393D0
Content-Type: text/plain

The reason I can't allocate on the stack is that my variable can be any
length.  It essentially boils down to the string representation of an xml
file.  That file can be any size.  When I pass it to my SP, the sp's
parameter is ntext (to allow for any size).   What do people do when they
want to pass XML of unknown length to a SQL Server stored procedure?



-----Original Message-----
From: Peter Moss [mailto:[email protected]]
Sent: Thursday, January 09, 2003 7:58 AM
To: [email protected]
Subject: Re: [OLEDB_DEV] OLE DB Consumer Templates



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.

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_01C2B7FB.2BA393D0
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">


<meta name=Generator content="Microsoft Word 10 (filtered)">

<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* 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;}
span.EmailStyle18
        {font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>The reason I can't allocate on the
stack is that my variable can be any length.&nbsp; It essentially boils down to
the string representation of an xml file. &nbsp;That file can be any
size.&nbsp; When I pass it to my SP, the sp's parameter is ntext (to
allow for any size).&nbsp;&nbsp; What do people do when they want to pass XML
of unknown length to a SQL Server stored procedure?</span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma'>-----Original Message-----<br>
<b><span style='font-weight:bold'>From:</span></b> Peter Moss
[mailto:[email protected]] <br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, January 09, 2003
7:58 AM<br>
<b><span style='font-weight:bold'>To:</span></b> [email protected]<br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [OLEDB_DEV] OLE DB
Consumer Templates</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:blue'>If I remember right, you
can't use the macros for heap-allocated variables.&nbsp; If you dig into the
macro definitions, I believe you will find that pointers offset from the
beginning of 'this' are used.&nbsp; Thus, a heap-allocated variable like
m_WorkRequest will not work.</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:blue'>Why can't you just
allocate a TCHAR on the stack frame of the object, ie,</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:blue'>TCHAR
m_WorkRequest[257];&nbsp;&nbsp;&nbsp;&nbsp; // Or 1 + the size of your SP
parameter size</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:blue'>Then you can just use
COLUMN_ENTRY.</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:blue'>HTH,</span></font></p>

</div>

<div>

<p class=MsoNormal style='margin-left:.5in'><font size=2 color=blue face=Arial><span
style='font-size:10.0pt;font-family:Arial;color:blue'>Peter</span></font></p>

</div>

<blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'>

<p class=MsoNormal style='margin-right:0in;margin-bottom:12.0pt;margin-left:
.5in'><font size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'>-----Original
Message-----<br>
<b><span style='font-weight:bold'>From:</span></b> OLEDB_DEV
[mailto:[email protected]]<b><span style='font-weight:bold'>On
Behalf Of </span></b>Erik Valdes<br>
<b><span style='font-weight:bold'>Sent:</span></b> Wednesday, January 08, 2003
5:22 PM<br>
<b><span style='font-weight:bold'>To:</span></b> [email protected]<br>
<b><span style='font-weight:bold'>Subject:</span></b> [OLEDB_DEV] OLE DB
Consumer Templates</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;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 style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>class CAddWorkRequest</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>{</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>public:</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; CAddWorkRequest()
STD_INIT</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; ~CAddWorkRequest()</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; { </span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
(m_WorkRequest)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
delete [] m_WorkRequest;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; }</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; LONG m_RETURNVALUE;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; LPTSTR m_WorkRequest;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; LONG m_lLength;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; void
SetStringParam(LPCTSTR szString,int cBytes)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; {</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
m_WorkRequest = (LPTSTR) new TCHAR[cBytes];</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_tcsncpy(m_WorkRequest,szString,cBytes);</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
m_lLength = _tcslen(m_WorkRequest);</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; })</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>BEGIN_PARAM_MAP(CAddWorkRequest)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; SET_PARAM_TYPE(DBPARAMIO_OUTPUT)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp; COLUMN_ENTRY(1,
m_RETURNVALUE)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>&nbsp;&nbsp;
SET_PARAM_TYPE(DBPARAMIO_INPUT)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>//&nbsp;&nbsp;
COLUMN_ENTRY_TYPE_SIZE(2,DBTYPE_STR,_tcslen(m_WorkRequest), m_WorkRequest)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>END_PARAM_MAP()</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>DEFINE_COMMAND(CAddWorkRequest, _T(&quot;{
? = CALL dbo.AddWorkRequest;1 (?) }&quot;))</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=2 face=Arial><span
style='font-size:10.0pt;font-family:Arial'>};</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>class CAddWorkRequestCommand : public
CBsDbCommand&lt;CAddWorkRequest&gt;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>{</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>};</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>foo (LPTSTR szWor)</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>{</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
CAddWorkRequestCommand cmd;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size: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 style='margin-left:.5in;text-indent:.5in'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>cmd.Open();</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>}</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>&nbsp;</span></font></p>

<p class=MsoNormal style='margin-left:.5in'><font size=3 face="Times New Roman"><span
style='font-size:12.0pt'>You can read messages from the OLEDB_DEV archive,
unsubscribe from OLEDB_DEV, or subscribe to other DevelopMentor lists at
http://discuss.develop.com. </span></font></p>

</blockquote>

</div>

</body>

</html>
You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
You can read messages from the OLEDB_DEV archive, unsubscribe from OLEDB_DEV,
or subscribe to other DevelopMentor lists at http://discuss.develop.com.
or subscribe to other DevelopMentor lists at http://discuss.develop.com.
------_=_NextPart_001_01C2B7FB.2BA393D0--