About ODBC configuration, access to Oracle's blobs, and CString storage

Source: Internet
Author: User
Tags dsn

When using C + + to access Oracle, ODBC is an option and the DSN needs to be configured when CDatabase is used for OpenEx. Here's how to configure DSN

    1. Open ODBC Data Source Manager (ORC1 I have configured, not before configuration)


Click "Add" and a dialog box appears:


Select Oracle in Oraclinetxxx, after the XXX representative version is different, may be different, click "Done"


The TNS Service Name is optional (my ORCL), select it, fill in the Data Source Name and User ID, and then click "Test Connection" to indicate success.

And then use it when programming.

CDatabase DB;
Db. OpenEx (_t ("DSN=ORC1; Uid=uid; Pwd=pwd "), Cdatabase::openreadonly | Cdatabase::noodbcdialog); DSN is the last name of the first picture, the UID is my id,pwd is my password

2 using Cdbimage to read a blob of a database

The variables defined in the DBIMAGES.H must be consistent with the name of the database table. If there is AAA in the table, then the definition is AAA. If the BLOB has a column name of BBB, the CLongBinary BBB is defined.

In the CPP file

CString Cdbimages::getdefaultsql ()
{
Return _t ("[TABLENAME]"); //In parentheses indicates that the name of the table to be queried
}

Others can be configured with reference to other tutorials.

If you read directly, you can use the

Cdbimages dbimages (&DB);

Dbimages.open ();

At this point, the BBB value for the first row of the table is obtained. If you need to get the value of BBB for AAA = ' AAA ', that is: select BBB from TABLENAME where aaa= ' aaa ' can:

CString Bbb_str;
CString aaa_str = L "AAA";

DbImages.m_strFilter.Format (L "aaa= '%s '", AAA_STR);
if (Dbimages.open (crecordset::snapshot,l "TABLENAME"));

{

What you get is the data you want.

}


3 CString saved to TXT document

In the case of Unicode, the result is a string of 16-bit binary data saved with Ofstream. This is because the address is saved, not the data itself. You can do this by:

CString str = "CSTRING_STR";
CStringA stra (str);

Std::ofstream outfile;
Outfile.open ("Save.txt", ios::out);
outfile<<stra;
Outfile.close ();

Data from Str can be saved.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.