EasyManua.ls Logo

HP NonStop SQL/MP User Manual

HP NonStop SQL/MP
331 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #217 background image
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-19
Dynamic Allocation of Memory
provide names for the SQLDA and names buffer as shown:
EXEC SQL INCLUDE SQLDA (dummy_da, 1, dummy_namesbuf, 1);
The INCLUDE directive generates the structure templates sqlda_type and
sqlvar_type, which you can later use to allocate the memory. You might set up
the pointers that will eventually point to that memory. For example:
typedef struct SQLDA_TYPE *sqldaptr;
sqldaptr input_sqlda_ptr, output_sqlda_ptr;
When the memory is allocated, input_sqlda_ptr points to the memory for the
input SQLDA, and output_sqlda_ptr points to the memory for the output
SQLDA. To access the SQLDA and names buffer, declare pointers and then pass
the pointers to a function that allocates the memory as follows:
EXEC SQL BEGIN DECLARE SECTION;
typedef struct SQLDA_TYPE *sqldaptr;
sqldaptr input_sqlda_ptr, output_sqlda_ptr;
typedef char (*arrayptr) [1000];
arrayptr input_namesbuf_ptr, output_namesbuf_ptr;
EXEC SQL END DECLARE SECTION;
To give the DESCRIBE INPUT and DESCRIBE statements a size to use before the
memory is actually allocated, you must declare the names buffer to be an
arbitrarily large size (this example uses 1000). Estimate a number that is greater
than any possible size your names buffer could be. Otherwise, DESCRIBE INPUT
and DESCRIBE might stop describing parameters or variables too soon.
3. Declare an SQLSA structure using the INCLUDE SQLSA directive:
EXEC SQL INCLUDE SQLSA;
4. Dynamically compile the SQL statement (stmt1) entered by the user using the
PREPARE statement as shown in this example:
#define MAX_QUERY_SIZE 512
EXEC SQL BEGIN DECLARE SECTION;
char statement_buffer[MAX_QUERY_SIZE + 1];
...
EXEC SQL END DECLARE SECTION;
...
printf("\nEnter a new SQL statement:\n");
/* Pass statement_buffer to a function that reads */
/* and parses the input (code is in sample program) */
...
EXEC SQL PREPARE stmt1 FROM :statement_buffer;
5. Use the information in the SQLSA structure to determine the number of input
parameters and output variables in the statement.
6. Allocate space for the required number of SQLDA data structures to describe the
parameters and output variables using the malloc function.
7. Allocate space for the values input to the program or output from the database,
again using the malloc function.

Table of Contents

Question and Answer IconNeed help?

Do you have a question about the HP NonStop SQL/MP and is the answer not in the manual?

HP NonStop SQL/MP Specifications

General IconGeneral
PlatformHP NonStop Servers
Data ModelRelational
SQL StandardANSI SQL
Concurrency ControlMulti-Version Concurrency Control (MVCC)
Fault ToleranceYes
High AvailabilityYes
CategoryDatabase Software
Initial Release1980s
Operating SystemHP NonStop OS
LicenseProprietary
TypeRelational Database Management System
Transaction ManagementACID Compliance
DeveloperHewlett Packard Enterprise

Summary

1. Introduction

Developing a C Program

Outlines the process of creating C programs with embedded SQL statements.

Dynamic SQL

Describes how to construct, compile, and run SQL statements at runtime.

2. Host Variables

3. SQL/MP Statements and Directives

4. Data Retrieval and Modification

Single-Row SELECT Statement

Retrieves a single row of data from tables or views into host variables.

Multirow SELECT Statement

Returns multiple rows from tables or views, one row at a time, using cursors.

INSERT Statement

Inserts one or more rows into a table or protection view using host variables.

Using SQL Cursors

Explains how to use named pointers to access sets of rows one at a time.

5. SQL/MP System Procedures

6. Explicit Program Compilation

Explicit Program Compilation

Outlines the general steps for compiling C programs with embedded SQL.

Developing a C Program in the Guardian Environment

Details C program development within the Guardian environment.

7. Program Execution

Required Access Authority

Specifies the access permissions needed to run NonStop SQL program files.

8. Program Invalidation and Automatic SQL Recompilation

Program Invalidation

Explains how SQL program files can become invalid due to changes or errors.

Automatic SQL Recompilation

Describes the run-time recompilation process invoked by the SQL executor.

9. Error and Status Reporting

10. Dynamic SQL Operations

Uses for Dynamic SQL

Identifies scenarios where dynamic SQL programs are beneficial.

Dynamic SQL Statements

Summarizes dynamic SQL statements usable in a C program.

11. Character Processing Rules (CPRL) Procedures

Appendix B: Memory Considerations

Avoiding Memory Stack Overflows

Provides guidelines to prevent stack overflows for SQL statements.

Related product manuals