2
* ===========================================================================
5
* National Center for Biotechnology Information
7
* This software/database is a "United States Government Work" under the
8
* terms of the United States Copyright Act. It was written as part of
9
* the author's official duties as a United States Government employee and
10
* thus cannot be copyrighted. This software/database is freely available
11
* to the public for use. The National Library of Medicine and the U.S.
12
* Government have not placed any restriction on its use or reproduction.
14
* Although all reasonable efforts have been taken to ensure the accuracy
15
* and reliability of the software and data, the NLM and the U.S.
16
* Government do not and cannot warrant the performance or results that
17
* may be obtained by using this software or data. The NLM and the U.S.
18
* Government disclaim all warranties, express or implied, including
19
* warranties of performance, merchantability or fitness for any particular
22
* Please cite the author in any work or product based on this material.
24
* ===========================================================================
26
* File Name: txcproc.c
28
* Author: Vladimir Soussov
30
* File Description: taxonomy client communication procedures
34
* Revision 1.6 1999/12/20 17:05:17 soussov
37
* Revision 1.5 1998/07/27 16:55:08 soussov
40
* Revision 1.4 1998/04/01 17:33:57 soussov
41
* changed tp include <>
43
* Revision 1.3 1998/03/13 19:18:54 soussov
44
* add CS_CANCELED case for ct_results
46
* Revision 1.2 1998/02/11 15:53:13 soussov
47
* ctpublic.h was added
49
* Revision 1.1 1998/02/10 20:12:06 soussov
58
static CS_CONTEXT* te_context;
59
static CS_CONNECTION* te_link;
60
static CS_INT my_last_update= 0;
62
CS_RETCODE c_msg_proc(CS_CONTEXT* cp, CS_CONNECTION* chp, CS_CLIENTMSG* emsgp)
66
if(emsgp->msgstringlen > 0) {
67
sprintf(buff, "! ct error: %s\n", emsgp->msgstring);
68
ErrPostEx(SEV_ERROR, 100, 1, buff);
70
if((emsgp->osnumber != 0) && (emsgp->osstringlen > 0)) {
71
sprintf(buff, "! os error: %s\n", emsgp->osstring);
72
ErrPostEx(SEV_ERROR, 100, 2, buff);
74
if((emsgp->sqlstatelen > 0) && (strcmp(emsgp->sqlstate, "ZZZZZ") != 0)) {
75
sprintf(buff, "! sql statement: %s\n", emsgp->sqlstate);
76
ErrPostEx(SEV_ERROR, 100, 3, buff);
82
CS_RETCODE s_msg_proc(CS_CONTEXT* cp, CS_CONNECTION* chp, CS_SERVERMSG* msg)
86
if((msg->textlen > 0) && (msg->severity > 0)) {
87
sprintf(buff, "! server message: %s\t %s\t %s\t %s\n", msg->svrname, msg->proc, msg->text, msg->sqlstate);
88
ErrPostEx(SEV_ERROR, 100, 4, buff);
93
Boolean txc_connect2Server(CharPtr srv_name, CharPtr usr, CharPtr passwd, CharPtr applic)
98
cs_ctx_global(CS_VERSION_110, &te_context);
99
ct_init(te_context, CS_VERSION_110);
100
ct_config(te_context, CS_SET, CS_TIMEOUT, &t_out, CS_UNUSED, NULL);
102
ct_callback(te_context, NULL, CS_SET, CS_CLIENTMSG_CB, c_msg_proc);
103
ct_callback(te_context, NULL, CS_SET, CS_SERVERMSG_CB, s_msg_proc);
105
ct_con_alloc(te_context, &te_link);
106
ct_con_props(te_link, CS_SET, CS_USERNAME, usr, CS_NULLTERM, NULL);
107
ct_con_props(te_link, CS_SET, CS_PASSWORD, passwd, CS_NULLTERM, NULL);
108
ct_con_props(te_link, CS_SET, CS_APPNAME, applic, CS_NULLTERM, NULL);
109
if(ct_connect(te_link, srv_name, CS_NULLTERM) != CS_SUCCEED) {
115
Int4 tax_findByName(CharPtr sname, int mode, TaxNamePtr* res_name)
120
CS_INT res_type, rows_read, tax_id;
121
char nbuff[256], ubuff[256];
122
Boolean more_results= TRUE;
124
CS_SMALLINT has_unique;
125
CS_TINYINT class_cde, designator;
126
Int4 n= 0, alloc_room= 0;
127
TaxNamePtr fnd_name= NULL;
130
if(sname == NULL) return 0;
132
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
135
/* build command: tax_findByName @name_txt, @mode */
137
if(ct_command(cmd, CS_RPC_CMD, "tax_findByName", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
142
memset(&parfmt, 0, sizeof(CS_DATAFMT));
143
strcpy(parfmt.name, "@name_txt");
144
parfmt.namelen= CS_NULLTERM;
145
parfmt.datatype= CS_CHAR_TYPE;
146
parfmt.maxlength= strlen(sname);
147
parfmt.status= CS_INPUTVALUE;
149
if(ct_param(cmd, &parfmt, sname, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
154
strcpy(parfmt.name, "@mode");
155
parfmt.datatype= CS_TINYINT_TYPE;
159
if(ct_param(cmd, &parfmt, &smode, 1, CS_UNUSED) != CS_SUCCEED) {
164
/* send this command to server */
165
if(ct_send(cmd) != CS_SUCCEED) {
170
while(more_results && (--nnn > 0)) {
171
switch(ct_results(cmd, &res_type)) {
173
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
174
ct_close(te_link, CS_FORCE_CLOSE);
180
case CS_END_RESULTS :
185
if(res_type == CS_ROW_RESULT) {
186
/* bind and fetch these data */
188
parfmt.datatype= CS_INT_TYPE;
189
parfmt.format= CS_FMT_UNUSED;
191
parfmt.scale= CS_SRC_VALUE;
192
parfmt.precision= CS_SRC_VALUE;
195
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
197
parfmt.datatype= CS_CHAR_TYPE;
198
parfmt.format= CS_FMT_NULLTERM;
199
parfmt.maxlength= 255;
200
if((ct_bind(cmd, 2, &parfmt, nbuff, NULL, NULL) != CS_SUCCEED) ||
201
(ct_bind(cmd, 3, &parfmt, ubuff, NULL, &has_unique) != CS_SUCCEED)) break;
203
parfmt.datatype= CS_TINYINT_TYPE;
204
parfmt.format= CS_FMT_UNUSED;
206
if((ct_bind(cmd, 4, &parfmt, &class_cde, NULL, NULL) != CS_SUCCEED) ||
207
(ct_bind(cmd, 5, &parfmt, &designator, NULL, NULL) != CS_SUCCEED)) break;
210
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
213
*res_name= fnd_name= malloc(sizeof(TaxName));
216
else if(n >= alloc_room) {
218
alloc_room+= (8 > (alloc_room/4))? 8 : (alloc_room/4);
219
*res_name= realloc(fnd_name, alloc_room*sizeof(TaxName));
220
if(*res_name == NULL) {
224
else fnd_name= *res_name;
227
fnd_name[n].tax_id= tax_id;
228
fnd_name[n].class_cde= class_cde;
229
fnd_name[n].designator= designator;
230
fnd_name[n].name_txt= StringSave(nbuff);
231
fnd_name[n].unique_name= (has_unique < 0)? NULL : StringSave(ubuff);
243
/* this is a error */
245
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
246
ct_close(te_link, CS_FORCE_CLOSE);
262
Int4 tax_getDesignator(char* sname)
266
CS_INT res_type, rows_read, tax_id= 0;
267
Boolean more_results= TRUE;
271
if((sname == NULL) || (*sname == '\0')) return 0;
273
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
275
/* build command: tax_getDesignator @name_txt */
277
if(ct_command(cmd, CS_RPC_CMD, "tax_getDesignator", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
282
memset(&parfmt, 0, sizeof(CS_DATAFMT));
283
strcpy(parfmt.name, "@name_txt");
284
parfmt.namelen= CS_NULLTERM;
285
parfmt.datatype= CS_CHAR_TYPE;
286
parfmt.maxlength= strlen(sname);
287
parfmt.status= CS_INPUTVALUE;
289
if(ct_param(cmd, &parfmt, sname, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
294
/* send this command to server */
295
if(ct_send(cmd) != CS_SUCCEED) {
300
while(more_results && (--nnn > 0)) {
301
switch(ct_results(cmd, &res_type)) {
303
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
304
ct_close(te_link, CS_FORCE_CLOSE);
310
case CS_END_RESULTS :
315
if(res_type == CS_STATUS_RESULT) {
317
parfmt.datatype= CS_INT_TYPE;
318
parfmt.format= CS_FMT_UNUSED;
320
parfmt.scale= CS_SRC_VALUE;
321
parfmt.precision= CS_SRC_VALUE;
323
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
325
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
337
/* this is a error */
339
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
340
ct_close(te_link, CS_FORCE_CLOSE);
357
Int4 tax_uniqueName(char* sname, Int4 id)
361
CS_INT res_type, rows_read, tax_id= 0;
362
Boolean more_results= TRUE;
366
if((sname == NULL) || (*sname == '\0')) return 0;
368
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
370
/* build command: tax_checkUnique @name_txt, @tax_id */
372
if(ct_command(cmd, CS_RPC_CMD, "tax_checkUnique", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
377
memset(&parfmt, 0, sizeof(CS_DATAFMT));
378
strcpy(parfmt.name, "@name_txt");
379
parfmt.namelen= CS_NULLTERM;
380
parfmt.datatype= CS_CHAR_TYPE;
381
parfmt.maxlength= strlen(sname);
382
parfmt.status= CS_INPUTVALUE;
384
if(ct_param(cmd, &parfmt, sname, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
389
strcpy(parfmt.name, "@tax_id");
390
parfmt.datatype= CS_INT_TYPE;
391
parfmt.maxlength= sizeof(CS_INT);
392
if(ct_param(cmd, &parfmt, &id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
397
/* send this command to server */
398
if(ct_send(cmd) != CS_SUCCEED) {
403
while(more_results && (--nnn > 0)) {
404
switch(ct_results(cmd, &res_type)) {
406
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
407
ct_close(te_link, CS_FORCE_CLOSE);
413
case CS_END_RESULTS :
418
if(res_type == CS_STATUS_RESULT) {
420
parfmt.datatype= CS_INT_TYPE;
421
parfmt.format= CS_FMT_UNUSED;
423
parfmt.scale= CS_SRC_VALUE;
424
parfmt.precision= CS_SRC_VALUE;
426
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
428
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
440
/* this is a error */
442
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
443
ct_close(te_link, CS_FORCE_CLOSE);
460
Int4 tax_getIdByName(char* sname, char* qualif, Int1 id)
464
CS_INT res_type, rows_read, tax_id= 0;
466
Boolean more_results= TRUE;
471
if((sname == NULL) || (*sname == '\0')) return 0;
473
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
475
/* build command: tax_getIdByName(@org_name, @qualif, @q_type) */
477
if(ct_command(cmd, CS_RPC_CMD, "tax_getIdByName", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
482
memset(&parfmt, 0, sizeof(CS_DATAFMT));
483
strcpy(parfmt.name, "@org_name");
484
parfmt.namelen= CS_NULLTERM;
485
parfmt.datatype= CS_CHAR_TYPE;
486
strncpy(s_sname, sname, 96);
488
parfmt.maxlength= strlen(s_sname);
489
parfmt.status= CS_INPUTVALUE;
491
if(ct_param(cmd, &parfmt, s_sname, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
495
strcpy(parfmt.name, "@qualif");
497
s_qualif[0]= s_qualif[1]= '\0';
501
strncpy(s_qualif, qualif, 116);
503
parfmt.maxlength= strlen(s_qualif);
506
if(ct_param(cmd, &parfmt, s_qualif, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
511
strcpy(parfmt.name, "@q_type");
512
parfmt.datatype= CS_TINYINT_TYPE;
513
parfmt.maxlength= sizeof(CS_TINYINT);
514
if(ct_param(cmd, &parfmt, &id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
519
/* send this command to server */
520
if(ct_send(cmd) != CS_SUCCEED) {
525
while(more_results && (--nnn > 0)) {
526
switch(ct_results(cmd, &res_type)) {
528
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
529
ct_close(te_link, CS_FORCE_CLOSE);
535
case CS_END_RESULTS :
540
if(res_type == CS_STATUS_RESULT) {
542
parfmt.datatype= CS_INT_TYPE;
543
parfmt.format= CS_FMT_UNUSED;
545
parfmt.scale= CS_SRC_VALUE;
546
parfmt.precision= CS_SRC_VALUE;
548
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
550
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
562
/* this is a error */
564
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
565
ct_close(te_link, CS_FORCE_CLOSE);
582
Int4 tax_getOrgNames(Int4 tax_id, TaxNamePtr* res_name)
587
CS_INT res_type, rows_read;
588
Boolean more_results= TRUE;
590
char nbuff[256], ubuff[256];
591
CS_SMALLINT has_unique;
592
CS_TINYINT class_cde, designator;
593
Int4 n= 0, alloc_room= 0;
594
TaxNamePtr fnd_name= NULL;
597
if(tax_id <= 0) return 0;
599
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
602
/* build command: tax_getOrgNames @tax_id */
604
if(ct_command(cmd, CS_RPC_CMD, "tax_getOrgNames", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
609
memset(&parfmt, 0, sizeof(CS_DATAFMT));
610
strcpy(parfmt.name, "@tax_id");
611
parfmt.namelen= CS_NULLTERM;
612
parfmt.datatype= CS_INT_TYPE;
613
parfmt.maxlength= sizeof(Int4);
614
parfmt.status= CS_INPUTVALUE;
616
if(ct_param(cmd, &parfmt, &tax_id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
621
/* send this command to server */
622
if(ct_send(cmd) != CS_SUCCEED) {
627
while(more_results && (--nnn > 0)) {
628
switch(ct_results(cmd, &res_type)) {
630
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
631
ct_close(te_link, CS_FORCE_CLOSE);
637
case CS_END_RESULTS :
642
if(res_type == CS_ROW_RESULT) {
643
/* bind and fetch these data */
645
parfmt.datatype= CS_INT_TYPE;
646
parfmt.format= CS_FMT_UNUSED;
648
parfmt.scale= CS_SRC_VALUE;
649
parfmt.precision= CS_SRC_VALUE;
652
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
654
parfmt.datatype= CS_CHAR_TYPE;
655
parfmt.format= CS_FMT_NULLTERM;
656
parfmt.maxlength= 255;
657
if((ct_bind(cmd, 2, &parfmt, nbuff, NULL, NULL) != CS_SUCCEED) ||
658
(ct_bind(cmd, 3, &parfmt, ubuff, NULL, &has_unique) != CS_SUCCEED)) break;
660
parfmt.datatype= CS_TINYINT_TYPE;
661
parfmt.format= CS_FMT_UNUSED;
663
if((ct_bind(cmd, 4, &parfmt, &class_cde, NULL, NULL) != CS_SUCCEED) ||
664
(ct_bind(cmd, 5, &parfmt, &designator, NULL, NULL) != CS_SUCCEED)) break;
667
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
670
*res_name= fnd_name= malloc(sizeof(TaxName));
673
else if(n >= alloc_room) {
675
alloc_room+= (8 > (alloc_room/4))? 8 : (alloc_room/4);
676
*res_name= realloc(fnd_name, alloc_room*sizeof(TaxName));
677
if(*res_name == NULL) {
681
else fnd_name= *res_name;
684
fnd_name[n].tax_id= tax_id;
685
fnd_name[n].class_cde= class_cde;
686
fnd_name[n].designator= designator;
687
fnd_name[n].name_txt= StringSave(nbuff);
688
fnd_name[n].unique_name= (has_unique < 0)? NULL : StringSave(ubuff);
700
/* this is an error */
702
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
703
ct_close(te_link, CS_FORCE_CLOSE);
720
TXC_NodeDataPtr txc_getOrgData(Int4 tax_id)
724
CS_INT res_type, rows_read;
725
CS_SMALLINT rank_id, gc_id, mgc_id, div_id;
726
Boolean more_results= TRUE;
728
TXC_NodeDataPtr node_data= NULL;
732
if(tax_id <= 0) return 0;
734
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
737
/* build command: tax_getOrgData @tax_id */
739
if(ct_command(cmd, CS_RPC_CMD, "tax_getOrgData", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
744
memset(&parfmt, 0, sizeof(CS_DATAFMT));
745
strcpy(parfmt.name, "@tax_id");
746
parfmt.namelen= CS_NULLTERM;
747
parfmt.datatype= CS_INT_TYPE;
748
parfmt.maxlength= sizeof(Int4);
749
parfmt.status= CS_INPUTVALUE;
751
if(ct_param(cmd, &parfmt, &tax_id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
756
/* send this command to server */
757
if(ct_send(cmd) != CS_SUCCEED) {
762
while(more_results && (--nnn > 0)) {
763
switch(ct_results(cmd, &res_type)) {
765
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
766
ct_close(te_link, CS_FORCE_CLOSE);
772
case CS_END_RESULTS :
777
if(res_type == CS_ROW_RESULT) {
778
/* bind and fetch these data */
779
if(node_data == NULL) {
780
if((node_data= MemNew(sizeof(TXC_NodeData))) == NULL) {
781
ct_cancel(NULL, cmd, CS_CANCEL_ALL);
785
node_data->tax_id= tax_id;
789
parfmt.datatype= CS_INT_TYPE;
790
parfmt.format= CS_FMT_UNUSED;
792
parfmt.scale= CS_SRC_VALUE;
793
parfmt.precision= CS_SRC_VALUE;
796
if((ct_bind(cmd, 1, &parfmt, &node_data->crt_date, NULL, NULL) != CS_SUCCEED) ||
797
(ct_bind(cmd, 2, &parfmt, &node_data->upd_date, NULL, NULL) != CS_SUCCEED)) break;
799
parfmt.datatype= CS_SMALLINT_TYPE;
801
if((ct_bind(cmd, 3, &parfmt, &rank_id, NULL, NULL) != CS_SUCCEED) ||
802
(ct_bind(cmd, 4, &parfmt, &gc_id, NULL, NULL) != CS_SUCCEED) ||
803
(ct_bind(cmd, 5, &parfmt, &mgc_id, NULL, NULL) != CS_SUCCEED) ||
804
(ct_bind(cmd, 6, &parfmt, &div_id, NULL, NULL) != CS_SUCCEED) ||
805
(ct_bind(cmd, 7, &parfmt, &node_data->flags, NULL, NULL) != CS_SUCCEED)) break;
807
parfmt.datatype= CS_CHAR_TYPE;
808
parfmt.format= CS_FMT_NULLTERM;
810
if(ct_bind(cmd, 8, &parfmt, embl_buff, NULL, NULL) != CS_SUCCEED) break;
813
switch(ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read)) {
815
node_data->rank_id= rank_id;
816
node_data->gc_id= gc_id;
817
node_data->mgc_id= mgc_id;
818
node_data->div_id= div_id;
819
StringNCpy(node_data->embl_cde, embl_buff, 4);
830
/* this is an error */
832
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
833
ct_close(te_link, CS_FORCE_CLOSE);
850
Boolean txc_loadNameClasses()
854
CS_SMALLINT class_cde, priority;
855
CS_INT res_type, rows_read;
857
Boolean more_results= TRUE;
861
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
864
/* build command: tax_dumpClasses() */
866
if(ct_command(cmd, CS_RPC_CMD, "tax_dumpClasses", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
871
/* send this command to server */
872
if(ct_send(cmd) != CS_SUCCEED) {
877
memset(&datafmt, 0, sizeof(CS_DATAFMT));
879
while(more_results && (--nnn > 0)) {
880
switch(ct_results(cmd, &res_type)) {
882
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
883
ct_close(te_link, CS_FORCE_CLOSE);
889
case CS_END_RESULTS :
894
if(res_type == CS_ROW_RESULT) {
895
/* bind and fetch these data */
897
datafmt.datatype= CS_SMALLINT_TYPE;
898
datafmt.format= CS_FMT_UNUSED;
899
datafmt.maxlength= sizeof(CS_SMALLINT);
900
datafmt.scale= CS_SRC_VALUE;
901
datafmt.precision= CS_SRC_VALUE;
903
datafmt.locale= NULL;
904
if((ct_bind(cmd, 1, &datafmt, &class_cde, NULL, NULL) != CS_SUCCEED) ||
905
(ct_bind(cmd, 2, &datafmt, &priority, NULL, NULL) != CS_SUCCEED)) break;
907
datafmt.datatype= CS_CHAR_TYPE;
908
datafmt.format= CS_FMT_NULLTERM;
909
datafmt.maxlength= 128;
910
if(ct_bind(cmd, 3, &datafmt, class_txt, NULL, NULL) != CS_SUCCEED) break;
913
switch(ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read)) {
915
tax_addNameClass(class_cde, class_txt, priority);
926
/* this is an error */
928
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
929
ct_close(te_link, CS_FORCE_CLOSE);
946
Boolean txc_loadRanks()
951
CS_INT res_type, rows_read;
953
Boolean more_results= TRUE;
957
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
960
/* build command: tax_dumpRanks() */
962
if(ct_command(cmd, CS_RPC_CMD, "tax_dumpRanks", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
967
/* send this command to server */
968
if(ct_send(cmd) != CS_SUCCEED) {
973
memset(&datafmt, 0, sizeof(CS_DATAFMT));
975
while(more_results && (--nnn > 0)) {
976
switch(ct_results(cmd, &res_type)) {
978
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
979
ct_close(te_link, CS_FORCE_CLOSE);
985
case CS_END_RESULTS :
990
if(res_type == CS_ROW_RESULT) {
991
/* bind and fetch these data */
993
datafmt.datatype= CS_SMALLINT_TYPE;
994
datafmt.format= CS_FMT_UNUSED;
995
datafmt.maxlength= sizeof(CS_SMALLINT);
996
datafmt.scale= CS_SRC_VALUE;
997
datafmt.precision= CS_SRC_VALUE;
999
datafmt.locale= NULL;
1000
if(ct_bind(cmd, 1, &datafmt, &rank_id, NULL, NULL) != CS_SUCCEED) break;
1002
datafmt.datatype= CS_CHAR_TYPE;
1003
datafmt.format= CS_FMT_NULLTERM;
1004
datafmt.maxlength= 128;
1005
if(ct_bind(cmd, 2, &datafmt, rank_txt, NULL, NULL) != CS_SUCCEED) break;
1008
switch(ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read)) {
1010
tax_addRank(rank_id, rank_txt);
1021
/* this is an error */
1023
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1024
ct_close(te_link, CS_FORCE_CLOSE);
1041
Boolean txc_loadDivisions()
1046
CS_INT res_type, rows_read;
1048
Boolean more_results= TRUE;
1050
char div_cde[8], div_txt[128];
1052
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
1055
/* build command: tax_dumpDivisions() */
1057
if(ct_command(cmd, CS_RPC_CMD, "tax_dumpDivisions", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1062
/* send this command to server */
1063
if(ct_send(cmd) != CS_SUCCEED) {
1068
memset(&datafmt, 0, sizeof(CS_DATAFMT));
1070
while(more_results && (--nnn > 0)) {
1071
switch(ct_results(cmd, &res_type)) {
1073
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1074
ct_close(te_link, CS_FORCE_CLOSE);
1080
case CS_END_RESULTS :
1081
more_results= FALSE;
1085
if(res_type == CS_ROW_RESULT) {
1086
/* bind and fetch these data */
1088
datafmt.datatype= CS_SMALLINT_TYPE;
1089
datafmt.format= CS_FMT_UNUSED;
1090
datafmt.maxlength= sizeof(CS_SMALLINT);
1091
datafmt.scale= CS_SRC_VALUE;
1092
datafmt.precision= CS_SRC_VALUE;
1094
datafmt.locale= NULL;
1095
if(ct_bind(cmd, 1, &datafmt, &div_id, NULL, NULL) != CS_SUCCEED) break;
1097
datafmt.datatype= CS_CHAR_TYPE;
1098
datafmt.format= CS_FMT_NULLTERM;
1099
datafmt.maxlength= 8;
1100
if(ct_bind(cmd, 2, &datafmt, div_cde, NULL, NULL) != CS_SUCCEED) break;
1102
datafmt.maxlength= 128;
1103
if(ct_bind(cmd, 3, &datafmt, div_txt, NULL, NULL) != CS_SUCCEED) break;
1106
switch(ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read)) {
1108
tax_addDivision(div_id, div_cde, div_txt);
1119
/* this is an error */
1121
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1122
ct_close(te_link, CS_FORCE_CLOSE);
1138
Boolean txc_loadGCs()
1143
CS_INT res_type, rows_read;
1145
Boolean more_results= TRUE;
1149
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
1152
/* build command: tax_dumpGCs() */
1154
if(ct_command(cmd, CS_RPC_CMD, "tax_dumpGCs", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1159
/* send this command to server */
1160
if(ct_send(cmd) != CS_SUCCEED) {
1165
memset(&datafmt, 0, sizeof(CS_DATAFMT));
1167
while(more_results && (--nnn > 0)) {
1168
switch(ct_results(cmd, &res_type)) {
1170
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1171
ct_close(te_link, CS_FORCE_CLOSE);
1177
case CS_END_RESULTS :
1178
more_results= FALSE;
1182
if(res_type == CS_ROW_RESULT) {
1183
/* bind and fetch these data */
1185
datafmt.datatype= CS_SMALLINT_TYPE;
1186
datafmt.format= CS_FMT_UNUSED;
1187
datafmt.maxlength= sizeof(CS_SMALLINT);
1188
datafmt.scale= CS_SRC_VALUE;
1189
datafmt.precision= CS_SRC_VALUE;
1191
datafmt.locale= NULL;
1192
if(ct_bind(cmd, 1, &datafmt, &gc_id, NULL, NULL) != CS_SUCCEED) break;
1194
datafmt.datatype= CS_CHAR_TYPE;
1195
datafmt.format= CS_FMT_NULLTERM;
1196
datafmt.maxlength= 128;
1197
if(ct_bind(cmd, 2, &datafmt, gc_name, NULL, NULL) != CS_SUCCEED) break;
1200
switch(ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows_read)) {
1202
tax_addGC(gc_id, gc_name);
1213
/* this is an error */
1215
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1216
ct_close(te_link, CS_FORCE_CLOSE);
1233
TXC_TreeNodePtr* txc_getLineage(Int4 lin_id, Int4Ptr lin_len)
1237
CS_INT res_type, rows_read, tax_id, flags;
1239
Boolean more_results= TRUE;
1241
Int4 n, l, alloc_room= 48;
1243
TXC_TreeNodePtr* lineage= NULL;
1248
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return FALSE;
1251
/* build command: tax_getLineage @tax_id=lin_id */
1253
if(ct_command(cmd, CS_RPC_CMD, "tax_getLineage", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1258
memset(&parfmt, 0, sizeof(CS_DATAFMT));
1259
strcpy(parfmt.name, "@tax_id");
1260
parfmt.namelen= CS_NULLTERM;
1261
parfmt.datatype= CS_INT_TYPE;
1262
parfmt.maxlength= CS_UNUSED;
1263
parfmt.status= CS_INPUTVALUE;
1264
parfmt.locale= NULL;
1265
if(ct_param(cmd, &parfmt, &lin_id, 4, CS_UNUSED) != CS_SUCCEED) {
1271
/* send this command to server */
1272
if(ct_send(cmd) != CS_SUCCEED) {
1278
while(more_results && (--nnn > 0)) {
1279
switch(ct_results(cmd, &res_type)) {
1281
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1282
ct_close(te_link, CS_FORCE_CLOSE);
1288
case CS_END_RESULTS :
1289
more_results= FALSE;
1293
if(res_type == CS_ROW_RESULT) {
1294
/* bind and fetch these data */
1296
parfmt.datatype= CS_INT_TYPE;
1297
parfmt.format= CS_FMT_UNUSED;
1298
parfmt.maxlength= 4;
1299
parfmt.scale= CS_SRC_VALUE;
1300
parfmt.precision= CS_SRC_VALUE;
1302
parfmt.locale= NULL;
1303
if((ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) ||
1304
(ct_bind(cmd, 2, &parfmt, &flags, NULL, NULL) != CS_SUCCEED)) {
1307
parfmt.datatype= CS_CHAR_TYPE;
1308
parfmt.format= CS_FMT_NULLTERM;
1309
parfmt.maxlength= 255;
1310
if(ct_bind(cmd, 3, &parfmt, label, NULL, NULL) != CS_SUCCEED) break;
1312
if(lineage == NULL) {
1313
lineage= MemNew(alloc_room*sizeof(TXC_TreeNodePtr));
1314
if(lineage == NULL) {
1315
ct_cancel(NULL, cmd, CS_CANCEL_ALL);
1323
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
1325
if(n >= alloc_room) {
1326
/* need more memory */
1327
TXC_TreeNodePtr* tmp= MemMore(lineage, (alloc_room + 8)*sizeof(TXC_TreeNodePtr));
1329
if(tmp == NULL) continue;
1333
l= StringLen(label) + 1;
1334
if((lineage[n]= MemNew(l + 8)) != NULL) {
1335
lineage[n]->tax_id= tax_id;
1336
lineage[n]->flags= flags;
1337
StringCpy(lineage[n]->node_label, label);
1338
if((flags & TXC_SUFFIX) != 0) {
1339
c= StringChr(lineage[n]->node_label, '~');
1340
if(c != NULL) *c= '\0';
1341
lineage[n]->flags^= TXC_SUFFIX; /* clear this flag */
1355
/* this is a error */
1357
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1358
ct_close(te_link, CS_FORCE_CLOSE);
1376
TXC_TreeNodePtr* txc_getChildren(Int4 node_id, Int4Ptr nof_children)
1380
CS_INT res_type, rows_read, tax_id, parent_id, flags, last_parent= -1;
1381
CS_SMALLINT levels= 1;
1383
Boolean more_results= TRUE;
1385
Int4 n, l, alloc_room= 16;
1387
TXC_TreeNodePtr* child= NULL;
1393
alloc_room= 64*1024;
1398
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
1401
/* build command: tax_getSubtree @root_id=root, @levels= levels */
1403
if(ct_command(cmd, CS_RPC_CMD, "tax_getSubtree", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1408
memset(&parfmt, 0, sizeof(CS_DATAFMT));
1409
strcpy(parfmt.name, "@root_id");
1410
parfmt.namelen= CS_NULLTERM;
1411
parfmt.datatype= CS_INT_TYPE;
1412
parfmt.maxlength= CS_UNUSED;
1413
parfmt.status= CS_INPUTVALUE;
1414
parfmt.locale= NULL;
1415
if(ct_param(cmd, &parfmt, &node_id, 4, CS_UNUSED) != CS_SUCCEED) {
1420
strcpy(parfmt.name, "@levels");
1421
parfmt.datatype= CS_SMALLINT_TYPE;
1422
parfmt.locale= NULL;
1423
if(ct_param(cmd, &parfmt, &levels, 2, CS_UNUSED) != CS_SUCCEED) {
1428
/* send this command to server */
1429
if(ct_send(cmd) != CS_SUCCEED) {
1435
while(more_results && (--nnn > 0)) {
1436
switch(ct_results(cmd, &res_type)) {
1438
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1439
ct_close(te_link, CS_FORCE_CLOSE);
1445
case CS_END_RESULTS :
1446
more_results= FALSE;
1450
if(res_type == CS_STATUS_RESULT) {
1452
parfmt.datatype= CS_INT_TYPE;
1453
parfmt.format= CS_FMT_UNUSED;
1454
parfmt.maxlength= 4;
1455
parfmt.scale= CS_SRC_VALUE;
1456
parfmt.precision= CS_SRC_VALUE;
1458
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
1460
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
1472
/* this is a error */
1474
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1475
ct_close(te_link, CS_FORCE_CLOSE);
1482
else if(res_type == CS_ROW_RESULT) {
1483
/* bind and fetch these data */
1485
parfmt.datatype= CS_INT_TYPE;
1486
parfmt.format= CS_FMT_UNUSED;
1487
parfmt.maxlength= 4;
1488
parfmt.scale= CS_SRC_VALUE;
1489
parfmt.precision= CS_SRC_VALUE;
1491
parfmt.locale= NULL;
1492
if((ct_bind(cmd, 1, &parfmt, &parent_id, NULL, NULL) != CS_SUCCEED) ||
1493
(ct_bind(cmd, 2, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) ||
1494
(ct_bind(cmd, 3, &parfmt, &flags, NULL, NULL) != CS_SUCCEED)) {
1497
parfmt.datatype= CS_CHAR_TYPE;
1498
parfmt.format= CS_FMT_NULLTERM;
1499
parfmt.maxlength= 255;
1500
if(ct_bind(cmd, 4, &parfmt, label, NULL, NULL) != CS_SUCCEED) break;
1504
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
1506
if(((levels == 1) && (parent_id != node_id)) || (tax_id == node_id)) continue;
1509
child= MemNew(alloc_room*sizeof(TXC_TreeNodePtr));
1511
ct_cancel(NULL, cmd, CS_CANCEL_ALL);
1517
else if(n >= alloc_room-1) {
1518
/* need more memory */
1519
TXC_TreeNodePtr* tmp=
1520
MemMore(child, (alloc_room + 8*levels)*sizeof(TXC_TreeNodePtr));
1522
if(tmp == NULL) continue;
1524
alloc_room+= 8*levels;
1526
if((levels > 1) && (parent_id != last_parent)) {
1527
last_parent= parent_id;
1528
child[n]= MemNew(8);
1529
child[n]->tax_id= parent_id;
1530
child[n++]->flags= TXC_SUFFIX;
1532
l= StringLen(label) + 1;
1533
if((child[n]= MemNew(l + 8)) != NULL) {
1534
child[n]->tax_id= tax_id;
1535
child[n]->flags= flags;
1536
StringCpy(child[n]->node_label, label);
1537
if((flags & TXC_SUFFIX) != 0) {
1538
c= StringChr(child[n]->node_label, '~');
1539
if(c != NULL) *c= '\0';
1540
child[n]->flags^= TXC_SUFFIX; /* clear this flag */
1553
/* this is a error */
1555
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1556
ct_close(te_link, CS_FORCE_CLOSE);
1578
TXC_CitListPtr txc_citGet4Node(Int4 tax_id, Int4Ptr nof_cit)
1582
CS_INT res_type, rows_read;
1584
Boolean more_results= TRUE;
1588
Int4 n= 0, alloc_room= 0;
1589
TXC_CitListPtr refer= NULL, tmp;
1591
if(tax_id <= 0) return NULL;
1593
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
1596
/* build command: tax_citGet4Node @tax_id */
1598
if(ct_command(cmd, CS_RPC_CMD, "tax_getCit4Node", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1603
memset(&parfmt, 0, sizeof(CS_DATAFMT));
1604
strcpy(parfmt.name, "@tax_id");
1605
parfmt.namelen= CS_NULLTERM;
1606
parfmt.datatype= CS_INT_TYPE;
1607
parfmt.maxlength= sizeof(Int4);
1608
parfmt.status= CS_INPUTVALUE;
1609
parfmt.locale= NULL;
1610
if(ct_param(cmd, &parfmt, &tax_id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
1615
/* send this command to server */
1616
if(ct_send(cmd) != CS_SUCCEED) {
1621
while(more_results && (--nnn > 0)) {
1622
switch(ct_results(cmd, &res_type)) {
1624
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1625
ct_close(te_link, CS_FORCE_CLOSE);
1631
case CS_END_RESULTS :
1632
more_results= FALSE;
1636
if(res_type == CS_ROW_RESULT) {
1637
/* bind and fetch these data */
1639
parfmt.datatype= CS_INT_TYPE;
1640
parfmt.format= CS_FMT_UNUSED;
1641
parfmt.maxlength= 4;
1642
parfmt.scale= CS_SRC_VALUE;
1643
parfmt.precision= CS_SRC_VALUE;
1645
parfmt.locale= NULL;
1646
if(ct_bind(cmd, 1, &parfmt, &cit_id, NULL, NULL) != CS_SUCCEED) break;
1648
parfmt.datatype= CS_CHAR_TYPE;
1649
parfmt.format= CS_FMT_NULLTERM;
1650
parfmt.maxlength= 128;
1651
if(ct_bind(cmd, 2, &parfmt, cit_key, NULL, NULL) != CS_SUCCEED) break;
1654
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
1657
refer= malloc(sizeof(TXC_CitList));
1660
else if(n >= alloc_room) {
1663
tmp= realloc(refer, alloc_room*sizeof(TXC_CitList));
1670
refer[n].cit_id= cit_id;
1671
refer[n].cit_key= StringSave(cit_key);
1683
/* this is an error */
1685
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1686
ct_close(te_link, CS_FORCE_CLOSE);
1704
CharPtr txc_citGetKey(Int4 cit_id)
1708
CS_INT res_type, rows_read;
1710
Boolean more_results= TRUE;
1714
if(cit_id <= 0) return NULL;
1716
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
1719
/* build command: tax_citGet4Node @tax_id */
1721
if(ct_command(cmd, CS_RPC_CMD, "tax_getCitKey", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1726
memset(&parfmt, 0, sizeof(CS_DATAFMT));
1727
strcpy(parfmt.name, "@cit_id");
1728
parfmt.namelen= CS_NULLTERM;
1729
parfmt.datatype= CS_INT_TYPE;
1730
parfmt.maxlength= sizeof(Int4);
1731
parfmt.status= CS_INPUTVALUE;
1732
parfmt.locale= NULL;
1733
if(ct_param(cmd, &parfmt, &cit_id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
1738
/* send this command to server */
1739
if(ct_send(cmd) != CS_SUCCEED) {
1744
while(more_results && (--nnn > 0)) {
1745
switch(ct_results(cmd, &res_type)) {
1747
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1748
ct_close(te_link, CS_FORCE_CLOSE);
1754
case CS_END_RESULTS :
1755
more_results= FALSE;
1759
if(res_type == CS_ROW_RESULT) {
1760
/* bind and fetch these data */
1763
parfmt.datatype= CS_CHAR_TYPE;
1764
parfmt.format= CS_FMT_NULLTERM;
1765
parfmt.maxlength= 128;
1766
parfmt.scale= CS_SRC_VALUE;
1767
parfmt.precision= CS_SRC_VALUE;
1769
parfmt.locale= NULL;
1770
if(ct_bind(cmd, 1, &parfmt, cit_key, NULL, NULL) != CS_SUCCEED) break;
1773
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
1786
/* this is an error */
1788
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1789
ct_close(te_link, CS_FORCE_CLOSE);
1792
return StringSave(cit_key);
1803
return StringSave(cit_key);
1806
TXC_CitListPtr txc_citFind(CharPtr key_str, Int4Ptr nof_cit)
1810
CS_INT res_type, rows_read;
1812
Boolean more_results= TRUE;
1816
Int4 n= 0, alloc_room= 0;
1817
TXC_CitListPtr refer= NULL, tmp;
1819
if((key_str == NULL) || (*key_str == '\0')) return NULL;
1821
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
1824
/* build command: tax_citGet4Node @tax_id */
1826
if(ct_command(cmd, CS_RPC_CMD, "tax_findCit", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1831
memset(&parfmt, 0, sizeof(CS_DATAFMT));
1832
strcpy(parfmt.name, "@cit_key");
1833
parfmt.namelen= CS_NULLTERM;
1834
parfmt.datatype= CS_CHAR_TYPE;
1835
parfmt.maxlength= strlen(key_str);
1836
parfmt.status= CS_INPUTVALUE;
1837
parfmt.locale= NULL;
1838
if(ct_param(cmd, &parfmt, key_str, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
1843
/* send this command to the server */
1844
if(ct_send(cmd) != CS_SUCCEED) {
1849
while(more_results && (--nnn > 0)) {
1850
switch(ct_results(cmd, &res_type)) {
1852
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1853
ct_close(te_link, CS_FORCE_CLOSE);
1859
case CS_END_RESULTS :
1860
more_results= FALSE;
1864
if(res_type == CS_ROW_RESULT) {
1865
/* bind and fetch these data */
1867
parfmt.datatype= CS_INT_TYPE;
1868
parfmt.format= CS_FMT_UNUSED;
1869
parfmt.maxlength= 4;
1870
parfmt.scale= CS_SRC_VALUE;
1871
parfmt.precision= CS_SRC_VALUE;
1873
parfmt.locale= NULL;
1874
if(ct_bind(cmd, 1, &parfmt, &cit_id, NULL, NULL) != CS_SUCCEED) break;
1876
parfmt.datatype= CS_CHAR_TYPE;
1877
parfmt.format= CS_FMT_NULLTERM;
1878
parfmt.maxlength= 128;
1879
if(ct_bind(cmd, 2, &parfmt, cit_key, NULL, NULL) != CS_SUCCEED) break;
1882
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
1885
refer= malloc(sizeof(TXC_CitList));
1888
else if(n >= alloc_room) {
1891
tmp= realloc(refer, alloc_room*sizeof(TXC_CitList));
1898
refer[n].cit_id= cit_id;
1899
refer[n].cit_key= StringSave(cit_key);
1911
/* this is an error */
1913
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1914
ct_close(te_link, CS_FORCE_CLOSE);
1932
_citation* txc_citGetByKey(CharPtr key_str)
1936
CS_INT res_type, rows_read;
1938
Boolean more_results= TRUE;
1940
char cit_key[132], url[132], txt[6*256];
1941
CS_INT cit_key_ln, url_ln, txt_ln[6];
1942
CS_SMALLINT url_ind, txt_ind[6];
1943
CS_INT cit_id, flags, medline_id, pubmed_id;
1945
_citation* cit= NULL;
1947
if((key_str == NULL) || (*key_str == '\0')) return NULL;
1949
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
1952
/* build command: tax_citGet4Node @tax_id */
1954
if(ct_command(cmd, CS_RPC_CMD, "tax_citGetByKey", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
1959
memset(&parfmt, 0, sizeof(CS_DATAFMT));
1960
strcpy(parfmt.name, "@cit_key");
1961
parfmt.namelen= CS_NULLTERM;
1962
parfmt.datatype= CS_CHAR_TYPE;
1963
parfmt.maxlength= strlen(key_str);
1964
parfmt.status= CS_INPUTVALUE;
1965
parfmt.locale= NULL;
1966
if(ct_param(cmd, &parfmt, key_str, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
1971
/* send this command to the server */
1972
if(ct_send(cmd) != CS_SUCCEED) {
1977
while(more_results && (--nnn > 0)) {
1978
switch(ct_results(cmd, &res_type)) {
1980
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
1981
ct_close(te_link, CS_FORCE_CLOSE);
1987
case CS_END_RESULTS :
1988
more_results= FALSE;
1992
if(res_type == CS_ROW_RESULT) {
1993
/* bind and fetch these data */
1995
parfmt.datatype= CS_INT_TYPE;
1996
parfmt.format= CS_FMT_UNUSED;
1997
parfmt.maxlength= 4;
1998
parfmt.scale= CS_SRC_VALUE;
1999
parfmt.precision= CS_SRC_VALUE;
2001
parfmt.locale= NULL;
2002
if((ct_bind(cmd, 1, &parfmt, &cit_id, NULL, NULL) != CS_SUCCEED) ||
2003
(ct_bind(cmd, 3, &parfmt, &flags, NULL, NULL) != CS_SUCCEED) ||
2004
(ct_bind(cmd, 4, &parfmt, &medline_id, NULL, NULL) != CS_SUCCEED) ||
2005
(ct_bind(cmd, 5, &parfmt, &pubmed_id, NULL, NULL) != CS_SUCCEED)) break;
2007
parfmt.datatype= CS_CHAR_TYPE;
2008
parfmt.format= CS_FMT_NULLTERM;
2009
parfmt.maxlength= 128;
2010
if((ct_bind(cmd, 2, &parfmt, cit_key, &cit_key_ln, NULL) != CS_SUCCEED) ||
2011
(ct_bind(cmd, 6, &parfmt, url, &url_ln, &url_ind) != CS_SUCCEED)) break;
2013
parfmt.maxlength= 256;
2014
for(n= 0; n < 6; n++) {
2015
if(ct_bind(cmd, 7+n, &parfmt, txt + 256*n, &txt_ln[n], &txt_ind[n]) != CS_SUCCEED)
2020
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
2023
cit= malloc(sizeof(_citation));
2026
cit->key= StringSave(cit_key);
2028
cit->mu_id= medline_id;
2029
cit->pm_id= pubmed_id;
2030
cit->url= ((url_ind == -1) || (url_ln < 1) || (url[0] == '\0'))? NULL :
2033
for(i= n= 0; i < 6; i++) {
2034
n+= ((txt_ind[i] == -1) || (txt_ln[i] < 1) || (txt[256*i] == '\0'))? 0 :
2041
cit->txt= MemNew(n);
2043
for(i= 0; i < 6; i++) {
2044
if((txt_ind[i] != -1) && (txt_ln[i] > 0) && (txt[256*i] != '\0')) {
2045
strcat(cit->txt, &txt[256*i]);
2059
/* this is an error */
2061
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2062
ct_close(te_link, CS_FORCE_CLOSE);
2084
while((rc= ct_close(te_link, CS_UNUSED)) == CS_FAIL) {
2086
if(ct_cancel(te_link, NULL, CS_CANCEL_ALL) != CS_SUCCEED) break;
2089
if(rc == CS_FAIL) ct_close(te_link, CS_FORCE_CLOSE);
2091
if(ct_exit(te_context, CS_UNUSED) != CS_FAIL) {
2092
ct_exit(te_context, CS_FORCE_EXIT);
2097
/********************************/
2098
/* retrive subspecies functions */
2099
/********************************/
2101
/* tax_SSget(@tax_id int, @subtype tinyint, @subname varchar(120)) proc */
2103
_subspecPtr tax_SSget(Int4 tax_id, _subspecPtr ssrec)
2108
CS_INT res_type, rows_read;
2111
Boolean more_results= TRUE;
2114
if(tax_id < 2) return NULL;
2116
if((ssrec == NULL) || (ssrec->sname == NULL)) return NULL;
2118
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
2120
/* build command: tax_checkUnique @name_txt, @tax_id */
2122
if(ct_command(cmd, CS_RPC_CMD, "tax_SSget", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
2127
memset(&parfmt, 0, sizeof(CS_DATAFMT));
2128
strcpy(parfmt.name, "@tax_id");
2129
parfmt.namelen= CS_NULLTERM;
2130
parfmt.status= CS_INPUTVALUE;
2131
parfmt.locale= NULL;
2132
parfmt.datatype= CS_INT_TYPE;
2133
parfmt.maxlength= sizeof(CS_INT);
2134
if(ct_param(cmd, &parfmt, &tax_id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2139
strcpy(parfmt.name, "@subtype");
2140
parfmt.datatype= CS_TINYINT_TYPE;
2141
parfmt.maxlength= 1;
2142
if(ct_param(cmd, &parfmt, &ssrec->stype, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2147
strcpy(parfmt.name, "@subname");
2148
strncpy(rname, ssrec->sname, 116);
2150
parfmt.datatype= CS_CHAR_TYPE;
2151
parfmt.maxlength= strlen(rname);
2152
if(ct_param(cmd, &parfmt, rname, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2157
/* send this command to server */
2158
if(ct_send(cmd) != CS_SUCCEED) {
2163
if(ssrec->rname != NULL) ssrec->rname= MemFree(ssrec->rname);
2165
while(more_results && (--nnn > 0)) {
2166
switch(ct_results(cmd, &res_type)) {
2168
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2169
ct_close(te_link, CS_FORCE_CLOSE);
2175
case CS_END_RESULTS :
2176
more_results= FALSE;
2180
if(res_type == CS_ROW_RESULT) {
2181
/* bind and fetch these data */
2183
parfmt.datatype= CS_INT_TYPE;
2184
parfmt.format= CS_FMT_UNUSED;
2185
parfmt.maxlength= 4;
2186
parfmt.scale= CS_SRC_VALUE;
2187
parfmt.precision= CS_SRC_VALUE;
2189
parfmt.locale= NULL;
2190
if(ct_bind(cmd, 1, &parfmt, &ssrec->r_id, NULL, NULL) != CS_SUCCEED) break;
2192
parfmt.datatype= CS_TINYINT_TYPE;
2193
parfmt.maxlength= 1;
2194
if(ct_bind(cmd, 2, &parfmt, &ssrec->rtype, NULL, NULL) != CS_SUCCEED) break;
2197
parfmt.datatype= CS_CHAR_TYPE;
2198
parfmt.format= CS_FMT_NULLTERM;
2199
parfmt.maxlength= 132;
2200
if(ct_bind(cmd, 3, &parfmt, rname, &rname_ln, NULL) != CS_SUCCEED) break;
2203
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
2206
rname[rname_ln]= '\0';
2207
if(ssrec->rname != NULL) MemFree(ssrec->rname);
2208
ssrec->rname= StringSave(rname);
2220
/* this is an error */
2222
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2223
ct_close(te_link, CS_FORCE_CLOSE);
2237
return (ssrec->rname == NULL)? NULL : ssrec;
2240
tax_OrgModPtr tax_SSgetLegal(Int4 tax_id)
2244
CS_INT res_type, rows_read;
2247
Boolean more_results= TRUE;
2251
tax_OrgModPtr first= NULL;
2252
tax_OrgModPtr last, tmp;
2254
if(tax_id < 2) return NULL;
2256
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return NULL;
2259
/* call tax_SSgetLegal (@tax_id int) proc */
2261
if(ct_command(cmd, CS_RPC_CMD, "tax_SSgetLegal", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
2266
memset(&parfmt, 0, sizeof(CS_DATAFMT));
2267
strcpy(parfmt.name, "@tax_id");
2268
parfmt.namelen= CS_NULLTERM;
2269
parfmt.datatype= CS_INT_TYPE;
2270
parfmt.maxlength= sizeof(Int4);
2271
parfmt.status= CS_INPUTVALUE;
2272
parfmt.locale= NULL;
2273
if(ct_param(cmd, &parfmt, &tax_id, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2278
/* send this command to the server */
2279
if(ct_send(cmd) != CS_SUCCEED) {
2284
while(more_results && (--nnn > 0)) {
2285
switch(ct_results(cmd, &res_type)) {
2287
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2288
ct_close(te_link, CS_FORCE_CLOSE);
2294
case CS_END_RESULTS :
2295
more_results= FALSE;
2299
if(res_type == CS_ROW_RESULT) {
2300
/* bind and fetch these data */
2302
parfmt.datatype= CS_TINYINT_TYPE;
2303
parfmt.format= CS_FMT_UNUSED;
2304
parfmt.maxlength= 1;
2305
parfmt.scale= CS_SRC_VALUE;
2306
parfmt.precision= CS_SRC_VALUE;
2308
parfmt.locale= NULL;
2309
if(ct_bind(cmd, 1, &parfmt, &subtype, NULL, NULL) != CS_SUCCEED) break;
2312
parfmt.datatype= CS_CHAR_TYPE;
2313
parfmt.format= CS_FMT_NULLTERM;
2314
parfmt.maxlength= 240;
2315
if(ct_bind(cmd, 2, &parfmt, subname, &subname_ln, NULL) != CS_SUCCEED) break;
2318
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
2320
if(subname_ln >= 0) subname[subname_ln]= '\0';
2321
tmp= MemNew(sizeof(tax_OrgMod));
2322
if(tmp == NULL) continue;
2324
tmp->subname= StringSave(subname);
2325
tmp->subtype= subtype;
2344
/* this is an error */
2346
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2347
ct_close(te_link, CS_FORCE_CLOSE);
2364
/* tax_SSgetNodes(@tax_id int, @subtype tinyint, @subname varchar(120)) proc */
2366
Int4 tax_SSgetNodes(Uint1 stype, CharPtr sname, Uint1 mode, Int4Ptr* ids)
2370
CS_INT res_type, rows_read;
2372
Boolean more_results= TRUE;
2375
Int4 nof_nodes= 0, nof_rooms;
2379
if((sname == NULL) || (*sname == '\0')) return 0;
2381
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
2383
/* build command: tax_SSgetNodes @subtype, @subname, @mode */
2385
if(ct_command(cmd, CS_RPC_CMD, "tax_SSgetNodes", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
2390
memset(&parfmt, 0, sizeof(CS_DATAFMT));
2391
strcpy(parfmt.name, "@subtype");
2392
parfmt.namelen= CS_NULLTERM;
2393
parfmt.status= CS_INPUTVALUE;
2394
parfmt.locale= NULL;
2395
parfmt.datatype= CS_TINYINT_TYPE;
2396
parfmt.maxlength= sizeof(CS_TINYINT);
2397
if(ct_param(cmd, &parfmt, &stype, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2402
strcpy(parfmt.name, "@subname");
2403
parfmt.datatype= CS_CHAR_TYPE;
2404
strncpy(tname, sname, 116);
2406
parfmt.maxlength= strlen(tname);
2407
if(ct_param(cmd, &parfmt, tname, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2412
strcpy(parfmt.name, "@mode");
2413
parfmt.datatype= CS_TINYINT_TYPE;
2414
parfmt.maxlength= 1;
2415
if(ct_param(cmd, &parfmt, &mode, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2420
/* send this command to server */
2421
if(ct_send(cmd) != CS_SUCCEED) {
2426
while(more_results && (--nnn > 0)) {
2427
switch(ct_results(cmd, &res_type)) {
2429
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2430
ct_close(te_link, CS_FORCE_CLOSE);
2436
case CS_END_RESULTS :
2437
more_results= FALSE;
2441
if(res_type == CS_ROW_RESULT) {
2442
/* bind and fetch these data */
2444
parfmt.datatype= CS_INT_TYPE;
2445
parfmt.format= CS_FMT_UNUSED;
2446
parfmt.maxlength= 4;
2447
parfmt.scale= CS_SRC_VALUE;
2448
parfmt.precision= CS_SRC_VALUE;
2450
parfmt.locale= NULL;
2451
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
2452
p_id= MemNew(4 * sizeof(Int4));
2459
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
2461
if(nof_nodes >= nof_rooms) {
2464
p_id= MemMore(p_id, nof_rooms*(sizeof(Int4)));
2472
p_id[nof_nodes++]= tax_id;
2483
/* this is an error */
2485
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2486
ct_close(te_link, CS_FORCE_CLOSE);
2504
Int4 tax_getTaxId4GI(Int4 gi)
2508
CS_INT res_type, rows_read, tax_id= 0;
2509
Boolean more_results= TRUE;
2513
if(ct_cmd_alloc(te_link, &cmd) != CS_SUCCEED) return 0;
2515
/* build command: tax_getTaxId4GI @gi */
2517
if(ct_command(cmd, CS_RPC_CMD, "tax_getTaxId4GI", CS_NULLTERM, CS_UNUSED) != CS_SUCCEED) {
2522
memset(&parfmt, 0, sizeof(CS_DATAFMT));
2523
strcpy(parfmt.name, "@gi");
2524
parfmt.namelen= CS_NULLTERM;
2525
parfmt.datatype= CS_INT_TYPE;
2526
parfmt.maxlength= sizeof(Int4);
2527
parfmt.status= CS_INPUTVALUE;
2528
parfmt.locale= NULL;
2529
if(ct_param(cmd, &parfmt, &gi, parfmt.maxlength, CS_UNUSED) != CS_SUCCEED) {
2534
/* send this command to server */
2535
if(ct_send(cmd) != CS_SUCCEED) {
2540
while(more_results && (--nnn > 0)) {
2541
switch(ct_results(cmd, &res_type)) {
2543
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2544
ct_close(te_link, CS_FORCE_CLOSE);
2550
case CS_END_RESULTS :
2551
more_results= FALSE;
2555
if(res_type == CS_STATUS_RESULT) {
2557
parfmt.datatype= CS_INT_TYPE;
2558
parfmt.format= CS_FMT_UNUSED;
2559
parfmt.maxlength= 4;
2560
parfmt.scale= CS_SRC_VALUE;
2561
parfmt.precision= CS_SRC_VALUE;
2563
if(ct_bind(cmd, 1, &parfmt, &tax_id, NULL, NULL) != CS_SUCCEED) break;
2565
switch(ct_fetch(cmd,CS_UNUSED,CS_UNUSED,CS_UNUSED,&rows_read)) {
2577
/* this is a error */
2579
if(ct_cancel(NULL, cmd, CS_CANCEL_ALL) != CS_SUCCEED) {
2580
ct_close(te_link, CS_FORCE_CLOSE);