📄 mysql_lib.c
字号:
else { fprintf(stderr," cannot find getdesc field:\n%s\n",tmp_str); goto error_r; } if ((bp=strchr(bps,';'))!=NULL) { *bp='\0';} if ((m_fptr->sql_getseq=calloc(strlen(bps)+1,sizeof(char)))==NULL) { fprintf(stderr, " cannot allocate space for database name [%d], %s\n", strlen(bps),bps); goto error_r; } if (strlen(bps) > 0) { strcpy(m_fptr->sql_getseq,bps); } else { fprintf(stderr," cannot find getseq field:\n%s\n",tmp_str); return 0; } if (bp!=NULL) *bp=';'; /* now do the query */ if (mysql_query(m_fptr->mysql_conn,m_fptr->sql_query)) { fprintf(stderr,"*** Error %u - query failed:\n%s\n%s\n", mysql_errno(m_fptr->mysql_conn), m_fptr->sql_query, mysql_error(m_fptr->mysql_conn)); goto error_r; } if ((m_fptr->mysql_res = mysql_use_result(m_fptr->mysql_conn)) == NULL) { fprintf(stderr,"*** Error = use result failed\n%s\n", mysql_error(m_fptr->mysql_conn)); goto error_r; } return m_fptr; error_r: free(m_fptr->sql_getseq); free(m_fptr->sql_getdesc); free(m_fptr->sql_query); free(m_fptr); free(sql_db); return NULL;}struct lmf_str *mysql_reopen(struct lmf_str *m_fptr) { m_fptr->sql_reopen = 1; return m_fptr;}voidmysql_closelib(struct lmf_str *m_fptr) { if (m_fptr == NULL) return; if (m_fptr->mysql_res != NULL) mysql_free_result(m_fptr->mysql_res); mysql_close(m_fptr->mysql_conn); m_fptr->sql_reopen=0;}/*static char *sql_seq = NULL, *sql_seqp;static int sql_seq_len;static MYSQL_ROW sql_row;*/intmysql_getlib( unsigned char *seq, int maxs, char *libstr, int n_libstr, fseek_t *libpos, int *lcont, struct lmf_str *lm_fd, long *l_off){ register unsigned char *cp, *seqp; register int *ap; unsigned char *seqm, *seqm1; char *bp; /* int l_start, l_stop, len; */ seqp = seq; seqm = &seq[maxs-9]; seqm1 = seqm-1; ap = lm_fd->sascii;#ifdef SUPERFAMNUM sfnum[0]=nsfnum = 0;#endif if (*lcont==0) { /* get a row, with UID, sequence */ *l_off = 1; if ((lm_fd->mysql_row =mysql_fetch_row(lm_fd->mysql_res))!=NULL) { *libpos=(fseek_t)atol(lm_fd->mysql_row[0]); /* for @P:1-n removed */ /* if ((bp=strchr(lm_fd->mysql_row[2],'@'))!=NULL && !strncmp(bp+1,"P:",2)) { sscanf(bp+3,"%d-%d",&l_start,&l_stop) l_start--; if (l_start < 0) l_start=0; if (l_stop > (len=strlen(lm_fd->mysql_row[1]))) l_stop= len-1; lm_fd->sql_seqp = lm_fd->mysql_row[1]; lm_fd->sql_seqp[l_stop]='\0'; lm_fd->sql_seqp += l_start; */ if (lm_fd->mysql_row[2] == NULL) { fprintf(stderr," NULL comment at: [%s] %ld\n", lm_fd->mysql_row[0],*libpos); } else if ((bp=strchr(lm_fd->mysql_row[2],'@'))!=NULL && !strncmp(bp+1,"C:",2)) sscanf(bp+3,"%ld",l_off); else *l_off = 1; lm_fd->sql_seqp = lm_fd->mysql_row[1]; /* because of changes in mysql_ranlib(), it is essential that libstr return the unique identifier; thus we must use sql_row[0], not sql_row[2]. Using libstr as the UID allows one to use any UID, not just numeric ones. *libpos is not used for mysql libraries. */ if (n_libstr <= MAX_UID) { /* the normal case returns only GID/sequence */ strncpy(libstr,lm_fd->mysql_row[0],MAX_UID-1); libstr[MAX_UID-1]='\0'; } else { /* here we do not use the UID in libstr, because we are not going back into the db */ /* the PVM case also returns a long description */ if (lm_fd->mysql_row[2]!=NULL) { strncpy(libstr,lm_fd->mysql_row[2],n_libstr-1); } else { strncpy(libstr,lm_fd->mysql_row[0],n_libstr-1); } libstr[n_libstr-1]='\0'; } } else { mysql_free_result(lm_fd->mysql_res); lm_fd->mysql_res=NULL; *lcont = 0; *seqp = EOSEQ; return -1; } } for (cp=(unsigned char *)lm_fd->sql_seqp; seqp<seqm1 && *cp; ) { if ((*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA && (*seqp++=ap[*cp++])<NA) continue; --seqp; if (*(cp-1)==0) break; } lm_fd->sql_seqp = (char *)cp; if (seqp>=seqm1) (*lcont)++; else { *lcont=0; if (lm_fd->sql_reopen) { mysql_free_result(lm_fd->mysql_res); lm_fd->mysql_res = NULL; } } *seqp = EOSEQ; /* if ((int)(seqp-seq)==0) return 1; */ return (int)(seqp-seq);}voidmysql_ranlib(char *str, int cnt, fseek_t libpos, char *libstr, struct lmf_str *lm_fd ){ char tmp_query[1024], tmp_val[20]; char *bp; str[0]='\0'; /* put the UID into the query string - cannot use sprintf because of "%' etc */ /* sprintf(tmp_query,lm_fd->sql_getdesc,libpos); */ if ((bp=strchr(lm_fd->sql_getdesc,'#'))==NULL) { fprintf(stderr, "no GID position in %s\n",lm_fd->sql_getdesc); goto next1; } else { *bp = '\0'; strncpy(tmp_query,lm_fd->sql_getdesc,sizeof(tmp_query)); tmp_query[sizeof(tmp_query)-1]='\0'; /* sprintf(tmp_val,"%ld",(long)libpos); */ strncat(tmp_query,libstr,sizeof(tmp_query)-1); strncat(tmp_query,bp+1,sizeof(tmp_query)-1); *bp='#'; lm_fd->lpos = libpos; } /* fprintf(stderr," requesting: %s\n",tmp_query); */ if (lm_fd->mysql_res !=NULL) { mysql_free_result(lm_fd->mysql_res); lm_fd->mysql_res = NULL; } if (mysql_query(lm_fd->mysql_conn,tmp_query)) { fprintf(stderr,"*** Error - query failed:\n%s\n%s\n",tmp_query, mysql_error(lm_fd->mysql_conn)); sprintf(str,"gi|%ld ***Error - query failed***",(long)libpos); goto next1; } if ((lm_fd->mysql_res = mysql_use_result(lm_fd->mysql_conn)) == NULL) {/* fprintf(stderr,"*** Error = use result failed\n%s\n", mysql_error(lm_fd->mysql_conn)); */ sprintf(str,"gi|%ld ***use result failed***",(long)libpos); goto next0; } /* have the description */ if ((lm_fd->mysql_row = mysql_fetch_row(lm_fd->mysql_res))==NULL) { /* fprintf(stderr," cannot fetch description: %s\n",tmp_query); */ sprintf(str,"gi|%ld ***cannot fetch description***",(long)libpos); goto next0; } if (lm_fd->mysql_row[1] != NULL) strncpy(str,lm_fd->mysql_row[1],cnt-1); else strncpy(str,lm_fd->mysql_row[0],cnt-1); str[cnt-1]='\0'; while (strlen(str) < cnt-1 && (lm_fd->mysql_row = mysql_fetch_row(lm_fd->mysql_res))!=NULL) { strncat(str," ",cnt-2-strlen(str)); if (lm_fd->mysql_row[1]!=NULL) strncat(str,lm_fd->mysql_row[1],cnt-2-strlen(str)); else break; } str[cnt-1]='\0'; if ((bp = strchr(str,'\r'))!=NULL) *bp='\0'; if ((bp = strchr(str,'\n'))!=NULL) *bp='\0'; next0: mysql_free_result(lm_fd->mysql_res); next1: lm_fd->mysql_res = NULL; /* get the sequence, set up for mysql_getseq() */ /* put the UID into the query string */ if ((bp=strchr(lm_fd->sql_getseq,'#'))==NULL) { fprintf(stderr, "no GID position in %s\n",lm_fd->sql_getseq); return; } else { *bp = '\0'; strncpy(tmp_query,lm_fd->sql_getseq,sizeof(tmp_query)); tmp_query[sizeof(tmp_query)-1]='\0'; /* sprintf(tmp_val,"%ld",(long)libpos); */ strncat(tmp_query,libstr,sizeof(tmp_query)); strncat(tmp_query,bp+1,sizeof(tmp_query)); *bp='#'; } if (mysql_query(lm_fd->mysql_conn,tmp_query)) { fprintf(stderr,"*** Error - query failed:\n%s\n%s\n",tmp_query, mysql_error(lm_fd->mysql_conn)); } if ((lm_fd->mysql_res = mysql_use_result(lm_fd->mysql_conn)) == NULL) { fprintf(stderr,"*** Error = use result failed\n%s\n", mysql_error(lm_fd->mysql_conn)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -