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 #50 background imageLoading...
Page #50 background image
Host Variables
HP NonStop SQL/MP Programming Manual for C—429847-008
2-16
Date-Time and INTERVAL Data Types
Example—Creating DATETIME and INTERVAL Data Types
Example 2-1. Creating Valid DATETIME and INTERVAL Data Types
#include <stdio.h>
#include <string.h>
#include <sql.h>
#define STMT_LEN 256
EXEC SQL BEGIN DECLARE SECTION;
short sqlcode;
char hv_projdesc[30];
char hv_start_date[11];
char in_start_date[11];
char curspec[STMT_LEN];
EXEC SQL END DECLARE SECTION;
int main()
{
int len;
strcpy(curspec,
"SELECT projdesc, CAST(start_date AS CHAR(10)) FROM test1 "
"WHERE start_date <= CAST(CAST( ? AS CHAR(10)) "
"AS DATE) BROWSE ACCESS");
len = strlen(curspec);
memset(&curspec[len], ' ', STMT_LEN - len);
EXEC SQL PREPARE cursor_spec from :curspec;
/* Declare the dynamic cursor from the prepared statement. */
EXEC SQL DECLARE get_proj CURSOR FOR cursor_spec;
/* Initialize the parameter in the WHERE clause. */
printf("Enter the most recent start date in the form yyyy-mm-dd: ");
scanf("%s", in_start_date);
/* Open the cursor using the value of the dynamic parameter. */
EXEC SQL OPEN get_proj USING :in_start_date;
/* Fetch the first row of the result table. */
EXEC SQL FETCH get_proj INTO :hv_projdesc,:hv_start_date;
while (sqlcode == 0)
{
hv_start_date[10]='\0';
printf("\n Start Date: %s", hv_start_date);
/* Fetch the next row of the result table. */
EXEC SQL FETCH get_proj INTO :hv_projdesc,:hv_start_date;
}
/* Close the cursor. */
EXEC SQL CLOSE get_proj;
return 0;
}

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