Ingres Community Forums Login Register Ingres.com  

Ingres Community Forum



Reply
 
LinkBack (1) Thread Tools Display Modes
Old 2008-11-19   1 links from elsewhere to this Post. Click to view. #1 (permalink)
Junior Member
 
schma01's Avatar
 
Join Date: Jun 2007
Location: Dallas Texas
Posts: 4
Question Using OpenAPI in C++

I'm using the OpenAPI in a C++ program. My C++ program uses alot of "string" datatypes.

I'm trying to get my username and password from string variables into my IIAPI_CONNPARM.co_username and IIAPI_CONNPARM.co_password which are character pointers. Neither strcpy or ='s works, expectedly, as I have mismatched datatypes.

This may be a C++ question more than an OpenAPI question, but I'm hoping someone can help me populate this.

//code snippet

string user;
...
iiConn.co_username = user; // doesn't compile, cant convert string to char* in assignment
strcpy(iiConn.co_username, user); // doesn't compile either
...
IIapi_connect (&iiConn);
...

Is there some casting function out there. I'm not that familiar w/ C++ and I've been unable surfing for an answer.

Thanks,
Mary
schma01 is offline   Reply With Quote
Old 2008-11-19   #2 (permalink)
Ingres Corp
 
Join Date: Apr 2007
Posts: 49
Default

Hi,

Did you try this???? I am assuming that you are using "use namespace std" C++ package... You may have to use the correct constructor to build char*....

string s = "user";
char *db_user = new char[s.length()+1];

iiConn.co_username = db_user;


HTH.

Regards,
Usha
rajus01 is offline   Reply With Quote
Old 2008-11-19   #3 (permalink)
Ingres Corp
 
Join Date: Apr 2007
Posts: 49
Default

It looks that I missed a line of code ....

It should be:

string s = "user";
char *db_user = new char[s.length()+1];

strcpy(db_user, s.c_str() );
iiConn.co_username = db_user;

HTH.

Regards,
Usha
rajus01 is offline   Reply With Quote

Reply



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://community.ingres.com/forum/database-drivers-apis/2261-using-openapi-c.html
Posted By For Type Date
Related Information for tag: OpenAPI This thread Refback 2008-12-16 05:13 AM

© 2009 Ingres Corporation. All Rights Reserved