/* Copyright © Oracle Corporation 1995. All Rights Reserved. */ /* SQL$TEXT_FIELDS.C * This program demonstrates the use of DEC C and the SQL module language * to show different formats for a text field P stored in the * data dictonary. The program tests each fetched field to * make sure that it ends in a null character if it is supposed to. * * The program calls the SQL module SQL$TEXT_FIELDS_C.SQLMOD. * To create and populate the database for this example, you must run * the command procedure SQL$TEXT_FIELDS.SQL. You must also have the * data dictionary installed on your system. * */ #include void open_p(); void fetch_p_default(); void close_p(); void fetch_p_fixed(); void fetch_p_ntb(); void fetch_p_ntc(); main() { int sqlcode; int i; int fixed_okay; /* Host variables for SQL calls. * Structure P_NTC shows the definition for a text * string interpreted with the NULL TERMINATED CHARACTERS option. * Character strings for P_NTC are one byte longer than those * character strings in the other three structures. * A field with length of 7 bytes contains 6 characters, * followed by the null value. */ struct { char pnum[7]; char pname[21]; char color[7]; short weight; char city[16]; } p_ntc; /* * Structure P_NTB shows the definition for a text * string interpreted with the NULL TERMINATED BYTES option. * A field with a length of 6 bytes contains 5 characters, * followed by the null value. */ struct { char pnum[6]; char pname[20]; char color[6]; short weight; char city[15]; } p_ntb; /* * Structure P_DEFAULT shows the definition for a text * string interpreted without a character interpretation * option. The default interpretation is the same as * NULL TERMINATED BYTES: a field with a length of 6 bytes * contains 5 characters, followed by the null value. */ struct { char pnum[6]; char pname[20]; char color[6]; short weight; char city[15]; } p_default; /* * Structure P_FIXED shows the definition for a text * string interpreted with the FIXED option. * A field with a length of 6 bytes contains 6 * characters. There is no null value added to the field. */ struct { char pnum[6]; char pname[20]; char color[6]; short weight; char city[15]; } p_fixed; open_p( &sqlcode ); fetch_p_default( &sqlcode, &p_default ); close_p( &sqlcode ); printf( "%s, %s, %s, %s\n", p_default.pnum, p_default.pname,p_default.color, p_default.city ); for (i=0;i<6;i++) { if (p_default.pnum[i] == '\0') { if (i != 5) { printf("NULL not terminating in DEFAULT\n"); } else { printf("DEFAULT is okay\n"); } } } open_p( &sqlcode ); fetch_p_fixed( &sqlcode, &p_fixed ); close_p( &sqlcode ); printf( "%0.6s, %0.20s, %0.6s, %0.15s\n", p_fixed.pnum, p_fixed.pname,p_fixed.color, p_fixed.city ); fixed_okay = 1; for (i=0;i<6;i++) { if (p_fixed.pnum[i] == '\0') { fixed_okay = 0; }; }; if (fixed_okay == 0) { printf("NULL in fixed string\n"); } else { printf("FIXED is okay\n"); }; open_p( &sqlcode ); fetch_p_ntb( &sqlcode, &p_ntb ); close_p( &sqlcode ); printf( "%s, %s, %s, %s\n", p_ntb.pnum, p_ntb.pname,p_ntb.color, p_ntb.city ); for (i=0;i<6;i++) { if (p_ntb.pnum[i] == '\0') { if (i != 5) { printf("NULL not terminating in NTB\n"); } else { printf("NTB is okay\n"); } } } open_p( &sqlcode ); fetch_p_ntc( &sqlcode, &p_ntc ); close_p( &sqlcode ); printf( "%s, %s, %s, %s\n", p_ntc.pnum, p_ntc.pname,p_ntc.color, p_ntc.city ); for (i=0;i<7;i++) { if (p_ntc.pnum[i] == '\0') { if (i != 6) { printf("NULL not terminating in NTC\n"); } else { printf("NTC is okay\n"); } } } } /**** Host Program ****/