Hitachi

Hitachi Advanced Database Application Development Guide


19.6.2 Correspondences between SQL data types and data descriptions

The following table shows the correspondences between the SQL data types and the data descriptions in C or C++.

Table 19‒8: Correspondences between the SQL data types and the data descriptions in C or C++.

No.

SQL data type

Data description in C or C++

Area length (bytes)

1

CHAR(n)

char variable-name [n + 1];

n + 1

2

VARCHAR(n)

a_rdb_M_VARCHAR(n) variable-name;

n + 4

3

INTEGER

long long variable-name;

8

4

SMALLINT

int variable-name;

4

5

DECIMAL(m,n)

unsigned char variable-name[p#1];

p#1

6

DOUBLE PRECISION

double variable-name;

8

7

DATE

unsigned char variable-name[4];

4

8

TIME(p)#2

unsigned char variable-name[3 + (p + 1) ÷ 2];

3 + (p + 1) ÷ 2

9

TIMESTAMP(p)#2

unsigned char variable-name[7 + (p + 1) ÷ 2];

7 + (p + 1) ÷ 2

10

BINARY(n)

unsigned char variable-name[n];

n

11

VARBINARY(n)

a_rdb_M_VARBINARY(n) variable-name;

n + 2

12

ROW

unsigned char variable-name[row-length#3];

row-length#3

Legend:

m, n: Positive integer

#1

The value of p depends on the value of m (precision).

No.

Value of m

Value of p

1

1 ≤ m ≤ 4

2

2

5 ≤ m ≤ 8

4

3

9 ≤ m ≤ 16

8

4

17 ≤ m ≤ 38

16

#2

p indicates the fractional seconds precision and its value is 0, 3, 6, 9, or 12.

#3

The row length is the sum of the data lengths of all the columns. For details about determining the data length of a column, see Length of data storage in the topic List of data types in the manual HADB SQL Reference.

Macros used in the data descriptions are expanded as shown below.

a_rdb_M_VARCHAR(n) variable-name;
struct
{
  unsigned int Length ;           /* Data length */
  char Data[n] ;                  /* Character string data */
}
a_rdb_M_VARBINARY(n) variable-name;
struct
{
  unsigned short Length ;         /* Data length */
  unsigned char Data[n] ;         /* Binary data */
}