void go_load(uint4 begin, uint4 end) { char *ptr; int len, fmt, keylength, keystate; uint4 iter, max_data_len, max_subsc_len, key_count, max_rec_size; mstr src, des; unsigned char *rec_buff, ch; boolean_t utf8_extract, format_error = FALSE, hasht_ignored = FALSE, hasht_gbl = FALSE; char *val_off; int val_len, val_off1, val_len1; boolean_t is_setextract; gvinit(); max_rec_size = DEFAULT_MAX_REC_SIZE; rec_buff = (unsigned char *)malloc(max_rec_size); fmt = MU_FMT_ZWR; /* by default, the extract format is ZWR (not GO) */ len = file_input_get(&ptr); if (mupip_error_occurred) { free(rec_buff); return; } if (len >= 0) { util_out_print("!AD", TRUE, len, ptr); utf8_extract = ((len >= STR_LIT_LEN(UTF8_NAME)) && (0 == MEMCMP_LIT(ptr + len - STR_LIT_LEN("UTF-8"), "UTF-8"))) ? TRUE : FALSE; if ((utf8_extract && !gtm_utf8_mode) || (!utf8_extract && gtm_utf8_mode)) { /* extract CHSET doesn't match $ZCHSET */ if (utf8_extract) gtm_putmsg(VARLSTCNT(4) ERR_LOADINVCHSET, 2, LEN_AND_LIT("UTF-8")); else gtm_putmsg(VARLSTCNT(4) ERR_LOADINVCHSET, 2, LEN_AND_LIT("M")); mupip_error_occurred = TRUE; free(rec_buff); return; } } else mupip_exit(ERR_LOADFILERR); len = file_input_get(&ptr); if (mupip_error_occurred) { free(rec_buff); return; } if (len >= 0) { util_out_print("!AD", TRUE, len, ptr); fmt = (0 == memcmp(ptr + len - STR_LIT_LEN("ZWR"), "ZWR", STR_LIT_LEN("ZWR"))) ? MU_FMT_ZWR : MU_FMT_GO; } else mupip_exit(ERR_LOADFILERR); if (begin < 3) begin = 3; for (iter = 3; iter < begin; iter++) { len = file_input_get(&ptr); if (len < 0) /* The IO device has signalled an end of file */ { gtm_putmsg(VARLSTCNT(3) ERR_LOADEOF, 1, begin); mupip_error_occurred = TRUE; } if (mupip_error_occurred) { util_out_print("Error reading record number: !UL\n", TRUE, iter); free(rec_buff); return; } } assert(iter == begin); util_out_print("Beginning LOAD at record number: !UL\n", TRUE, begin); max_data_len = 0; max_subsc_len = 0; key_count = 0; for (iter = begin - 1; ; ) { if (++iter > end) break; if (mu_ctrly_occurred) break; if (mu_ctrlc_occurred) { util_out_print("!AD:!_ Key cnt: !UL max subsc len: !UL max data len: !UL", TRUE, LEN_AND_LIT(gt_lit), key_count, max_subsc_len, max_data_len); util_out_print("Last LOAD record number: !UL", TRUE, key_count ? iter : 0); mu_gvis(); util_out_print(0, TRUE); mu_ctrlc_occurred = FALSE; } if (0 > (len = file_input_get(&ptr))) break; if (mupip_error_occurred) { mu_gvis(); break; } if ('\n' == *ptr) { if ('\n' == *(ptr+1)) break; ptr++; } if (0 == len) continue; if (MU_FMT_GO != fmt) { /* Determine if the ZWR has $extract format */ if ('$' == *ptr) { keylength = zwrkeyvallen(ptr, len, &val_off, &val_len, &val_off1, &val_len1); ptr = ptr + 4; /* Skip first 4 character '$','z','e','(' */ is_setextract = TRUE; } else { /* Determine the ZWR key length. -1 (SIZEOF(=)) is needed since ZWR allows '^x(1,2)='*/ keylength = zwrkeyvallen(ptr, len, &val_off, &val_len, NULL, NULL); is_setextract = FALSE; } ISSUE_TRIGDATAIGNORE_IF_NEEDED(keylength, ptr, hasht_gbl); if (hasht_gbl) { hasht_gbl = FALSE; continue; } go_call_db(GO_PUT_SUB, ptr, keylength, 0, 0); if (mupip_error_occurred) { mu_gvis(); util_out_print("Error loading record number: !UL\n", TRUE, iter); mupip_error_occurred = FALSE; continue; } assert(keylength < len - 1); if (max_subsc_len < (gv_currkey->end + 1)) max_subsc_len = gv_currkey->end + 1; src.len = val_len; src.addr = val_off; des.len = 0; if (src.len > max_rec_size) { max_rec_size = src.len; free(rec_buff); rec_buff = (unsigned char *)malloc(max_rec_size); } des.addr = (char *)rec_buff; if (FALSE == zwr2format(&src, &des)) { util_out_print("Format error in record number !8UL: !/!AD", TRUE, iter, src.len, src.addr); format_error = TRUE; continue; } if (max_data_len < des.len) max_data_len = des.len; (is_setextract) ? go_call_db(GO_SET_EXTRACT, des.addr, des.len, val_off1, val_len1) : go_call_db(GO_PUT_DATA, (char *)rec_buff, des.len, 0, 0); if (mupip_error_occurred) { mu_gvis(); util_out_print("Error loading record number: !UL\n", TRUE, iter); mupip_error_occurred = FALSE; continue; } key_count++; } else { ISSUE_TRIGDATAIGNORE_IF_NEEDED(len, ptr, hasht_gbl); if (hasht_gbl) { if (0 > (len = file_input_get(&ptr))) break; iter++; hasht_gbl = FALSE; continue; } go_call_db(GO_PUT_SUB, ptr, len, 0, 0); if (mupip_error_occurred) { mu_gvis(); util_out_print("Error loading record number: !UL\n", TRUE, iter); mupip_error_occurred = FALSE; continue; } if (max_subsc_len < (gv_currkey->end + 1)) max_subsc_len = gv_currkey->end + 1; if (++iter > end) { iter--; /* Decrement as didn't load key */ break; } if ((len = file_input_get(&ptr)) < 0) break; if (mupip_error_occurred) { mu_gvis(); util_out_print("Error loading record number: !UL\n", TRUE, iter); break; } stringpool.free = stringpool.base; if (max_data_len < len) max_data_len = len; go_call_db(GO_PUT_DATA, ptr, len, 0, 0); if (mupip_error_occurred) { mu_gvis(); util_out_print("Error loading record number: !UL\n", TRUE, iter); mupip_error_occurred = FALSE; continue; } key_count++; } } free(rec_buff); file_input_close(); if (mu_ctrly_occurred) { gtm_putmsg(VARLSTCNT(1) ERR_LOADCTRLY); mupip_exit(ERR_MUNOFINISH); } util_out_print("LOAD TOTAL!_!_Key Cnt: !UL Max Subsc Len: !UL Max Data Len: !UL",TRUE,key_count,max_subsc_len, max_data_len); util_out_print("Last LOAD record number: !UL\n", TRUE, key_count ? (iter - 1) : 0); if (format_error) mupip_exit(ERR_LOADFILERR); }
static double file_input_get_double (void *vstate) { return file_input_get (vstate) / (double) UINT_MAX; }
STATICFNDEF boolean_t trigger_trgfile_tpwrap_helper(char *trigger_filename, uint4 trigger_filename_len, boolean_t noprompt, boolean_t lcl_implicit_tpwrap) { boolean_t all_triggers_error; uint4 i; io_pair io_save_device; io_pair io_trigfile_device; int len; int4 record_num; boolean_t trigger_status; enum cdb_sc cdb_status; uint4 trig_stats[NUM_STATS]; char *trigger_rec; char *values[NUM_SUBS]; unsigned short value_len[NUM_SUBS]; all_triggers_error = FALSE; if (lcl_implicit_tpwrap) ESTABLISH_RET(trigger_tpwrap_ch, TRIG_FAILURE); /* Return through here is a failure */ io_save_device = io_curr_device; file_input_init(trigger_filename, trigger_filename_len); if (mupip_error_occurred) TRIG_ERROR_RETURN; io_trigfile_device = io_curr_device; record_num = 0; for (i = 0; NUM_STATS > i; i++) trig_stats[i] = 0; while ((0 == io_curr_device.in->dollar.zeof) && (0 <= (len = file_input_get(&trigger_rec)))) { io_curr_device = io_save_device; record_num++; if ((0 != len) && (COMMENT_LITERAL != trigger_rec[0])) util_out_print_gtmio("File !AD, Line !UL: ", NOFLUSH, trigger_filename_len, trigger_filename, record_num); trigger_status = trigger_update_rec(trigger_rec, (uint4)len, noprompt, trig_stats, &io_trigfile_device, &record_num); all_triggers_error |= (TRIG_FAILURE == trigger_status); io_curr_device = io_trigfile_device; } if ((-1 == len) && (!io_curr_device.in->dollar.zeof)) { io_curr_device = io_save_device; util_out_print_gtmio("File !AD, Line !UL: Line too long", FLUSH, trigger_filename_len, trigger_filename, ++record_num); } file_input_close(); io_curr_device = io_save_device; if (all_triggers_error) { util_out_print_gtmio("=========================================", FLUSH); util_out_print_gtmio("!UL trigger file entries matched existing triggers", FLUSH, trig_stats[STATS_UNCHANGED]); util_out_print_gtmio("!UL trigger file entries have errors", FLUSH, trig_stats[STATS_ERROR]); util_out_print_gtmio("!UL trigger file entries have no errors", FLUSH, trig_stats[STATS_ADDED] + trig_stats[STATS_DELETED] + trig_stats[STATS_MODIFIED]); util_out_print_gtmio("=========================================", FLUSH); TRIG_ERROR_RETURN; } if (lcl_implicit_tpwrap) { GVTR_OP_TCOMMIT(cdb_status); if (cdb_sc_normal != cdb_status) t_retry(cdb_status); /* won't return */ REVERT; } if ((0 == trig_stats[STATS_ERROR]) && (0 != (trig_stats[STATS_ADDED] + trig_stats[STATS_DELETED] + trig_stats[STATS_UNCHANGED] + trig_stats[STATS_MODIFIED]))) { util_out_print_gtmio("=========================================", FLUSH); util_out_print_gtmio("!UL triggers added", FLUSH, trig_stats[STATS_ADDED]); util_out_print_gtmio("!UL triggers deleted", FLUSH, trig_stats[STATS_DELETED]); util_out_print_gtmio("!UL trigger file entries not changed", FLUSH, trig_stats[STATS_UNCHANGED]); util_out_print_gtmio("!UL triggers modified", FLUSH, trig_stats[STATS_MODIFIED]); util_out_print_gtmio("=========================================", FLUSH); } else if (0 != trig_stats[STATS_ERROR]) { util_out_print_gtmio("=========================================", FLUSH); util_out_print_gtmio("!UL trigger file entries matched existing triggers", FLUSH, trig_stats[STATS_UNCHANGED]); util_out_print_gtmio("!UL trigger file entries have errors", FLUSH, trig_stats[STATS_ERROR]); util_out_print_gtmio("!UL trigger file entries have no errors", FLUSH, trig_stats[STATS_ADDED] + trig_stats[STATS_DELETED] + trig_stats[STATS_MODIFIED]); util_out_print_gtmio("=========================================", FLUSH); } return TRIG_SUCCESS; }