home *** CD-ROM | disk | FTP | other *** search
-
- 1 Version 4.0 -- 5/1/89 dbsetbusy
- ______________________________________________________________________
-
- NAME: dbsetbusy
-
- FUNCTION:
- Call a user-supplied function when DB-Library is reading from
- SQL Server.
-
- SYNTAX:
- void dbsetbusy(dbproc, busyfunc)
-
- DBPROCESS *dbproc;
- void (*(*busyfunc)())();
-
-
-
-
-
-
-
-
- dbsetbusy Version 4.0 -- 5/1/89 2
- ______________________________________________________________________
-
- COMMENTS:
-
- o This routine associates a user-supplied function with the
- specified dbproc. The user-supplied function will automati-
- cally be called whenever DB-Library is reading or waiting to
- read output from SQL Server. For example, an application may
- want to print a message whenever SQL Server is accessed.
- dbsetbusy() will cause the user-supplied function busyfunc() to
- be called in this case.
- o Similarly, dbsetidle() may also be used to associate a user-
- supplied function, idlefunc(), with a dbproc. idlefunc() will
- automatically be called whenever DB-Library has finished read-
- ing output from SQL Server.
-
- o The server sends result data to the application in packets of
- 512 bytes. (The final packet in a set of results may be less
- than 512 bytes.) DB-Library calls busyfunc() at the beginning
-
-
- 3 Version 4.0 -- 5/1/89 dbsetbusy
- ______________________________________________________________________
- of each packet and idlefunc() at the end of each packet. If
- the output from the server spans multiple packets, busyfunc()
- and idlefunc() will be called multiple times.
-
- o Here's an example of installing and defining busyfunc() and
- idlefunc():
-
- int (*busyfunc())(); /* busyfunc is a function which returns
- * a pointer to a function which returns
- * an integer.
- */
- void idlefunc();
-
- int counterfunc();
- ...
-
- main()
- {
-
-
- dbsetbusy Version 4.0 -- 5/1/89 4
- ______________________________________________________________________
- DBPROCESS *dbproc;
- ...
-
- dbproc = dbopen(login, NULL);
-
- /* Now that we have a DBPROCESS, install the busy-function
- * and the idle-function.
- */
- dbsetbusy(dbproc, busyfunc);
- dbsetidle(dbproc, idlefunc);
-
- dbcmd(dbproc, "select * from sysdatabases");
- dbcmd(dbproc, " select * from sysobjects");
- dbsqlexec(dbproc);
-
- /* DB-Library calls busyfunc() for the first time during
- * dbsqlexec(). Depending on the size of the results,
-
-
-
- 5 Version 4.0 -- 5/1/89 dbsetbusy
- ______________________________________________________________________
- * it may call busyfunc() again during processing of
- * the results. */
-
- while (dbresults(dbproc) != NO_MORE_RESULTS)
- dbprrow(dbproc);
-
- /* DB-Library calls idlefunc() each time a packet of results
- * has been received. Depending on the size of the results,
- * it may call idlefunc() multiple times during processing of
- the results. */
- ...
- }
-
- int (*busyfunc(dbproc))()
- DBPROCESS *dbproc;
- {
- printf("Waiting for data...\n");
-
-
-
- dbsetbusy Version 4.0 -- 5/1/89 6
- ______________________________________________________________________
-
- /* busyfunc returns a pointer to a routine which returns an integer. */
- return(counterfunc);
- }
-
- void idlefunc(procptr, dbproc)
- int (*procptr)(); /* idlefunc's first parameter is a pointer
- * to a routine which returns an integer.
- * This is the same pointer that busyfunc
- * returns.
- */
- DBPROCESS *dbproc;
- {
- int count;
-
- printf("Data is ready.\n");
- count = (*procptr)();
-
-
-
- 7 Version 4.0 -- 5/1/89 dbsetbusy
- ______________________________________________________________________
-
- printf
- ("Counterfunc has been called %d %s.\n",
- count, (count == 1 ? "time" : "times"));
-
- }
-
- int counterfunc()
- {
- static int counter = 0;
-
- return(++counter);
- }
-
-
- PARAMETERS:
- dbproc - A pointer to the DBPROCESS structure that provides the
-
-
-
- dbsetbusy Version 4.0 -- 5/1/89 8
- ______________________________________________________________________
- connection for a particular front-end/SQL Server process. It
- contains all the information that DB-Library uses to manage
- communications and data between the front end and SQL Server.
- busyfunc - The user-supplied function that DB-Library will call
- whenever it accesses SQL Server. DB-Library calls busyfunc()
- with a single parameter-a pointer to the DBPROCESS from the
- dbsetbusy() call.
-
- busyfunc() returns a pointer to a function that returns an
- integer.
-
- RETURNS:
- None.
-
- SEE ALSO:
- dbsetidle
-
-
-
-