home *** CD-ROM | disk | FTP | other *** search
- #include <memory.h>
- #include <string.h>
-
- #include <sqlenv.h> /* defines SQLZ_DISCONNECT_PROC */
- #include <sqlutil.h> /* defines sqlchar structure */
-
- EXEC SQL INCLUDE SQLCA; /* defines/declares sqlca structure */
- EXEC SQL INCLUDE SQLDA; /* defines sqlda structure */
-
- EXEC SQL BEGIN DECLARE SECTION;
- char table_stmt[80] = "CREATE TABLE ";
- char insert_stmt[80] = "INSERT INTO ";
- char insert_data[21];
- EXEC SQL END DECLARE SECTION;
-
- SQL_API_RC SQL_API_FN INPSRV(struct sqlchar *vardata, /* table name */ /* :rk.1:erk. */
- struct sqlda *input_sqlda, /* table data */
- struct sqlda *output_sqlda, /* not used */
- struct sqlca *sqlcaptr) /* output sqlca */
- {
- int cntr = 0;
-
- EXEC SQL WHENEVER SQLERROR GOTO error_exit;
-
- strcat(table_stmt, vardata->data);
- strcat(table_stmt, " (name CHAR(20))"); /* :rk.2:erk. */
- EXEC SQL EXECUTE IMMEDIATE :table_stmt;
-
- strcat(insert_stmt, vardata->data);
- strcat(insert_stmt, " VALUES (?)"); /* :rk.3:erk. */
- EXEC SQL PREPARE INSERT_NAME FROM :insert_stmt;
-
- for (cntr = 0; cntr < input_sqlda->sqld; cntr++) {
- strcpy(insert_data, input_sqlda->sqlvar[cntr].sqldata);
- EXEC SQL EXECUTE INSERT_NAME USING :insert_data; /* :rk.4:erk. */
- }
-
- error_exit: /* :rk.5:erk. */
- memcpy(sqlcaptr, &sqlca, sizeof(struct sqlca));
- EXEC SQL WHENEVER SQLERROR CONTINUE;
- if (SQLCODE == 0)
- EXEC SQL COMMIT;
- else
- EXEC SQL ROLLBACK;
- return(SQLZ_DISCONNECT_PROC);
- }