Pro * C/C ++ Study Notes (1)

Source: Internet
Author: User
Tags what header

Last Saturday, I took the time to learn about Pro * C/C ++. I used the reference book "proficient in Oracle 10gPro * C/C ++ programming". In my opinion, the Pro * C/C ++ syntax is not difficult, that is, it is a bit difficult to set the environment. Programming is like this. It starts with a hurdle. If the compiling environment is not well set and the output result is not visible, it is difficult to get that sense of accomplishment. The following is a simple example to illustrate how to set the compiling environment of Pro * C/C ++. This development environment is: Win XP sp2, VC ++ 6.0,
OCI: version 9.2, Oracle DataBase 10g Enterprise Edition Release 10.1.0.2.0.
 
It is said that Oracle provides the Pro * C/C ++ graphical interface tool for the Windows platform, but the Oracle 10 Gb I installed does not contain this graphic interface tool. Well, use the Proc on the console. Pro * C/C ++ is generally divided into four steps:
1. Specify the executable file path, header file path, and library file path
The path of the specified executable file is actually in Visual C ++, which specifies the Pro * C/csf-‑compiler proc.exe that runs Oracle 10 Gb. This proc.exe is available on both the server side and the client side. I think it is the same. Here, the server is used. The specific method is: On the Directory tab of the TOOl> Option menu item in VC 6.0, select Executable files in the Show directoryes for Option to add the proc.exe path, as shown in:

As for adding header files and library files, I think people who have been engaged in secondary development are clear, so I will not elaborate on them one by one. What header files should be added? There are two main headers: one is the directory where sqlca. h is located, generally precomp \ public, and the other is the OCI header file, as shown in:

As for the library files, you only need to add the OCI library files, as shown in:
 
In the future, you may need to add the corresponding header files and library files as needed.
2. Use the configuration file
The configuration file is used to set the pre-compilation options. Because we just got started, this time we use the system configuration file, but the system configuration file does not fully meet our needs. For example, the system configuration file does not contain the parsing embedded SQL syntax, therefore, edit the system configuration file. The system configuration file is usually % precomp \ admin \ pcscfg. cfg. Here we will refer to my Oracle installation directory. my options are: D: \ Oracle \ Server \ precomp \ admin \ pcscfg. cfg. Use Notepad (other text editing tools can also be used) to open the file and add the following content to it:
Parse = full
Include = "C: \ Program Files \ Microsoft Visual Studio \ VC98 \ INCLUDE"
Include = "D: \ Oracle \ Server \ precomp \ public"
Include = "D: \ Oracle \ Server \ OCI \ include"
Parse = full indicates all the syntaxes for parsing the source file, including C syntax and embedded SQL syntax. include specifies the path of the header file, including the Visual C ++ header file path, ProC/C ++ header file path, and OCI header file path.
 
3. Create a project file and start programming.
The exciting programming time has finally arrived. First, use NotePad to create a text file and enter the following code:
# Include <stdio. h>
# Include <string. h>
# Include <stdlib. h>
# Include <conio. h>
# Include <sqlca. h>
 
Int main ()
{
Char username [10], password [10], server [10];
Printf ("input Username: \ n ");
Gets (username );
Printf ("input password: \ n ");
Gets (password );
Printf ("enter network service name: \ n ");
Gets (server );
Exec SQL CONNECT: username IDENTIFIED BY: password USING: server;
If (sqlca. sqlcode = 0)
Printf ("connection successful! \ N ");
Else
Printf ("%. * s \ n", sqlca. sqlerrm. sqlerrml, sqlca. sqlerrm. sqlerrmc );
Getch ();
Return 0;
}
 
Save as demo. pc (note that the suffix is. pc)
Create an empty console project demo on VC, select Source File on the FileView page, and add demo. pc to the project (), as shown in:

In the same way, enter demo. c in the file name,
Because the file does not exist at this time, the following dialog box is displayed:
 
Click Yes to add the. c file to the project file. Note that demo. c is generated after pre-compilation.
 
Then Add the SQLLIB library, specifically: select Source Fil on the FileView page, select Add Files To Folder, and Add the oraSQL10.LIB file To the project, this file is generally stored in the precomp \ lib subdirectory under the Oracle Installation File directory. For example:


 
Create a pre-compilation command as follows:
1. Right-click and select demo. pc, for example:

2. right-click setting from the menu, and enter proc F: \ MyProSrc \ ProC \ Demo \ demo.pcin the Command edit box. The idea is to use proc.exe to access the file F: \ MyProSrc \ ProC \ Demo \ demo. in the Outputs edit box, enter F: \ MyProSrc \ ProC \ Demo \ demo. c, which means that the pre-compiled output file is: F: \ MyProSrc \ ProC \ Demo \ demo. c, such
 
Click OK to save the settings.
 
After completing the preceding settings, you can create and generate an executable file. Press the Ctrl + F5 shortcut key. Visual C ++ calls the proc tool for pre-compilation, converts the pc source program into the c code, and then compiles the c code to generate the target code, finally, link the target code and the sqllib library file to generate the executable file. The program runs as follows:

 

This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/clever101/archive/2007/09/19/1792075.aspx

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.