473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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
3 1894

"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
<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

<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Kai Jaensch | last post by:
Hello, i am an newbie and i have to to solve this problem as fast as i can. But at this time i don´t have a lot of success. Can anybody help me (and understand my english :-))? I have a...
17
by: Karl Ebener | last post by:
Hi! I asked a similar question before but then changed everything to using char-Arrays instead of the string class, but I would rather not do this again. So, does anyone know of a...
10
by: Jean-David Beyer | last post by:
I have some programs running on Red Hat Linux 7.3 working with IBM DB2 V6.1 (with all the FixPacks) on my old machine. I have just installed IBM DB2 V8.1 on this (new) machine running Red Hat...
9
by: Danny | last post by:
HI again Is there a nifty function in access that will: 1. return the amount of occurances of a small string within a larger string? this<br>is<br>a<br>test would return 3 for <br>
35
by: David Mathog | last post by:
Every so often one of my fgets() based programs encounters an input file containing embedded nulls. fgets is happy to read these but the embedded nulls subsequently cause problems elsewhere in...
5
by: Torben Laursen | last post by:
Hi Can anyone show me how to convert between VARIANT and std::string and back, thanks! Torben ---
3
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
25
by: John Salerno | last post by:
Forgive my excitement, especially if you are already aware of this, but this seems like the kind of feature that is easily overlooked (yet could be very useful): Both 8-bit and Unicode strings...
13
by: Angus | last post by:
Hello I have a stream of bytes - unsigned char*. But the 'string' may contain embedded nulls. So not like a traditional c string terminated with a null. I need to calculate the length of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.