home *** CD-ROM | disk | FTP | other *** search
- /* C test program */
-
- #include <sqlenv_.h>
- #include <sql_.h>
- #include <sqlca_.h>
- #include <sqlda_.h>
- #include <sqlutil_.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <signal.h>
- #include <conio.h>
- #include <dos.h>
-
-
- EXEC SQL INCLUDE SQLCA;
-
- EXEC SQL BEGIN DECLARE SECTION;
-
- char results[80];
- char query[80];
-
- EXEC SQL END DECLARE SECTION;
-
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* FUNCTION PROTOTYPES */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- int fred (void);
- /* Interrupt handler */
- void _interrupt _far int_handler (void);
-
- int rc;
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
- /* GLOBAL VARIABLES */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- int main (void)
- {
- printf ("Begin program\n");
-
- /* Disable interrupts */
- _disable ();
-
- /* Install interrupt handler */
- _dos_setvect (0x23, int_handler);
-
- /* Enable interrupts */
- _enable ();
-
- printf ("Calling fred .... Hi fred \n");
- rc = fred ();
- printf ("We're back \n");
- return rc;
- }
-
- /********************************************************************/
- /* function - int_handler */
- /* ctrl-c, ctrl-break interrupt handler function */
- /********************************************************************/
-
- void _interrupt _far int_handler ()
- {
-
- /* Terminate query and communications to server */
-
- SQLGINTR ();
- return ;
-
- }
-
- int fred (void)
- {
-
- /* Declarations */
-
- char database[9];
- char alias[9];
- char type;
- char nodename[9];
- char drive;
- char comment[20];
- short codepg;
-
- /* Initializations */
-
- codepg = 0;
- drive = '0';
- strcpy (comment, "");
- strcpy (nodename, "KEYNES"); /* SERVER NETBIOS NAME */
- strcpy (database, "SAMPLE");
- strcpy (alias, "SAMPLE");
- type = '1';
-
- /* Catalog database */
-
- sqlecatd (database, alias, type, nodename, drive, comment, codepg, &sqlca);
- if (SQLCODE != 0)
- printf ("An error occurred in SQLECATD with rc = %ld\n",SQLCODE);
- else
- printf ("Succesful catalog ..... \n");
-
- /* Start using database */
-
- sqlestrd (database, SQL_USE_SHR, &sqlca);
- if (SQLCODE != 0) {
- printf("An error occurred in SQLESTRD with rc = %ld\n", SQLCODE);
- printf("SQLERRMC = %s\n", sqlca.sqlerrmc);
- printf("SQLERRP = %s\n", sqlca.sqlerrp);
- printf("SQLERRD = %ld\n", sqlca.sqlerrd);
- printf("SQLWARN = %s\n",SQLWARN1);
- } else {
- printf("Succesful start using database ..... \n");
- } /* endif */
-
- /* Perform query */
-
- EXEC SQL DECLARE c1 CURSOR FOR s1;
- printf ("Return from SQL DECLARE = %ld\n", SQLCODE);
-
- strcpy (query, "SELECT name FROM userid.staff ORDER BY name");
- EXEC SQL PREPARE s1 FROM :query;
- printf ("Return from SQL PREPARE = %ld\n", SQLCODE);
-
- EXEC SQL OPEN c1;
- printf ("Return from SQL OPEN = %ld\n", SQLCODE);
-
- EXEC SQL FETCH c1 INTO :results;
- printf ("Return from SQL FETCH .... %ld\n",SQLCODE);
-
- while (SQLCODE == 0) {
- printf ("Results = %s\n", results);
- EXEC SQL FETCH c1 INTO :results;
- };
-
- EXEC SQL CLOSE c1;
-
- /* Uncatalog database */
-
- sqleuncd ( database, &sqlca );
- if (SQLCODE != 0)
- printf("An error occurred in SQLEUNCD with rc = %ld\n", SQLCODE);
- else
- printf("Succesful uncatalog ..... \n");
-
- return(0);
- }
-