56 #define TDS_FIND(k,b,c) tds_find(k, b, sizeof(b)/sizeof(b[0]), sizeof(b[0]), c)
61 tds_find(
const void *
key,
const void *base,
size_t nelem,
size_t width,
65 for (
i=0;
i < nelem;
i++) {
66 char *p = (
char*)base + width *
i;
67 if (
true == compar(
key, p)) {
128 memset(p, 0,
sizeof(*p));
145 return pc1->data.ti ==
pc2->data.ti?
true :
false;
147 return pc1->data.si ==
pc2->data.si?
true :
false;
149 return pc1->data.i ==
pc2->data.i?
true :
false;
151 return pc1->data.f ==
pc2->data.f?
true :
false;
153 return pc1->data.r ==
pc2->data.r?
true :
false;
195 return &pcol->
data.
i;
197 return &pcol->
data.
f;
199 return &pcol->
data.
r;
231 col_print(FILE*
out,
const struct col_t *pcol)
239 return (
int) fwrite(pcol->
s, pcol->
len, 1,
out);
241 return fprintf(
out,
"%d", (
int)pcol->
ti);
243 return fprintf(
out,
"%d", (
int)pcol->
si);
245 return fprintf(
out,
"%d", (
int)pcol->
i);
247 return fprintf(
out,
"%f", pcol->
f);
249 return fprintf(
out,
"%f", (
double)pcol->
r);
275 static struct col_t *
281 memcpy(pdest, psrc,
sizeof(*pdest));
287 memcpy(pdest->
s, psrc->
s, psrc->
len);
359 join(
int argc,
char *argv[],
const char sep[])
364 for (p=argv; p < argv + argc; p++) {
368 len += 1 + argc * strlen(sep);
372 for (p=argv; p < argv + argc; p++) {
417 assert(
false && sybtype );
459 assert(
false && sybtype );
480 for (
i=0;
i <
a->nkeys;
i++) {
493 memset(p, 0,
sizeof(*p));
520 const struct col_t *pc;
532 for(pc=k->
keys; pc < k->keys + k->
nkeys; pc++) {
555 agg_key_equal(
const void *
a,
const void *
b)
647 #define TEST_MALLOC(dest,type) \
648 {if (!(dest = (type*)calloc(1, sizeof(type)))) goto Cleanup;}
651 #define TEST_CALLOC(dest,type,n) \
652 {if (!(dest = (type*)calloc((n), sizeof(type)))) goto Cleanup;}
654 #define tds_alloc_column() ((TDSCOLUMN*) calloc(1, sizeof(TDSCOLUMN)))
666 for (ppcol = res_info->
columns; ppcol < res_info->columns + num_cols; ppcol++)
704 "\tserver's type = %d (%s)\n"
705 "\tcolumn_varint_size = %d\n"
706 "\tcolumn_size = %d (%d on server)\n",
743 tdsdump_log(
TDS_DBG_INFO1,
"set current_results (%u column%s) to tds->res_info\n", (
unsigned) num_cols, (num_cols==1?
"":
"s"));
748 for (
i = 0;
i < num_cols;
i++) {
750 info->columns[
i]->bcp_terminator = (
char*) meta[
i].pacross;
754 static const char dashes[31] =
"------------------------------";
758 for (
i = 0;
i < num_cols;
i++) {
792 return a->dbproc ==
b->dbproc?
true :
false;
813 AGG_T candidate, *pout;
830 memset(&candidate, 0,
sizeof(candidate));
848 "no pcol->column_varaddr in col %d\n",
i);
859 (&candidate, pout, pp->
output + pp->
nout - pout,
877 "copying col %d, type %d/%d, len %d to %p\n",
880 switch (pval->
type) {
928 enum { logalot = 1 };
935 tdsdump_log(
TDS_DBG_FUNC,
"dbpivot(%p, %d,%p, %d,%p, %p, %d)\n",
dbproc, nkeys, keys, ncols, cols, func,
val);
938 const static char *
const names[2] = {
"\tkeys (down)",
"\n\tcols (across)" };
939 int *p = keys, *pend = p + nkeys;
941 for (
i=0;
i < 2;
i++) {
942 const char *sep =
"";
943 s += sprintf(s,
"%s: ",
names[
i]);
944 for ( ; p < pend; p++) {
945 s += sprintf(s,
"%s%d", sep, *p);
969 memset(pp, 0,
sizeof(*pp));
973 input.row_key.nkeys = nkeys;
974 for (
i=0;
i < nkeys;
i++) {
991 input.col_key.nkeys = ncols;
992 for (
i=0;
i < ncols;
i++) {
1073 for (
i=0;
i <
input.row_key.nkeys;
i++) {
1081 for (
i=0, pmeta = metadata +
input.row_key.nkeys; i < pp->nacross;
i++) {
1085 assert(pmeta +
i < metadata + nmeta);
1102 char name[256] = {0};
1104 assert(pp->pout->col_key.keys[0].len <
sizeof(name));
1105 memset(name,
'\0',
sizeof(name));
1106 memcpy(name, pp->pout->col_key.keys[0].s, pp->pout->col_key.keys[0].len),
1108 pp->pout->row_key.keys[0].i, name,
1109 pp->pout->value.i );
1142 switch (src->
type) {
1198 switch (src->
type) {
1254 switch (src->
type) {
1321 return n ?
n->func :
NULL;
STATUS dbnextrow(DBPROCESS *dbproc)
@ _DB_RES_RESULTSET_EMPTY
enum tag_DB_RESULT_STATE DB_RESULT_STATE
#define tds_alloc_column()
static bool col_equal(const struct col_t *pc1, const struct col_t *pc2)
static bool name_equal(const struct name_t *n1, const struct name_t *n2)
static struct col_t * col_init(struct col_t *pcol, int sybtype, size_t collen)
bool(* compare_func)(const void *, const void *)
static bool col_null(const struct col_t *pcol)
static TDS_SERVER_TYPE infer_col_type(int sybtype)
void dbpivot_count(struct col_t *tgt, const struct col_t *src)
static bool key_equal(const KEY_T *a, const KEY_T *b)
static TDSRET set_result_column(TDSSOCKET *tds, TDSCOLUMN *curcol, const char name[], const struct col_t *pvalue)
static const struct name_t names[]
static void * tds_find(const void *key, const void *base, size_t nelem, size_t width, compare_func compar)
static struct col_t * col_cpy(struct col_t *pdest, const struct col_t *psrc)
static char * join(int argc, char *argv[], const char sep[])
#define TEST_CALLOC(dest, type, n)
static KEY_T * key_cpy(KEY_T *pdest, const KEY_T *psrc)
static void agg_free(AGG_T *p)
static void col_free(struct col_t *p)
PIVOT_T * dbrows_pivoted(DBPROCESS *dbproc)
static bool reinit_results(TDSSOCKET *tds, TDS_USMALLINT num_cols, const struct metadata_t meta[])
#define TEST_MALLOC(dest, type)
DBPIVOT_FUNC dbpivot_lookup_name(const char name[])
void dbpivot_min(struct col_t *tgt, const struct col_t *src)
STATUS dbnextrow_pivoted(DBPROCESS *dbproc, PIVOT_T *pp)
static bool pivot_key_equal(const PIVOT_T *a, const PIVOT_T *b)
static bool agg_next(const AGG_T *p1, const AGG_T *p2)
static TDSRESULTINFO * alloc_results(TDS_USMALLINT num_cols)
static bool agg_equal(const AGG_T *p1, const AGG_T *p2)
void dbpivot_max(struct col_t *tgt, const struct col_t *src)
static char * string_value(const struct col_t *pcol)
#define TDS_FIND(k, b, c)
void dbpivot_sum(struct col_t *tgt, const struct col_t *src)
static int bind_type(int sybtype)
static char * make_col_name(DBPROCESS *dbproc, const KEY_T *k)
static void * col_buffer(struct col_t *pcol)
static void key_free(KEY_T *p)
RETCODE dbpivot(DBPROCESS *dbproc, int nkeys, int *keys, int ncols, int *cols, DBPIVOT_FUNC func, int val)
Pivot the rows, creating a new resultset.
std::ofstream out("events_result.xml")
main entry point for tests
int dbcoltype(DBPROCESS *dbproc, int column)
Get the datatype of a regular result set column.
RETCODE dbnullbind(DBPROCESS *dbproc, int column, DBINT *indicator)
Tie a null-indicator to a regular result column.
RETCODE dbbind(DBPROCESS *dbproc, int column, int vartype, DBINT varlen, BYTE *varaddr)
Tie a host variable to a resultset column.
DBINT dbcollen(DBPROCESS *dbproc, int column)
Get size of a regular result column.
char * dbcolname(DBPROCESS *dbproc, int column)
Return name of a regular result column.
static const char * tds_dstr_cstr(DSTR *s)
Returns a C version (NUL terminated string) of dstr.
DSTR * tds_dstr_copy(DSTR *s, const char *src) TDS_WUR
copy a string from another
#define P(a, b, c, d, k, s, t)
const struct ncbi::grid::netcache::search::fields::KEY key
int strncmp(const char *str1, const char *str2, size_t count)
int strcmp(const char *str1, const char *str2)
static pcre_uint8 * buffer
static SQLCHAR output[256]
#define copy_data_to_host_var
#define tds_set_column_type
#define tds_free_all_results
#define tds_set_current_results
DB_RESULT_STATE dbresults_state
tds_func_get_info * get_info
Metadata about columns in regular and compute rows.
TDS_CHAR * bcp_terminator
TDS_TINYINT column_varint_size
size of length when reading from wire (0, 1, 2 or 4)
TDS_SMALLINT * column_nullbind
TDS_INT column_size
maximun size of data.
unsigned int column_timestamp
const TDSCOLUMNFUNCS * funcs
TDS_SMALLINT column_bindtype
unsigned int column_writeable
unsigned char * column_data
TDS_SERVER_TYPE column_type
This type can be different from wire type because conversion (e.g.
unsigned int column_identity
unsigned int column_nullable
TDS_CHAR * column_varaddr
struct tds_column::@124 on_server
TDS_INT column_cur_size
size written in variable (ie: char, text, binary).
DB_RESULT_STATE dbresults_state
Hold information for any results.
Information for a server connection.
TDS_INT8 rows_affected
rows updated/deleted/inserted/selected, TDS_NO_COUNT if not valid
TDSCURSOR * cur_cursor
cursor in use
void(* DBPIVOT_FUNC)(struct col_t *output, const struct col_t *input)
Main include file for libtds.
#define tds_new0(type, n)
tds_sysdep_uint16_type TDS_USMALLINT
#define TDS_RESIZE(p, n_elem)