Subject | Re: XSQLVAR->sqltype flag bit explained |
---|---|
Author | David Rushby <woodsplitter@rocketmail.co |
Post date | 2003-02-03T01:12:44Z |
FWIW, I use the following macros to manage sqltype and sqlind:
--------------------------------------------------------------
#define SQLIND_NOT_NULL 0
#define SQLIND_NULL -1
/* See IB6 API Guide page 92. */
#define XSQLVAR_IS_ALLOWED_TO_BE_NULL(sqlvar) \
((sqlvar->sqltype & 1) != 0)
#define XSQLVAR_IS_NULL(sqlvar) \
(*(sqlvar->sqlind) == SQLIND_NULL)
#define XSQLVAR_SQLTYPE_IGNORING_NULL_FLAG(sqlvar) \
(sqlvar->sqltype & ~1)
#define XSQLVAR_SQLTYPE_READ_NULL_FLAG(sqlvar) \
(sqlvar->sqltype & 1)
#define XSQLVAR_SET_NULL(sqlvar) \
(*(sqlvar->sqlind) = SQLIND_NULL)
#define XSQLVAR_SET_NOT_NULL(sqlvar) \
(*(sqlvar->sqlind) = SQLIND_NOT_NULL)
--------------------------------------------------------
These allow me to write C code like:
--------------------------------------------------------
if (
XSQLVAR_IS_ALLOWED_TO_BE_NULL(sqlvar)
&& XSQLVAR_IS_NULL(sqlvar)
) {
// handle a null value
}
--------------------------------------------------------
which IMO is more readable than:
--------------------------------------------------------
if (sqlvar->sqltype & 1 == 1 && sqlvar->sqlind == 0) {
// handle a null value
}
--------------------------------------------------------
--------------------------------------------------------------
#define SQLIND_NOT_NULL 0
#define SQLIND_NULL -1
/* See IB6 API Guide page 92. */
#define XSQLVAR_IS_ALLOWED_TO_BE_NULL(sqlvar) \
((sqlvar->sqltype & 1) != 0)
#define XSQLVAR_IS_NULL(sqlvar) \
(*(sqlvar->sqlind) == SQLIND_NULL)
#define XSQLVAR_SQLTYPE_IGNORING_NULL_FLAG(sqlvar) \
(sqlvar->sqltype & ~1)
#define XSQLVAR_SQLTYPE_READ_NULL_FLAG(sqlvar) \
(sqlvar->sqltype & 1)
#define XSQLVAR_SET_NULL(sqlvar) \
(*(sqlvar->sqlind) = SQLIND_NULL)
#define XSQLVAR_SET_NOT_NULL(sqlvar) \
(*(sqlvar->sqlind) = SQLIND_NOT_NULL)
--------------------------------------------------------
These allow me to write C code like:
--------------------------------------------------------
if (
XSQLVAR_IS_ALLOWED_TO_BE_NULL(sqlvar)
&& XSQLVAR_IS_NULL(sqlvar)
) {
// handle a null value
}
--------------------------------------------------------
which IMO is more readable than:
--------------------------------------------------------
if (sqlvar->sqltype & 1 == 1 && sqlvar->sqlind == 0) {
// handle a null value
}
--------------------------------------------------------