Thread: [Refdb-cvs] CVS: refdb/src mods_processdata.h,1.1,1.2 mods_processdata.c,1.1,1.2
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2004-06-20 21:52:02
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14750 Modified Files: mods_processdata.h mods_processdata.c Log Message: new function mods_real_process_subject() Index: mods_processdata.h =================================================================== RCS file: /cvsroot/refdb/refdb/src/mods_processdata.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -U2 -r1.1 -r1.2 --- mods_processdata.h 17 May 2004 23:12:51 -0000 1.1 +++ mods_processdata.h 20 Jun 2004 21:51:53 -0000 1.2 @@ -34,4 +34,5 @@ int mods_process_note(struct modsObject* ptr_note, struct addmods_data* ptr_amdata); int mods_process_subject(struct modsObject* ptr_subject, struct addmods_data* ptr_amdata); +int mods_real_process_subject(struct modsObject* ptr_subject, struct addmods_data* ptr_amdata, unsigned long long n_subject_id, char* type_q, char* href_q, char* role_q, char* arcrole_q, char* title_q, char* show_q, char* actuate_q, char* lang_q, char* script_q, char* transliteration_q); int mods_process_classification(struct modsObject* ptr_classification, struct addmods_data* ptr_amdata); int mods_process_relateditem(struct modsObject* ptr_relateditem, struct addmods_data* ptr_amdata); Index: mods_processdata.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/mods_processdata.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -U2 -r1.1 -r1.2 --- mods_processdata.c 17 May 2004 23:12:51 -0000 1.1 +++ mods_processdata.c 20 Jun 2004 21:51:53 -0000 1.2 @@ -40,4 +40,7 @@ #include "mods_handler.h" #include "mods_helper.h" +#include "mods_processdata.h" +#include "mods_checkdup.h" + extern int n_log_level; @@ -199,5 +202,5 @@ int mods_process_object returns 0 if ok, 1 if error - struct modsObject* ptr_titleinfo ptr to titleinfo object + struct modsObject* ptr_object ptr to mods object struct addmods_data* ptr_amdata ptr to addmods_data structure @@ -325,4 +328,13 @@ driver = dbi_conn_get_driver(ptr_amdata->conn); + + /* see whether this is a duplicate */ + n_titleinfo_id = mods_checkdup_titleinfo(ptr_titleinfo, ptr_amdata); + + if (n_titleinfo_id) { + LOG_PRINT(LOG_DEBUG, "found duplicate titleinfo"); + return 0; + } + /* look at the content linked list */ ptr_first_content = &(ptr_titleinfo->content_sentinel); @@ -520,5 +532,5 @@ ptr_curr_content = ptr_first_content; - while ((ptr_curr_content = get_lilinameval(ptr_curr_content, "title", 0)) != NULL) { + while ((ptr_curr_content = get_next_lilinameval(ptr_curr_content)) != NULL) { char *value_q; @@ -532,138 +544,25 @@ } - sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'title\', "ULLSPEC")", value_q, n_titleinfo_id); - - free(value_q); - - LOG_PRINT(LOG_DEBUG, sql_command); - dbires = dbi_conn_query(ptr_amdata->conn, sql_command); - - if (!dbires) { - (ptr_amdata->ndb_error)++; - LOG_PRINT(LOG_WARNING, "insert into t_titleparts failed"); - retval++; - goto finish; - } - - dbi_result_free(dbires); - } /* end if value */ - } /* end while */ - - ptr_curr_content = ptr_first_content; - - while ((ptr_curr_content = get_lilinameval(ptr_curr_content, "subTitle", 0)) != NULL) { - char *value_q; - - if (ptr_curr_content->value) { - result = dbi_driver_quote_string_copy(driver, ptr_curr_content->value, &value_q); - if (result == -1) { - (ptr_amdata->nmem_error)++; - LOG_PRINT(LOG_WARNING, "cannot quote argument"); - retval++; - goto finish; + if (!strcmp(ptr_curr_content->name, "title")) { + sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'title\', "ULLSPEC")", value_q, n_titleinfo_id); } - - sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'subTitle\', "ULLSPEC")", value_q, n_titleinfo_id); - - free(value_q); - LOG_PRINT(LOG_DEBUG, sql_command); - dbires = dbi_conn_query(ptr_amdata->conn, sql_command); - - if (!dbires) { - (ptr_amdata->ndb_error)++; - LOG_PRINT(LOG_WARNING, "insert into t_titleparts failed"); - retval++; - goto finish; + else if (!strcmp(ptr_curr_content->name, "subTitle")) { + sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'subTitle\', "ULLSPEC")", value_q, n_titleinfo_id); } - - dbi_result_free(dbires); - } /* end if value */ - } /* end while */ - - ptr_curr_content = ptr_first_content; - - while ((ptr_curr_content = get_lilinameval(ptr_curr_content, "partNumber", 0)) != NULL) { - char *value_q; - - if (ptr_curr_content->value) { - result = dbi_driver_quote_string_copy(driver, ptr_curr_content->value, &value_q); - if (result == -1) { - (ptr_amdata->nmem_error)++; - LOG_PRINT(LOG_WARNING, "cannot quote argument"); - retval++; - goto finish; + else if (!strcmp(ptr_curr_content->name, "partNumber")) { + sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'partNumber\', "ULLSPEC")", value_q, n_titleinfo_id); } - - sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'partNumber\', "ULLSPEC")", value_q, n_titleinfo_id); - - free(value_q); - - LOG_PRINT(LOG_DEBUG, sql_command); - dbires = dbi_conn_query(ptr_amdata->conn, sql_command); - - if (!dbires) { - (ptr_amdata->ndb_error)++; - LOG_PRINT(LOG_WARNING, "insert into t_titleparts failed"); - retval++; - goto finish; + else if (!strcmp(ptr_curr_content->name, "partName")) { + sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'partName\', "ULLSPEC")", value_q, n_titleinfo_id); } - - dbi_result_free(dbires); - } /* end if value */ - } /* end while */ - - ptr_curr_content = ptr_first_content; - - if ((ptr_curr_content = get_lilinameval(ptr_curr_content, "partName", 0)) != NULL) { - char *value_q; - - if (ptr_curr_content->value) { - result = dbi_driver_quote_string_copy(driver, ptr_curr_content->value, &value_q); - if (result == -1) { - (ptr_amdata->nmem_error)++; - LOG_PRINT(LOG_WARNING, "cannot quote argument"); - retval++; - goto finish; + else if (!strcmp(ptr_curr_content->name, "nonSort")) { + sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'nonSort\', "ULLSPEC")", value_q, n_titleinfo_id); } - sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'partName\', "ULLSPEC")", value_q, n_titleinfo_id); - free(value_q); LOG_PRINT(LOG_DEBUG, sql_command); dbires = dbi_conn_query(ptr_amdata->conn, sql_command); - - if (!dbires) { - (ptr_amdata->ndb_error)++; - LOG_PRINT(LOG_WARNING, "insert into t_titleparts failed"); - retval++; - goto finish; - } - - dbi_result_free(dbires); - } /* end if value */ - } /* end while */ - - ptr_curr_content = ptr_first_content; - - if ((ptr_curr_content = get_lilinameval(ptr_curr_content, "nonSort", 0)) != NULL) { - char *value_q; - - if (ptr_curr_content->value) { - result = dbi_driver_quote_string_copy(driver, ptr_curr_content->value, &value_q); - if (result == -1) { - (ptr_amdata->nmem_error)++; - LOG_PRINT(LOG_WARNING, "cannot quote argument"); - retval++; - goto finish; - } - sprintf(sql_command, "INSERT INTO t_titleparts (titleparts_value, titleparts_type, titleinfo_id) VALUES (%s, \'nonSort\', "ULLSPEC")", value_q, n_titleinfo_id); - - free(value_q); - - LOG_PRINT(LOG_DEBUG, sql_command); - dbires = dbi_conn_query(ptr_amdata->conn, sql_command); - if (!dbires) { (ptr_amdata->ndb_error)++; @@ -735,4 +634,12 @@ driver = dbi_conn_get_driver(ptr_amdata->conn); + /* see whether this is a duplicate */ + n_name_id = mods_checkdup_name(ptr_name, ptr_amdata); + + if (n_name_id) { + LOG_PRINT(LOG_DEBUG, "found duplicate name"); + return 0; + } + ptr_first_content = &(ptr_name->content_sentinel); @@ -2650,5 +2557,4 @@ char* title_q = NULL; char* transliteration_q = NULL; - char *sql_command; char *type_q = NULL; char *role_q = NULL; @@ -2660,7 +2566,5 @@ int retval = 0; int result; - size_t sql_cmd_len; - unsigned long long n_subject_id; - unsigned long long n_geocode_id; + unsigned long long n_subject_id = 0; struct lilimem sentinel; Lilinameval* ptr_curr_content; @@ -2679,4 +2583,12 @@ driver = dbi_conn_get_driver(ptr_amdata->conn); + + /* ToDo: check for duplicates */ + /* must generate sql command dynamically along these lines: + SELECT t_subject.subject_id FROM t_subject, t_geocode, t_xgeocode, t_nameval WHERE t_subject.subject_type='type' AND t_subject.subject_href='href' AND t_subject.subject_role='role' AND t_subject.subject_arcrole='arcrole' AND t_subject.subject_title='title' AND t_subject.subject_show='show' AND t_subject.subject_actuate='actuate' AND t_subject.subject_lang='lang' AND t_subject.subject_script='script' AND t_subject.subject_transliteration='transliteration' AND t_geocode.geocode_value='value' AND t_geocode.geocode_authority='authority' AND t_geocode.geocode_id=t_xgeocode.geocode_id AND t_xgeocode.subject_id=t_subject.subject_id AND t_nameval.nameval_name='elname' AND t_nameval.nameval_value='value' AND t_nameval.nameval_parent='subject' AND t_nameval.parent_id=t_subject.subject_id + +Use same code as below to walk through the bits and pieces */ + + ptr_curr_content = get_lilinameval(&(ptr_subject->content_sentinel), "href", 1); @@ -2786,4 +2698,72 @@ } + n_subject_id = mods_checkdup_subject(ptr_subject, ptr_amdata, type_q, href_q, role_q, arcrole_q, title_q, show_q, actuate_q, lang_q, script_q, transliteration_q); + + result = mods_real_process_subject(ptr_subject, ptr_amdata, n_subject_id, type_q, href_q, role_q, arcrole_q, title_q, show_q, actuate_q, lang_q, script_q, transliteration_q); + + + finish: + delete_all_lilimem(&sentinel); + + return retval; +} + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + mods_real_process_subject(): processes subject data + + int mods_real_process_subject returns 0 if ok, 1 if error + + struct modsObject* ptr_subject ptr to subject object + + struct addmods_data* ptr_amdata ptr to addmods_data structure + + unsigned long long n_subject_id 0 if a new dataset should + be created, > 0 if the entry should be linked to the + existing subject entry with the given ID + + char* type_q ptr to quoted type + + char* href_q ptr to quoted href + + char* role_q ptr to quoted role + + char* arcrole_q ptr to quoted arcrole + + char* title_q ptr to quoted title + + char* show_q ptr to quoted show + + char* actuate_q ptr to quoted actuate + + char* lang_q ptr to quoted lang + + char* script_q ptr to quoted script + + char* transliteration_q ptr to quoted transliteration + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +int mods_real_process_subject(struct modsObject* ptr_subject, struct addmods_data* ptr_amdata, unsigned long long n_subject_id, char* type_q, char* href_q, char* role_q, char* arcrole_q, char* title_q, char* show_q, char* actuate_q, char* lang_q, char* script_q, char* transliteration_q) { + char *sql_command; + int retval = 0; + int result; + int n_create_new = 0; + size_t sql_cmd_len; + unsigned long long n_geocode_id = 0; + struct lilimem sentinel; + Lilinameval* ptr_curr_content; + Lilimodsdate* ptr_curr_lmdate; + Lilimodsobj* ptr_curr_lmobj; + struct modsDate* ptr_curr_date; + struct modsObject* ptr_curr_object; + dbi_result dbires; + dbi_driver driver; + +/* printf("process %s\n", ptr_subject->objectName); */ + + sentinel.ptr_mem = NULL; + sentinel.ptr_next = NULL; + sentinel.varname[0] = '\0'; + driver = dbi_conn_get_driver(ptr_amdata->conn); + sql_cmd_len = 512 /* sql overhead */; sql_cmd_len += (href_q) ? strlen(href_q) : 0; @@ -2797,25 +2777,28 @@ goto finish; } - - sprintf(sql_command, "INSERT INTO t_subject (subject_type, subject_href, subject_role, subject_arcrole, subject_title, subject_show, subject_actuate, subject_lang, subject_script, subject_transliteration) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", type_q, href_q, role_q, arcrole_q, title_q, show_q, actuate_q, lang_q, script_q, transliteration_q); - LOG_PRINT(LOG_DEBUG, sql_command); - dbires = dbi_conn_query(ptr_amdata->conn, sql_command); + if (!n_subject_id) { + n_create_new++; + sprintf(sql_command, "INSERT INTO t_subject (subject_type, subject_href, subject_role, subject_arcrole, subject_title, subject_show, subject_actuate, subject_lang, subject_script, subject_transliteration) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", type_q, href_q, role_q, arcrole_q, title_q, show_q, actuate_q, lang_q, script_q, transliteration_q); + + LOG_PRINT(LOG_DEBUG, sql_command); + dbires = dbi_conn_query(ptr_amdata->conn, sql_command); - if (!dbires) { - (ptr_amdata->ndb_error)++; - LOG_PRINT(LOG_WARNING, "insert into t_subject failed"); - retval++; - goto finish; - } - - dbi_result_free(dbires); + if (!dbires) { + (ptr_amdata->ndb_error)++; + LOG_PRINT(LOG_WARNING, "insert into t_subject failed"); + retval++; + goto finish; + } - /* retrieve subject_id of newly created dataset */ - if (!strcmp(ptr_amdata->drivername, "mysql") || !strcmp(ptr_amdata->drivername, "sqlite")) { - n_subject_id = dbi_conn_sequence_last(ptr_amdata->conn, NULL); - } - else if (!strcmp(ptr_amdata->drivername, "pgsql")) { - n_subject_id = dbi_conn_sequence_last(ptr_amdata->conn, "t_subject_subject_id_seq"); + dbi_result_free(dbires); + + /* retrieve subject_id of newly created dataset */ + if (!strcmp(ptr_amdata->drivername, "mysql") || !strcmp(ptr_amdata->drivername, "sqlite")) { + n_subject_id = dbi_conn_sequence_last(ptr_amdata->conn, NULL); + } + else if (!strcmp(ptr_amdata->drivername, "pgsql")) { + n_subject_id = dbi_conn_sequence_last(ptr_amdata->conn, "t_subject_subject_id_seq"); + } } @@ -2835,4 +2818,8 @@ dbi_result_free(dbires); + if (!n_create_new) { + goto finish; + } + ptr_curr_content = &(ptr_subject->content_sentinel); @@ -2895,4 +2882,5 @@ } else if (strcmp(ptr_curr_content->name, "transliteration")) { + /* topic | temporal | hierarchicalGeographic (subelements) | cartographics | occupation*/ sprintf(sql_command, "INSERT INTO t_nameval (nameval_name, nameval_value, nameval_parent, parent_id) VALUES (\'%s\', %s, \'%s\', "ULLSPEC")", ptr_curr_content->name, value_q, "subject", n_subject_id); } @@ -4022,5 +4010,5 @@ } - if (ptr_recordinfo->lang) { + if (*(ptr_recordinfo->lang)) { result = dbi_driver_quote_string_copy(driver, ptr_recordinfo->lang, &lang_q); if (result == -1 || insert_lilimem(&sentinel, (void**)&lang_q, NULL)) { @@ -4032,5 +4020,5 @@ } - if (ptr_recordinfo->script) { + if (*(ptr_recordinfo->script)) { result = dbi_driver_quote_string_copy(driver, ptr_recordinfo->script, &script_q); if (result == -1 || insert_lilimem(&sentinel, (void**)&script_q, NULL)) { |