[Refdb-cvs] CVS: refdb/src refdbdref.c,1.65.2.2,1.65.2.3
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2004-07-30 21:35:04
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32135 Modified Files: Tag: Release_0_9_5_stable refdbdref.c Log Message: getref():support TA pseudo target Index: refdbdref.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdbdref.c,v retrieving revision 1.65.2.2 retrieving revision 1.65.2.3 diff -u -U2 -r1.65.2.2 -r1.65.2.3 --- refdbdref.c 24 Jun 2004 21:10:07 -0000 1.65.2.2 +++ refdbdref.c 30 Jul 2004 21:34:54 -0000 1.65.2.3 @@ -3044,4 +3044,117 @@ /*----------------------------------------------------------------*/ + /* search in all titles */ + else if (strncmp(token, ":TA:", 4) == 0) { /* all titles query */ + char table[3][27] = {"t_refdb.refdb_title", + "t_refdb.refdb_booktitle", + "t_refdb.refdb_title_series"}; + char the_op[6]; + int i; + int n_isfirst = 1; + + /* todo: fixme */ + strncpy(operator, &token[4], sqltoken.length-4); /* save the comparison operator */ + operator[sqltoken.length-4] = '\0'; /* terminate string */ + + if (*operator == '=') { + strcpy(bitsandpieces, " = "); + strcpy(the_op, " OR "); + } + else if (*operator == '~') { + sprintf(bitsandpieces, " %s ", my_dbi_conn_get_cap(conn, "rlike")); + strcpy(the_op, " OR "); + } + else if (*operator == '!' && *(operator+1) == '=') { + sprintf(bitsandpieces, " != "); + strcpy(the_op, " AND "); + } + else { /* treat all other operators as non-equal */ + sprintf(bitsandpieces, " %s ", my_dbi_conn_get_cap(conn, "not_rlike")); + strcpy(the_op, " AND "); + } + + token = sql_tokenize(newtoken, &sqltoken); + newtoken = sqltoken.next_token; + if (token != NULL) { +/* printf("%s:%d\n", token, error); */ +/* printf("%s\n", newtoken); */ + if ((new_buffer = mstrncpy(buffer, token, sqltoken.length, &buffer_len)) == NULL) { + error = 1; + break; + } + else { + buffer = new_buffer; + } + buffer[sqltoken.length] ='\0'; + quoted_token = mstrdup(buffer); + if (!quoted_token) { + error = 1; + break; + } + if (dbi_driver_quote_string(driver, "ed_token) == -1) { + error = 1; + break; + } + + for (i = 0; i<3; i++) { + if (!n_isfirst) { + if ((new_sql_command1 = mstrcat(sql_command1, the_op, &sql_command1_len, 0)) == NULL) { + error = 1; + break; + } + else { + sql_command1 = new_sql_command1; + } + } + else { + n_isfirst--; + if ((new_sql_command1 = mstrcat(sql_command1, "(", &sql_command1_len, 0)) == NULL) { + error = 1; + break; + } + else { + sql_command1 = new_sql_command1; + } + } + + if ((new_sql_command1 = mstrcat(sql_command1, table[i], &sql_command1_len, 0)) == NULL) { + error = 1; + break; + } + else { + sql_command1 = new_sql_command1; + } + + if ((new_sql_command1 = mstrcat(sql_command1, bitsandpieces, &sql_command1_len, 0)) == NULL) { + error = 1; + break; + } + else { + sql_command1 = new_sql_command1; + } + + if ((new_sql_command1 = mstrcat(sql_command1, quoted_token, &sql_command1_len, 0)) == NULL) { + error = 1; + free(quoted_token); + break; + } + else { + sql_command1 = new_sql_command1; + } + } /* end for */ + + if ((new_sql_command1 = mstrcat(sql_command1, ")", &sql_command1_len, 0)) == NULL) { + error = 1; + break; + } + else { + sql_command1 = new_sql_command1; + } + + free(quoted_token); + } + } + + /*----------------------------------------------------------------*/ /* extended notes - note ID */ else if (strncmp(token, ":NID:", 5) == 0) { /* extended note ID query */ |