By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,915 Members | 1,345 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,915 IT Pros & Developers. It's quick & easy.

assigning a string, with embedded nulls, to an ADO variant_t parm

P: n/a
I am a newbie to c++, so maybe this one's too easy, tho apparently not
for me:

1. I am using MS Visual Studio.

2. I have a std::string variable.

3. Its value might contain embedded null chars.

4. I want to insert/update it in an ADO parameter to be presented to
an SQL statement, one whose CommandText is something such as:

Select * from mytable where key = ?

So my q is, how do I convert it from its current string format into
something that ADO (i.,e. Command>-Parameter->Item[n]->Value will
accept?

I can't assign it directly, that doesn't even compile. I can't use
c_str() or any other function that employs a char * argument because
of the embedded nulls in the data, and when I try to use an
intermediate _bstr_t wrapper, the data seems to turn up garbled (can I
assume that's a single- vs double- byte problem?)

Anyway, thx if anyone can help; hope this is the correct group for
such a q.

Aug 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"A SQL newsgroup is probably a better place for this question."

Possibly; I hadn't thought of it in those terms.

As to reading up about _variant_t, I have, and the prob is not that it
can't hold such a value, at least as near as I can tell, but that I
can't see how to assign it such a value in the first place. That would
be a good first step in determining how well it can or can't handle
it, but I haven't got past that first step yet and ... well, and here
we are.

My prob is taken from an existing system, btw, one that already
handles it (using VFP, as it happens), incl'ing the binary char data
and everything, and it works just fine, and now we want it to work
using C++/ADO, too, on a variety of databases.

Aug 28 '07 #2

P: n/a
<lo*********@yahoo.cawrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
>
"A SQL newsgroup is probably a better place for this question."

Possibly; I hadn't thought of it in those terms.

As to reading up about _variant_t, I have, and the prob is not that it
can't hold such a value, at least as near as I can tell, but that I
can't see how to assign it such a value in the first place. That would
be a good first step in determining how well it can or can't handle
it, but I haven't got past that first step yet and ... well, and here
we are.

My prob is taken from an existing system, btw, one that already
handles it (using VFP, as it happens), incl'ing the binary char data
and everything, and it works just fine, and now we want it to work
using C++/ADO, too, on a variety of databases.
Okay, looking at _variant_t it is a microsoft class. Try a microsoft
newsgroup maybe.
Aug 28 '07 #3

P: n/a

<lo*********@yahoo.cawrote in message...
I am a newbie to c++, so maybe this one's too easy, tho apparently not
for me:

1. I am using MS Visual Studio.
So sorry. You could fix that. (GCC MinGW)
>
2. I have a std::string variable.
3. Its value might contain embedded null chars.
#include <iostream>
#include <string>
#include <vector>

void CharDummy( char const *in, size_t sz ){
// do stuff with array 'in'
}

int main(){
std::string LongLineGoneBad(
"Say hello to the problem\0 in this line.");
std::cout<<"LongLineGoneBad.size()="
<<LongLineGoneBad.size()<<std::endl;
std::cout<<"LongLineGoneBad="<<LongLineGoneBad<<st d::endl;

char const LongLineArray[]=("Say hello to the problem\0 in this line.");
std::cout<<"sizeof(LongLineArray)="
<<sizeof(LongLineArray)<<std::endl;

std::vector<charvLine( LongLineArray,
LongLineArray + sizeof(LongLineArray) );
std::cout<<"vLine.size()="<<vLine.size()<<std::end l;

CharDummy( &vLine.at(0), vLine.size() );

return 0;
} // main()
/* -output-
LongLineGoneBad.size()=24
LongLineGoneBad=Say hello to the problem
sizeof(LongLineArray)=40
vLine.size()=40
*/

Try it and see if you get the same results.

--
Bob R
POVrookie
Aug 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.