Skip to Content.
Sympa Menu

freetds - [freetds] tds_process_tokens function

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddyz77 AT tin.it>
  • To: FreeTDS <freetds AT lists.ibiblio.org>
  • Subject: [freetds] tds_process_tokens function
  • Date: Wed, 13 Apr 2005 19:20:25 +0200

Well, I added this function to libTDS. This function should supercede:
- tds_process_result_tokens
- tds_process_row_tokens
- tds_process_trailing_tokens
Also code of tds_process_cancel is much esier.

The idea is to divide tokens in classes and tell how to handle each
class.

in tds.h are defined these classes

enum tds_token_results
{
TDS_TOKEN_RES_OTHERS,
TDS_TOKEN_RES_ROWFMT,
TDS_TOKEN_RES_COMPUTEFMT,
TDS_TOKEN_RES_PARAMFMT,
TDS_TOKEN_RES_DONE,
TDS_TOKEN_RES_ROW,
TDS_TOKEN_RES_COMPUTE,
TDS_TOKEN_RES_PROC
};

(which should be clear)
And these flags (witch can be combined)

#define TDS_TOKEN_FLAG(flag) \
TDS_RETURN_##flag = (1 << (TDS_TOKEN_RES_##flag*2)), \
TDS_STOPAT_##flag = (2 << (TDS_TOKEN_RES_##flag*2))

enum tds_token_flags
{
TDS_HANDLE_ALL = 0,
TDS_TOKEN_FLAG(OTHERS),
TDS_TOKEN_FLAG(ROWFMT),
TDS_TOKEN_FLAG(COMPUTEFMT),
TDS_TOKEN_FLAG(PARAMFMT),
TDS_TOKEN_FLAG(DONE),
TDS_TOKEN_FLAG(ROW),
TDS_TOKEN_FLAG(COMPUTE),
TDS_TOKEN_FLAG(PROC)
};

Caller can decide to let tds_process_tokens handle some tokens, stop
before some others or return some others. By default function handle
(process but not return) all kind of tokens, adding some flags instruct
function to stop before some tokens or return them.

For example if we want to get only row and stop at any other token we
can call function in this way

const unsigned only_row = TDS_STOPAT_OTHERS | TDS_STOPAT_ROWFMT |
TDS_STOPAT_COMPUTEFMT | TDS_STOPAT_PARAMFMT | TDS_STOPAT_DONE |
TDS_STOPAT_COMPUTE | TDS_STOPAT_PROC | TDS_RETURN_ROW;

TDS_INT result_type;
int result = tds_process_tokens(tds, &result_type, NULL, only_row);

I honestly don't link the long constant in code however in many places
we must handle tokens in a slight different version (for example we want
rows but not computed one, we want row and handle others tokens) so I
hope to avoid others strange functions/flags to catch different kind of
tokens.

Now I rewrote tds_process_*_tokens using this function, in the near
future I think to rewrite all libraries to use this function directly
removing old function from token.c. Also I'll remove the ugly tds_peek
use in dblib/ctlib...

freddy77






Archive powered by MHonArc 2.6.24.

Top of Page