home *** CD-ROM | disk | FTP | other *** search
- #include <sybfront.h>
- #include <sybdb.h>
- #include <screenio.h>
- #include <sybfrs.h>
-
- #if MSDOS
- # include "aforms.h"
- #endif /* MSDOS */
-
- /*
- ** FSSQL DEMO
- **
- ** Run a form specified by command line arguments. Execute
- ** SQL text entered by the user and print any resulting data.
- */
-
- extern int printit();
- extern int runsql();
-
- static FSPROCEDURE procarray[] = {
- {"printit", printit, NULL, SYB_C},
- {"runsql", runsql, NULL, SYB_C},
- {NULL, NULL, NULL, SYB_C}, };
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
-
- LOGINREC *loginrec;
- DBPROCESS *dbproc;
- FORM *testform;
- char *formname;
- char *formvers;
- POINTER argarray[1];
- char buf[80];
-
- /* Initialize the terminal environment. Fsopenscreen uses
- ** non-NULL parameters if it is running on a bitmap terminal.
- ** In other environments, non-NULL parameters are simply ignored.
- */
- fsopenscreen(&argc, argv, "FssqlDemo");
-
-
- #if BSD42 || VMS
- if (dbinit() == FAIL)
- exit(ERREXIT);
- #endif /* BDS42 || VMS */
- dbproc = fsdblogin(&loginrec, "Fssql Demo Login");
-
- /* Give the forms run-time system a LOGINREC and environment to use
- ** when opening up a new DBPROCESS for its own purposes.
- */
- fsdbrec(loginrec);
- fsdbenviron(dbproc);
-
- /* Get the form from the command line arguments. */
- if (argc >= 3)
- {
- formname = argv[1];
- formvers = argv[2];
- }
- else
- {
- formname = "basic";
- formvers = "1";
- }
-
- /* Load the form. */
- if ( (testform = fsgetform(formname, formvers) ) == NULL )
- {
- sprintf(buf, "Unable to open form %s %s.", formname, formvers);
- dbclose(dbproc);
- dbexit();
- fsabort(buf);
- }
-
- /* Install the procedures and arguments. */
- fsinstallproc(procarray);
- argarray[0] = (POINTER) dbproc;
- fsprocargs("runsql", argarray);
-
- /* Call the form. */
-
- fscallform(testform);
-
- dbclose(dbproc);
- dbexit();
- fsclosescreen();
- exit(STDEXIT);
-
- }
-
-
- /*
- ** RUNSQL
- ** Read user-entered SQL from the screen and execute it via fssql().
- ** This routine is triggered by menu processing.
- */
- runsql(context, argarray)
- FRSCONTEXT *context;
- POINTER *argarray[];
- {
- #define MYMSGSIZE 1024
- FORM *form;
- DBPROCESS *dbproc;
- char *val;
- int rows;
- int len;
- char buf[MYMSGSIZE];
-
- form = fscurform(context);
- dbproc = (DBPROCESS *)argarray[0];
-
- /*
- ** Get the SQL text from the screen, checking for empty text.
- */
- val = fsfreadval(form, "sqltext", -1, NULL, NULL, NULL);
- if (val == NULL)
- {
- fsmessage("Please enter the SQL statement.");
- return;
- }
-
- /* Send the SQL text to the SQL Server. */
- rows = fssql(dbproc, val);
-
- /* Print the SQL text resulting from field value
- ** substitution -- the actual SQL sent to the SQL Server.
- */
- sprintf(buf, "SQL sent was\n");
- len = strlen(buf);
- dbstrcpy(dbproc, 0, MYMSGSIZE - len, buf + len);
- if (strlen(buf + len) != 0)
- {
- fsmessage(buf);
- }
-
- /* Check the fssql() return code. */
- if (rows == -1)
- {
- /*
- ** An error: fssql() printed any DB-LIBRARY errors that
- ** were not consumed by a DB-LIBRARY error handler. You
- ** may want to put error handling code here.
- */
- }
- else if (rows < -1)
- {
- fsmessage("Unable to show all of the rows of data.");
- }
- return;
- }
-
-
- /*
- ** PRINTIT
- ** Print the data on the form and present a message.
- ** This routine is triggered by menu processing.
- */
- printit(context, argarray)
- FRSCONTEXT *context;
- POINTER *argarray[];
- {
- if (fsprint(fscurform(context), FRS_HEADER) == SUCCEED)
- {
- fsmessage("The data will be printed.");
- }
- else
- {
- fsmessage("Sorry, cannot print the data.");
- }
- return;
- }
-