Pro C# 7: With .Net And .Net Core Pdf Download UPDATED

Pro C# 7: With .Net And .Net Core Pdf Download

Pro*C tutorial

Pro*C Tutorial

In this tutorial, nosotros are going to cover the post-obit topics:

  • What is Pro*C
  • Compiling the Pro*C plan
  • Need of Pro*C compiler
  • Requirements
  • Directory Structure
  • Restrictions
  • Embedded SQL statements
  • Pro*C Syntax
  • Host Variables
  • Datatype Equivalencing
  • Dynamic vs Static SQL statements
  • Transactions
  • Error Handling
  • Programme

What is Pro*C?

Pro*C means creating a program that is embedded with SQL statements. We can access the Oracle database with the help of Pro*C. The C programming language provides the flexibility for data processing by manipulating or retrieving the data from the Oracle database. Therefore, we tin say that Pro*C allows C programming language to connect the C program with the Oracle database and practice the manipulations according to our requirements.


How tin we compile the Pro*C program?

Oracle software provides the PROC compiler (Oracle Precompiler), and this compiler takes the C programme having embedded SQL statements.

What is Oracle precompiler?

An oracle precompiler is a programming tool that allows the user to embed the SQL statements in a high-level source program. This compiler takes the source program every bit input, replacing the embedded SQL statements with the oracle runtime library calls, and this modified program can now compile, link, and execute.

The whole process of compilation of Pro*C programme is given below:

Pro*C Tutorial
  • Outset, we create a C program, which contains the SQL statements, and and then we save this file with an extension '.PC'. Hither, '.PC' means that the programme is a Pro*C plan.
  • After creating a programme, we compile the program by using the PROC compiler, which is provided by the Oracle. The PROC compiler generates .c file with all the SQL statements replaced by the functions which are already pre-defined in the Oracle runtime library.
  • The file created by the PROC compiler will exist compiled once again by the C compiler, which is supported by Pro*C. In Windows, the PROC compiler supports Microsoft Visual C++ compiler.
  • The C compiler will create a .exe file.
  • At present, finally, nosotros run the .exe file.

Why do we demand the Pro*C compiler?

  • The Pro*C compiler allows y'all to embed the SQL statements in the C program, and it also provides the required user interface.
  • Different many other evolution tools, the Pro*C allows you to customize applications. It creates user interfaces that incorporate the latest windowing and mouse engineering science. Sometimes information technology is possible that we cannot generate the reports from other development tools, merely we tin achieve this past retrieving the data from the oracle database.

Requirements

The main requirement of Pro*C is to install the Pro*C software. When we are installing the Oracle database, then we have to make certain that nosotros have selected the Pro*C components. If we have to check whether the installation of oracle contains the Pro*C components is past checking the PRECOMP directory of Oracle.


Directory Construction

When nosotros install the Oracle, a directory structure is created on our hard drive for the Oracle products. The chief oracle directory will contain the subdirectories and files which are required for the Pro*C.

When we install the Pro*C in Oracle, so Oracle Universal installer creates a directory known equally precomp in the ORACLE_BASE\ORACLE_HOME directory. This subdirectory, i.due east., precomp contains the executable files, library files, and some sample programs which is given beneath:

precomp Directory Structure

Directory Description
\admin It contains the configuration files.
\demo\proc It contains the sample programs for Pro*C.
\demo\sql It contains sql scripts for sample programs.
\doc\proc It contains the documentation files for pro*c.
\aid\proc It contains help files for Pro*C.
\lib\msvc It contains library files for Pro*C
\mesg It contains message files.
\misc\proc It contains miscellaneous files for Pro*C.
\public It contains the header files having .h extension.

Restrictions

All the Windows operating systems can incorporate the spaces in the files and directory names, but Oracle Pro*C precompiler does not precompile the files, which include space in the file proper noun.

For example, if the file name is the outset plan.pc, then this file name volition be invalid.


Embedded SQL statements

Hither, embedded SQL means placing the SQL statements inside the source program. As we house the statements inside the C programme, so C program is also known as the host program, and the linguistic communication we apply is known equally the host language. The Pro*C provides the power to embed the SQL statements within the plan.

Embedded SQL statements are of ii types:

  • Executable statements
  • Directives

Executable statements

Executable statements are the SQL statements that allow yous to manipulate the data in the Oracle database. These statements call the Oracle runtime library. It also allows your program to connect to the Oracle database, to define the query, to manipulate the data, and process the transactions. These statements are written where C executable statements tin can exist placed.

Directives

Directives or declarative statements are the SQL statements that neither call the Oracle runtime libraries nor operate on the Oracle information. It is used to declare the Oracle objects, SQL objects. These statements can be written where the C variables can be alleged.


Pro*C Syntax

In the C program, all the SQL statements must start with EXEC SQL, and should end with the semicolon ;.Nosotros tin write the SQL statement anywhere in the program but with one restriction that declarative statements should non come afterwards the executable statements.

Suppose we want to remember the student marks from the database based on their id, so its plan would be written as:

Preprocessor directives

The preprocessor directives that we tin use when we are dealing with Pro*C in C are #include and #if. But, Pro*C does not know nigh the #define directive. Permit's sympathise this through a simple scenario which is given below:

The above code is invalid, as Pro*C does not piece of work with a #ascertain directive.


Host Variables

Host variables are the variables of the host language that are used with the SQL embedded statements. Host variables are a key of advice between the Oracle and C program. These variables are alleged similarly as we make the declaration in the C program, and it tin can be referenced by both our program and Oracle.

The host variables can be placed where the SQL expressions are used, and these variables are declared between the BEGIN DECLARE Section and Cease DECLARE SECTION. When we write the SQL statements, then the host variables are prefixed with a ':' colon.

The following is the list of the C data types that are supported by Oracle:

  • char
  • char[northward]
  • int
  • brusk
  • long
  • float
  • double
  • VARCHAR[n]

Pointers

A pointer variable tin also be used every bit a host variable in SQL statements. Let's understand through a simple example.

In the above code, we declare a pointer variable of integer type, i.due east., *age. Later declaration, nosotros are executing a SELECT statement in which we are retrieving the value of age from the student table, and and so nosotros are storing the value of age in a host variable, i.e., age. The result will be stored in the *age, not in age.

Structures

C structures are besides used in Pro*C. The fellow member variables of the structure can exist treated equally the host variables in the host programme. When we provide the name of the structure in the SQL statement, so each host variable must be prefixed with a: colon.

In the higher up lawmaking, nosotros accept created a construction named as a pupil, which contains 2 variables, i.e., student_id and name. After creating structure, nosotros declare the variable, i.east., s1 of type student. And so, we insert the value of these two variables in a database by using the insert command.

Arrays

Arrays tin can be used as a host variable in SQL embedded statements. Let's sympathize this through a simple example:

In the higher up code, we have created a single-dimensional array of integer blazon. We implement the SQL INSERT control, which will insert all the 10 tuples in 1 become.

Let'south wait at the other case in which we use the two-dimensional array.

In Pro*C, arrays can only exist single-dimensional. But, Pro*C precompiles the above code successfully as information technology considers the ii-dimensional as a single-dimensional assortment of characters instead of a two-dimensional array of characters.

As we have shown in the above instance that we tin can use the indicator variable in a SELECT statement to decide whether the output host variable contains the NULLs or truncated value. The following table shows the possible values of the indicator variable that tin can exist given by the Oracle with its description:

Value returned past Oracle Description
-1 Information technology means that the value of cavalcade is Null, and so the value of the host variable will be indeterminate.
0 An intact cavalcade value is assigned to the host variable.
>0 Truncated value is assigned to the host variable.
-2 Truncated value is assigned to the host variable.

If we want to create the indicator variable of a host variable in a struct, we can merely do that by creating an indicator variable of each host variable in a struct. To add the name of an indicator variable in a SQL argument, we need to write the proper noun of the indicator variable of a structure that must be prefixed with a ':' colon, and must immediately follow the host variable.


Datatype Equivalencing

It is a very important feature as it adds flexibility to your application. It means that y'all tin customize co-ordinate to the requirements based on how Oracle interprets the input data and formats the output data.

Oracle contains two types of information types:

  • Internal datatypes
  • External datatypes

internal datatype: These information types are used past Oracle to define how information is going to be stored in a column.

External datatype: These data types are used by Oracle to format the output information, and so this output information volition exist stored in a host variable.

Let's see how we tin equivalence the data blazon.

On a variable-by-variable basis, we employ the var argument for equivalencing. The syntax of the var statement is given below:

For example, we want to call back the student names from the student table; then, we need to pass these student names to the office that accepts the C style strings (the concluding grapheme must exist a termination character '\0'). To equivalence the host variable with a String external datatype, we use the following code:

The column, i.e., educatee proper name, contains eleven characters. As the column student proper noun contains the 11 characters, so nosotros need to destine the 12 characters (11 characters of pupil name plus terminator character (\0)). We use the Cord data type that provides the interface with the C manner strings. Oracle volition automatically add the '\0' character.

Till now, we equivalence the congenital-in information types, i.e., in the higher up example, we equivalence the char array to the Oracle external datatype (String). We tin can also equivalence the user-divers data types by using the Type command. The syntax of the type argument is given below:


Dynamic vs Static SQL statements

Mainly, static SQL statements are used for fixed applications, merely sometimes information technology is required for a programme to create the SQL statements dynamically. To create the dynamic SQL statement, beginning, we need to store the SQL statement in a string variable. After storing the argument, we use the PREPARE statement to convert the character string into a SQL statement. Finally, we execute the argument by using the EXECUTE statement. Let's understand this scenario through an example.


Transactions

Oracle Pro*C as well follows the concept of the transaction every bit defined past the SQL standard. A transaction is a series of statements that Oracle uses to either fabricated all the changes permanent or undo all the changes washed since the transaction began. We use two statements, i.e., EXEC SQL COMMIT and EXEC SQL ROLLBACK. The EXEC SQL COMMIT statement is used to make all the changes permanent since the transaction began. The EXEC SQL ROLLBACK is used to undo all the changes since the transaction began. If nosotros start the next transaction without writing the statement EXEC SQL COMMIT, and so all the changes made during this transaction will be discarded.


Mistake Handling

C programming provides the in-built fault handling mechanism which we use in our source program. Fault treatment is a mechanism that provides the condition of our source program. We demand some mechanism that handles the mistake, then Pro*C contains the two error handling concepts which are given below:

  • SQLCA (SQL Advice Expanse)
  • Whenever statement

SQLCA

SQLCA (SQL Communication Area) is a data structure or an area used by our program to cheque for errors. This data structure contains some pre-divers variables used past Oracle. These variables contain the status information of the program, which is passed at the runtime.

The structure of sqlca is given below:

SQLCA Components

The following are the components of SQLCA:

  • sqlcaid: It is an assortment of char character which is initialized to "SQLCA", and used to determine the SQL Advice area.
  • sqlcabc: It is declared as an integer blazon to hold the length of the SQLCA structure in bytes.
  • sqlcode: It is declared as an integer type that stores the status lawmaking of the most recently executed SQL statement. The condition determines the outcome of the SQL statement, and the event tin come in the following ways:
Consequence Description
0 The statement has been executed successfully with no error.
>0 Some error occurs while executing the statement. For example, when we are using SELECT command with Where clause, and then no such row found mentioned in the Where clause status.
<0 In this case, statement is not executed due to the database, arrangement, application or network fault.
  • sqlerrm: Information technology is divers every bit a structure inside the sqlca.

This field contains ii components:

sqlerrml: It is declared as an integer blazon that holds the length of the text message stored in sqlerrmc.

sqlerrmc: It is declared as a string that holds the text bulletin with respect to the error code stored in a sqlcode.

  • sqlerrp: It is declared as a string but reserved for future employ.
  • sqlerrd: It is alleged as an array of integers that holds six elements.
Fields Description
sqlerrp[0] It is reserved for future use.
sqlerrp[1] It is reserved for future use.
sqlerrp[2] Information technology contains the no. of rows which are processed by the SQL argument.
sqlerrp[three] It is reserved for the future utilise.
sqlerrp[4] It contains the grapheme position at which the error begins in the most recently executed statement.
sqlerrp[5] It is reserved for the future use.
  • sqlwarn: It is declared every bit an array of characters having eight elements. These elements are used as a warning flag in sqlca. If the flag is set up, then Oracle assigns 'W' to the chemical element.
Fields Description
sqlwarn[0] It is set just when the value of another flag is set up.
sqlwarn[1] Information technology is set when the Oracle assigns a truncated value to the output host variable.
sqlwarn[two] Information technology is ready when the Null cavalcade value is non considered while calculating the SQL aggregate such MAX, MIN, AVG or SUM.
sqlwarn[3] It is ready when the no of columns retrieved past using the SELECT argument is not equal to the no. of host variables specified in a INTO clause.
  • sqlext: It is declared as a string which is reserved for future use.

Whenever argument

The whenever argument is used for error handling. It performs implicit error checking and handling. The syntax of the whenever statement is given below:

When the Whenever statement is executed, then the Oracle volition automatically check the SQLCA for the condition mentioned in the whenever statement. If such condition is found in the sqlca, then the action given in the whenever argument will be performed.

The condition can be NOT Institute, SQLERROR, SQLWARNING, and the activity can be CONTINUE, GOTO label, STOP, Exercise routine.

The condition can be of post-obit types:

  • SQLWARNING: If the oracle returns a warning, then the sqlwarn[0] will exist gear up.
  • SQLERROR: If the oracle returns an error, and then the value of sqlcode will exist negative.
  • Non FOUND: If the Oracle is not able to find the row based on the condition mentioned in the WHERE clause of the SELECT argument, then the value of the sqlcode volition exist positive.

If the Oracle finds any of the above condition, then the following actions can be taken:

  • Proceed: The plan volition proceed execution with its adjacent statement if possible.
  • DO: In this action, the control will exist transferred to the error handling function in the program. When the control is reached at the end of the error handling function, and so the control will be transferred to the statement that comes after the failed SQL statement.
  • DO BREAK: This pause statement is mainly used in our plan, and can be used every bit an action in loops. When the condition present inside a WHENEVER statement is satisfied, so our program exits from the loop.
  • Do Proceed: This continue statement is mainly used in our program, and can be used as activity in loops. When the condition within a WHENEVER statement is satisfied, then our program continue with the next iteration inside the loop.
  • GOTO: The program command transfers to the labeled argument.
  • Cease: Our program stops running. When the WHENEVER status is satisfied, so go out() role is called to cease the execution of the programme.

Steps to create a program

The post-obit are the steps required to create and run the program:

  • Outset, nosotros demand to install the Oracle database, and Microsoft Visual C++. In Visual C++, nosotros will create our C plan that contains the embedded SQL statements. This program volition connect with a oracle database.
  • The oracle database contains the in-congenital PROC components. To check whether the PROC has been installed successfully, open the cmd and blazon the 'proc' command.
Pro*C Tutorial

Subsequently inbound the proc command in command prompt, we press enter:

Pro*C Tutorial

The above screen shows that the proc has been installed successfully.

  • Now, we will create a C program in Visual C++. Open Visual C++. When nosotros open the Visual C++, the image shown below will appear:
Pro*C Tutorial
  • Click on the File appearing at the top menu. Movement the mouse over the New, and so click on the Projection.
    Pro*C Tutorial
  • When we click on the project, the screen appears shown beneath:
Pro*C Tutorial

In the above screen, click on the General appearing at the left-side under the Visual C++ category, so click on the Empty Project. Now, nosotros need to provide the name to this empty projection.

Pro*C Tutorial

In the to a higher place screen, we can find that we have given the name of our project as Demo.

  • After providing the proper noun to our project, we click on the OK button.
    Pro*C Tutorial

In the in a higher place screen, we can see that the workspace of our project has been created. At the leftmost side, we can see the hierarchy of our project which contains External Dependencies, Header Files, Resource files, and Source files.

  • Now, we have to add together the library files of Oracle, and then right-click on the header files, then continue the mouse cursor over the Add and and so click on the Existing-particular.
Pro*C Tutorial
  • Move to the oracle folder which contains precomp equally a subdirectory. Click on the precomp.
Pro*C Tutorial

When we click on the precomp binder, the screen shown below will appear:

Pro*C Tutorial

Click on the lib binder, which is shown in the above screen.

Now add the 2 object library files, i.east., orasql19, and another 1 is orasqx19, which is nowadays in the msvc folder.

Pro*C Tutorial
Pro*C Tutorial

When we add the above 2 library files, our Solution Explorer window would look like:

Pro*C Tutorial

In the to a higher place screen, the highlighted area shows that both the library files have been added successfully in our project.

  • Now, we add source code in our projection. To do so, right-click on the source files, keep the mouse cursor over the Add and then click on the New item.
    Pro*C Tutorial
  • Afterwards clicking on the New particular, the screen appears as shown below:
Pro*C Tutorial

In the in a higher place screen, click on the Code that appears at the leftmost side, so click on the C++ File. We too accept provided the file name equally first with a .pc extension.

  • After providing the name to the source file, we click on the Add button.
Pro*C Tutorial

In the above screen, we can observe that the workspace for the file that we take added has been created.

  • The following is the lawmaking of pc file:
  • Open the cmd, and motility to that folder, i.e., E:\Demo\Demo where first.pc file is stored.
Pro*C Tutorial
  • Now, we use the proc compiler to precompile the first.pc programme every bit shown in the beneath screenshot:
Pro*C Tutorial
Pro*C Tutorial

In the to a higher place screen, nosotros can find that first.c has been created after compilation of first.pc by Oracle precompiler.

  • Now, we add the first.c file in Visual C++. To add this file, right-click on the Source files, then keep the mouse cursor on Add and so click on the Existing detail. The below screen shows that first.c file has been added in Visual C++.
Pro*C Tutorial
  • After the compilation of first.pc, the lawmaking of first.c would be:

Run

We can run our program by simply clicking on the Debug that appears at the top carte, and then click on the Start Debugging.

Pro*C Tutorial

DOWNLOAD HERE

Posted by: norvellsaidence67.blogspot.com

0 Komentar

Post a Comment




banner