[Refdb-cvs] CVS: refdb/src refdbdbib.c,1.36.2.3,1.36.2.4
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2004-08-21 15:45:26
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6297 Modified Files: Tag: Release_0_9_5_stable refdbdbib.c Log Message: new function check_is_subseq(); various fixes for sorting order and related stuff Index: refdbdbib.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/refdbdbib.c,v retrieving revision 1.36.2.3 retrieving revision 1.36.2.4 diff -u -U2 -r1.36.2.3 -r1.36.2.4 --- refdbdbib.c 26 Jul 2004 20:36:55 -0000 1.36.2.3 +++ refdbdbib.c 21 Aug 2004 15:45:12 -0000 1.36.2.4 @@ -115,15 +115,8 @@ int ndb_error; int nread_done = 0; - size_t inbuffer_len; - size_t sql_command_len; - size_t outbuffer_len; - size_t authorlist_buffer_len = 0; - size_t curr_multi_id_len; int token_size; int numbyte; int i; int n_writeresult; - unsigned int n_pubyear; - unsigned long long nref_counter; int citation_count; /* counter for citations in id handler */ int xref_count; /* counter for xrefs in id handler */ @@ -131,8 +124,17 @@ int nis_numeric = 0; /* 1 for numeric in-text citation, 0 for author/year */ int n_mydistinct; - unsigned long long n_id; - unsigned long long ndb_notfound = 0; /* number of refs not found */ + int n_currpos; + int n_is_subseq = 0; + size_t inbuffer_len; + size_t sql_command_len; + size_t outbuffer_len; + size_t authorlist_buffer_len = 0; + size_t curr_multi_id_len; size_t msg_len = 0; size_t result_len; + short int n_pubyear; + unsigned long long nref_counter; + unsigned long long n_id; + unsigned long long ndb_notfound = 0; /* number of refs not found */ char table_buffer[256]; char entry_id[128]; @@ -158,4 +160,5 @@ char *prev_authorconcat = NULL; const char *bibsequence; + const char *intextsequence; const char* item; const char* item1; @@ -369,4 +372,27 @@ /* both MySQL and PostgreSQL use separate namespaces per connection so it is safe to reuse the same table name */ + + /* the columns mean : */ + /* + dbname the name of the database the ref is taken from + orig_id the numeric ID of the entry in the reference database + entry_id the ID string as taken from the foo.id.xml file + article_title the title of the work + author_concat the concatenated author string + periodical the journal name + volume + issue + startpage + pubyear + citation_pos position of the citation in the document, 0-based, identical for all references of a multiple citation + xref_pos position of the reference within a citation, 0-based and thus 0 for all references which are not part of a multiple citation + multi_id ID string of the multiple citation a ref is part of, if any + sorted_pos position of the ref in the bibliography after sorting + author_abbrevlist the proper et al.-like string + year_uni_suffix the unique suffix for the pubyear, if any + + */ + + if (!strcmp(ptr_clrequest->dbserver, "mysql")) { sprintf(sql_command, "CREATE TEMPORARY TABLE %s (id INT NOT NULL AUTO_INCREMENT, \ @@ -384,5 +410,5 @@ xref_pos INT, \ multi_id BLOB, \ - sorted_pos INT, \ + sorted_pos INT DEFAULT 1, \ author_abbrevlist BLOB, \ year_uni_suffix VARCHAR(16), \ @@ -404,5 +430,5 @@ xref_pos INTEGER, \ multi_id TEXT, \ - sorted_pos INTEGER, \ + sorted_pos INTEGER DEFAULT 1, \ author_abbrevlist TEXT, \ year_uni_suffix VARCHAR(16), \ @@ -424,5 +450,5 @@ xref_pos INTEGER, \ multi_id TEXT, \ - sorted_pos INTEGER, \ + sorted_pos INTEGER DEFAULT 1, \ author_abbrevlist TEXT, \ year_uni_suffix TEXT)", table_name); @@ -570,8 +596,8 @@ /* see how the references should be sorted */ if (!strcmp(my_dbi_conn_get_cap(bibconns.conn_refdb, "multiple_db"), "t")) { - sprintf(sql_command, "SELECT BIBLIOSEQUENCE from %s.CITSTYLE where JOURNAL=%s", MAIN_DB, myjournal); + sprintf(sql_command, "SELECT BIBLIOSEQUENCE,INTEXTSEQUENCE from %s.CITSTYLE where JOURNAL=%s", MAIN_DB, myjournal); } else { - sprintf(sql_command, "SELECT BIBLIOSEQUENCE from CITSTYLE where JOURNAL=%s", myjournal); + sprintf(sql_command, "SELECT BIBLIOSEQUENCE,INTEXTSEQUENCE from CITSTYLE where JOURNAL=%s", myjournal); } @@ -602,4 +628,5 @@ prepare_render_dbib(outbuffer, ptr_biblio_info, bibconns.conn_refdb, n_ref_format); + /* this is the sequence of the entries in the bibliography */ bibsequence = dbi_result_get_string(dbires, "BIBLIOSEQUENCE"); @@ -614,4 +641,17 @@ } + /* this is the sequence of references in a multiple citation */ + intextsequence = dbi_result_get_string(dbires, "INTEXTSEQUENCE"); + + if (!intextsequence || !strcmp(bibsequence, "ERROR")) { + tiwrite(ptr_clrequest->fd, "", TERM_YES); + if (!assemble_return_msg(ptr_addresult, "could not access format information: ", bibconns.conn)) { + LOG_PRINT(LOG_WARNING, ptr_addresult->msg); + } + dbi_result_free(dbires); + close_dbi_connections(&bibconns, drivername); + goto Finish; + } + if (strcmp(bibsequence, "BASIS") == 0) { /* sort the entries according to their appearance in the document */ @@ -622,15 +662,29 @@ goto Finish; } - /* now do the real query */ - sprintf(sql_command, "SELECT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix FROM %s WHERE sorted_pos>0 ORDER BY id", table_name); + + /* now do the real query. We have to take care of the fact that + the sorting order, although "ASIS", may be affected by the + sorting order of multiple in-text citations */ + if (strcmp(intextsequence, "ASIS") == 0) { + sprintf(sql_command, "SELECT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s WHERE sorted_pos>0 ORDER BY id", table_name); + } + else if (strcmp(intextsequence, "AUTHORDATE") == 0) { + sprintf(sql_command, "SELECT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s WHERE sorted_pos>0 ORDER BY citation_pos, author_concat, pubyear, periodical, volume, issue, startpage", table_name); + } + else if (strcmp(intextsequence, "DATEASC") == 0) { + sprintf(sql_command, "SELECT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s WHERE sorted_pos>0 ORDER BY citation_pos, pubyear, author_concat, periodical, volume, issue, startpage", table_name); + } + else if (strcmp(intextsequence, "DATEDESC") == 0) { + sprintf(sql_command, "SELECT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s WHERE sorted_pos>0 ORDER BY citation_pos, pubyear DESC, author_concat, periodical, volume, issue, startpage", table_name); + } } else if (strcmp(bibsequence, "BAUTHORDATE") == 0) { - sprintf(sql_command, "SELECT DISTINCT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix FROM %s ORDER BY author_concat, pubyear, volume, issue, article_title, periodical, startpage", table_name); + sprintf(sql_command, "SELECT DISTINCT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s ORDER BY author_concat, pubyear, volume, issue, article_title, periodical, startpage", table_name); } else if (strcmp(bibsequence, "BDATEASC") == 0) { - sprintf(sql_command, "SELECT DISTINCT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix FROM %s ORDER BY pubyear, author_concat, volume, issue, article_title, periodical, startpage", table_name); + sprintf(sql_command, "SELECT DISTINCT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s ORDER BY pubyear, author_concat, volume, issue, article_title, periodical, startpage", table_name); } else if (strcmp(bibsequence, "BDATEDESC") == 0) { - sprintf(sql_command, "SELECT DISTINCT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix FROM %s ORDER BY pubyear DESC, author_concat, volume, issue, article_title, periodical, startpage", table_name); + sprintf(sql_command, "SELECT DISTINCT dbname, orig_id, author_concat, pubyear, article_title, periodical, volume, issue, startpage, entry_id, year_uni_suffix, sorted_pos FROM %s ORDER BY pubyear DESC, author_concat, volume, issue, article_title, periodical, startpage", table_name); } @@ -862,4 +916,5 @@ ptr_biblio_info->year_unique_suffix = dbi_result_get_string(dbires, "year_uni_suffix"); + /* compare current string with the string of the previous iteration */ /* we have to work around a MySQL peculiarity as it returns NULL if @@ -877,14 +932,45 @@ } + n_currpos = dbi_result_get_long(dbires, "sorted_pos"); + if ((!n_currpos && dbi_conn_error_flag(bibconns.conn))) { + tiwrite(ptr_clrequest->fd, "", TERM_YES); + if (!assemble_return_msg(ptr_addresult, notempselectcolon.text, bibconns.conn)) { + LOG_PRINT(LOG_WARNING, ptr_addresult->msg); + } + dbi_result_free(dbires1); + dbi_result_free(dbires); + close_dbi_connections(&bibconns, drivername); + goto Finish; + } + + n_pubyear = dbi_result_get_short(dbires, "pubyear"); + if ((!n_pubyear && dbi_conn_error_flag(bibconns.conn))) { + tiwrite(ptr_clrequest->fd, "", TERM_YES); + if (!assemble_return_msg(ptr_addresult, notempselectcolon.text, bibconns.conn)) { + LOG_PRINT(LOG_WARNING, ptr_addresult->msg); + } + dbi_result_free(dbires1); + dbi_result_free(dbires); + close_dbi_connections(&bibconns, drivername); + goto Finish; + } + /* empty authorlists are never treated as subseq. Both the current and the previous authorlist may be NULL */ - if (item && *item && prev_authorconcat && *prev_authorconcat - && strcmp(item, prev_authorconcat) == 0) { - ptr_biblio_info->is_subseq = 1; - } - else { - ptr_biblio_info->is_subseq = 0; + n_is_subseq = check_is_subseq(item, table_name, n_currpos, n_pubyear, bibconns.conn); + + if (n_is_subseq == -1) { + tiwrite(ptr_clrequest->fd, "", TERM_YES); + if (!assemble_return_msg(ptr_addresult, noformatupdatecolon.text, bibconns.conn)) { + LOG_PRINT(LOG_WARNING, ptr_addresult->msg); + } + dbi_result_free(dbires1); + dbi_result_free(dbires); + close_dbi_connections(&bibconns, drivername); + goto Finish; } + ptr_biblio_info->is_subseq = n_is_subseq; + /* free memory */ if (prev_authorconcat) { @@ -1005,4 +1091,5 @@ /* printf("n_writeresult=%d<<\n", n_writeresult); */ + /* todo: switch on after debugging */ /* remove the temporary table */ sprintf(sql_command, "DROP TABLE %s", table_name); @@ -2306,4 +2393,69 @@ } + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + check_is_subseq(): checks whether a citation is the first or a subsequent + in the document + + int check_is_subseq returns -1 in case of an error, 0 if first, 1 if subsequent + + const char* author_concat ptr to the author_concat + + const char* table_name name of the table that contains author_concat data + + int n_currpos current position of citation + + int n_pubyear publication year + + dbi_conn conn ptr to an existing connection to the refdb database + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +int check_is_subseq(const char* author_concat, const char* table_name, int n_currpos, short int n_pubyear, dbi_conn conn) { + char* author_concat_q; + char* sql_command; + int n_is_subseq = 0; + dbi_result dbires; + + if (!author_concat || !*author_concat) { + /* nothing to do */ + return 0; + } + + if ((sql_command = (char*)malloc(strlen(author_concat_q)+256)) == NULL) { + return -1; + } + + if ((author_concat_q = strdup(author_concat)) == NULL || dbi_driver_quote_string(dbi_conn_get_driver(conn), &author_concat_q) == -1) { + return -1; + } + + if ((sql_command = (char*)malloc(strlen(author_concat_q)+256)) == NULL) { + free(author_concat_q); + return -1; + } + + sprintf(sql_command, "SELECT id FROM %s WHERE sorted_pos>0 AND sorted_pos < %d AND author_concat=%s AND pubyear=%d", table_name, n_currpos, author_concat_q, n_pubyear); + + free(author_concat_q); + + LOG_PRINT(LOG_DEBUG, sql_command); + dbires = dbi_conn_query(conn, sql_command); + free(sql_command); + + if (!dbires) { + return -1; + } + + if (dbi_result_get_numrows(dbires)) { + n_is_subseq = 1; + } + else { + n_is_subseq = 0; + } + dbi_result_free(dbires); + + return n_is_subseq; +} + /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ send_stylespec(): sends a style specification to the client; the |