473,834 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1916

"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*********@ya hoo.cawrote in message
news:11******** **************@ i13g2000prf.goo glegroups.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*********@ya hoo.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<<"Lon gLineGoneBad.si ze()="
<<LongLineGoneB ad.size()<<std: :endl;
std::cout<<"Lon gLineGoneBad="< <LongLineGoneBa d<<std::endl;

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

std::vector<cha rvLine( LongLineArray,
LongLineArray + sizeof(LongLine Array) );
std::cout<<"vLi ne.size()="<<vL ine.size()<<std ::endl;

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

return 0;
} // main()
/* -output-
LongLineGoneBad .size()=24
LongLineGoneBad =Say hello to the problem
sizeof(LongLine Array)=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
808
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 .txt-file in which the data is structured in that way: Project-Nr. ID name lastname 33 9 Lars Lundel 33 12 Emil Korla
17
3864
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 string-Class similar to the STL-<string> that supports null-bytes? I tried with standard <string> but this definitely does not support
10
4479
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 Enterplise Linux 3 ES, and applied FixPack fp5_mi00069.tar to it. After creating an instance, starting the database, creating a database, and entering the table definitions, all of which seems to work OK, I entered a tiny 8-row table and can do...
9
5717
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
9996
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 the program. Since fgets() doesn't return the number of characters read it is pretty tough to handle the embedded nulls once they are in the buffer. So two questions: 1. Why did the folks who wrote fgets() have a successful
5
15919
by: Torben Laursen | last post by:
Hi Can anyone show me how to convert between VARIANT and std::string and back, thanks! Torben ---
3
1935
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 that's written to disk in a binary format. Basically it's a bunch of records, one after the other, where each record has the following format : 18 bytes, 6 bytes which are all zero, 4 bytes which represent a UInt32. The first 18 bytes of each...
25
12959
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 have new partition(sep) and rpartition(sep) methods that simplify a common use case. The find(S) method is often used to get an index which is then used to slice the string and obtain the pieces that are before and after the separator....
13
3339
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 these arrays but can't use strlen because it just stops counting at the first null it finds. so how to do it? Angus
0
9796
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10500
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9323
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4422
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3972
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.