/******************************************************************************/ /* File : SVops.cc */ /* Schema : bdeschema.sch */ /* GENCPP Version : Chgen V 12 - Sathya */ /******************************************************************************/ #include #include #include #include "bdeschema.h" #include "SVschema.h" #include "TTschema.h" #include "TAschema.h" #include "VVschema.h" #include "TSschema.h" #include "FOschema.h" #include "GDschema.h" #include "HGschema.h" #include "HNschema.h" #include "HAschema.h" #include "HLschema.h" #include "HPschema.h" #include "HIschema.h" #include "CGschema.h" #include "GXschema.h" #ifdef USE_STL /******************************************************************************/ /* This routine returns table abbreviation. */ /******************************************************************************/ char *SVtable::getAbbrev() { return abbrev; } /******************************************************************************/ /* This routine returns table name. */ /******************************************************************************/ char *SVtable::getName() { return name; } /******************************************************************************/ /* This routine returns number of rows in the table. */ /******************************************************************************/ unsigned int SVtable::getRowCount() { return row.size(); } /******************************************************************************/ /* This routine returns an iterator to the first row in the table. */ /******************************************************************************/ list::iterator SVtable::getFirstRow() { return row.begin(); } /******************************************************************************/ /* This routine returns the last row in the table. */ /******************************************************************************/ SV *SVtable::getLastRow() { SV *retval; list::iterator iter; if (row.empty()) { retval = NULL; } else { iter = row.end(); iter--; retval = *iter; } return retval; } /******************************************************************************/ /* This routine returns the terminator after last row in the table. */ /******************************************************************************/ list::iterator SVtable::Terminator() { return row.end(); } bool SVtable::isFirstRow(SV* curr) { return(curr != NULL && curr != (*getFirstRow())); } bool SVtable::isLastRow(SV* curr) { return(curr != NULL && curr != getLastRow()); } #endif /* ifdef USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine inserts a row into the table. */ /******************************************************************************/ void SVtable::insertRow(SV *newRow) { list::iterator iter; iter = row.begin(); while (iter != row.end() && (*iter)->get_pkid() < newRow->get_pkid()) iter++; row.insert(iter, newRow); } #endif /* USE_STL */ #ifdef USE_STL /******************************************************************************/ /* This routine returns removes the specified row from the table. */ /******************************************************************************/ list::iterator SVtable::removeRow(list::iterator i) { SV *tmpRow = (*i); return row.erase(i); } #endif #ifdef USE_STL /******************************************************************************/ /* Constructor for table class. */ /******************************************************************************/ SVtable::SVtable(char *newAbbrev, char *newName) { strcpy(abbrev, newAbbrev); name = new char[sizeof( newName )]; strcpy(name, newName); } #endif #ifdef USE_STL /******************************************************************************/ /* Table destructor. */ /******************************************************************************/ SVtable::~SVtable() { SV *currRow; list::iterator iterator; iterator = row.begin(); while (iterator != row.end()) { currRow = *iterator; iterator = currRow->delete_row(iterator); } delete [] name; } #endif /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_PVid (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if ( strlen(value) >= sizeof(PVid) ) fprintf(stderr, "Warning: field PVid in class SV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"PVid", (value) ); } strncpy(PVid, value, sizeof(PVid)) ; SVid = RC::get_pkid(); decode(temp_key, &SVid); sprintf(log_text,"PR_SET_STR %s PVid %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_svname (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if ( strlen(value) >= sizeof(svname) ) fprintf(stderr, "Warning: field svname in class SV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"svname", (value) ); } strncpy(svname, value, sizeof(svname)) ; SVid = RC::get_pkid(); decode(temp_key, &SVid); sprintf(log_text,"PR_SET_STR %s svname %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_sformat (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if ( strlen(value) >= sizeof(sformat) ) fprintf(stderr, "Warning: field sformat in class SV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"sformat", (value) ); } strncpy(sformat, value, sizeof(sformat)) ; SVid = RC::get_pkid(); decode(temp_key, &SVid); sprintf(log_text,"PR_SET_STR %s sformat %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_sversion (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if ( strlen(value) >= sizeof(sversion) ) fprintf(stderr, "Warning: field sversion in class SV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"sversion", (value) ); } strncpy(sversion, value, sizeof(sversion)) ; SVid = RC::get_pkid(); decode(temp_key, &SVid); sprintf(log_text,"PR_SET_STR %s sversion %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_lastMod (int value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_INT %s %s %d\n", decode_retstr( (hcg_key*)(get_pkid()) ),"lastMod", (value) ); } lastMod = value ; #ifdef USE_STL SVid = get_pkid(); #else SVid = RC::get_pkid(); #endif decode(temp_key, &SVid); sprintf(log_text,"PR_SET_INT %s lastMod %d\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_svpath (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if ( strlen(value) >= sizeof(svpath) ) fprintf(stderr, "Warning: field svpath in class SV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"svpath", (value) ); } strncpy(svpath, value, sizeof(svpath)) ; SVid = RC::get_pkid(); decode(temp_key, &SVid); sprintf(log_text,"PR_SET_STR %s svpath %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to set value to a data member. */ /******************************************************************************/ void SV::set_descr (char *value) { char log_text[BUFSIZE]; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; logwait(); if ( strlen(value) >= sizeof(descr) ) fprintf(stderr, "Warning: field descr in class SV is too long- truncated\n"); if (get_RFLAG()==1 && hcg_log ==1 ) { fprintf( hcg_logfileptr, "SET_STR %s %s %s\n", decode_retstr( (hcg_key*)(get_pkid()) ),"descr", (value) ); } strncpy(descr, value, sizeof(descr)) ; SVid = RC::get_pkid(); decode(temp_key, &SVid); sprintf(log_text,"PR_SET_STR %s descr %s\n",temp_key, value); logstr(log_text); } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* SV::get_PVid () { return PVid; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* SV::get_svname () { return svname; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* SV::get_sformat () { return sformat; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* SV::get_sversion () { return sversion; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ int SV::get_lastMod () { return lastMod; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* SV::get_svpath () { return svpath; } /******************************************************************************/ /* This routine is used to get value from a data member. */ /******************************************************************************/ char* SV::get_descr () { return descr; } #ifndef USE_STL SV* SV::create_row() { SV *SVtmp; SVtmp = new SV; SVtmp->set_pkid(0); SVtmp->set_PVid("\0"); SVtmp->set_svname("\0"); SVtmp->set_sformat("\0"); SVtmp->set_sversion("\0"); SVtmp->set_lastMod(0); SVtmp->set_svpath("\0"); SVtmp->set_descr("\0"); SVtmp->next_ptr = NULL; SVtmp->prev_ptr = NULL; SVtmp->VVid_fcp = NULL; SVtmp->VVid_bcp = NULL; SVtmp->TTid_fcp = NULL; SVtmp->TTid_bcp = NULL; return SVtmp; } #endif /******************************************************************************/ /* This routine is used to add a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void SV::add_row (char *viewname) { char error_table[HCG_ABBR_SIZE+1]; char tempkey[HCG_KEY_SIZE+1]; hcg_key SVid; char VNstring[NAMELENGTH] = "VN "; if (hcg_log == 1) { logwait(); if (strcmp(viewname, hcg_viewname)) { logstr(strcat (strcat (VNstring, viewname), "\n")); strcpy (hcg_viewname, viewname); } } if (!hcg_initialized) { printf("Error: pr_add() called when database is not yet initialized.\n"); add_row_log (viewname); return; } if (!find_view_idx(viewname)) { printf("Error: view %s passed to pr_load is not defined.\n",viewname); add_row_log (viewname); return; } if (!find_tbl_idx("SV")) { strncpy_null(error_table, "SV", HCG_ABBR_SIZE); printf("Warning: unknown table (%s) passed to pr_add, ignored.\n",error_table); add_row_log (viewname); return; } hcg_version = hcg_view_list.view_list[hcg_view_idx].version_list[hcg_tbl_idx]; hcg_table_seq_list[hcg_tbl_idx].rcount++; hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].rcount++; #ifndef USE_STL SVelt = this; #endif pr_gen_pkey(viewname,SV,SVid); #ifdef USE_STL set_pkid(SVid); #else RC::set_pkid(SVid); #endif pr_check_str (SV,SVelt,PVid,8); pr_check_str (SV,SVelt,svname,30); pr_check_str (SV,SVelt,sformat,6); pr_check_str (SV,SVelt,sversion,12); pr_check_str (SV,SVelt,svpath,80); pr_check_str (SV,SVelt,descr,80); add_row_log (viewname); link_row(); hcg_ts_list[hcg_tbl_idx].ts_list[hcg_version].maxrow++; } /******************************************************************************/ /* This routine is used to link a single row to a virtual database table. */ /******************************************************************************/ void SV::link_row() { hcg_key SVid; #ifndef USE_STL insert_element(SV); #else SVtab->insertRow(this); #endif /* USE_STL */ link_child_bp_m(VV,SV,SVid,SVid,SVid,VVid); link_child_bp_m(TT,SV,SVid,SVid,SVid,TTid); } /******************************************************************************/ /* This routine is used to parse a single row to a virtual database table. */ /* Validations for valid table-id, table is within view, and the version */ /* number is the right one for this table in this view. if all this passes, */ /* the row is added to the database, and linked in to its parents, etc... */ /******************************************************************************/ void SV::parse_row (char *buffer, int idx, hcg_key hcg_k) { #ifdef USE_STL set_pkid(hcg_k); #else RC::set_pkid(hcg_k); #endif hcg_parse(buffer,hcg_t,&idx); mystrcpy(PVid,hcg_t,8,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(svname,hcg_t,30,1); hcg_parse(buffer,hcg_t,&idx); mystrcpy(sformat,hcg_t,6,0); hcg_parse(buffer,hcg_t,&idx); mystrcpy(sversion,hcg_t,12,1); hcg_parse(buffer,hcg_t,&idx); set_lastMod(atoi(hcg_t)); hcg_parse(buffer,hcg_t,&idx); mystrcpy(svpath,hcg_t,80,1); mystrcpy(descr,buffer+idx,80,1); } /******************************************************************************/ /* This routine will delete a single row from the database. The row is the */ /* one pointed to by the XXcurr variable. */ /******************************************************************************/ #ifdef USE_STL list::iterator SV::delete_row (list::iterator rowIter) #else void SV::delete_row () #endif { static char rcsid[] = "$Id"; char temp_key[HCG_KEY_SIZE+1]; hcg_key SVid; char log_text[BUFSIZE]; logwait(); unlink_child_bp_m(VV,SV,SVid,VVid); unlink_child_bp_m(TT,SV,SVid,TTid); #ifdef DEBUG #ifdef USE_STL SVid = get_pkid(); #else SVid = RC::get_pkid(); #endif decode(temp_key, &SVid); printf("The primary key deleted is %s\n",temp_key); #endif #ifdef USE_STL rowIter = SVtab->removeRow(rowIter); delete this; #else del_row(SV); #endif /* The following is to support logging */ #ifdef USE_STL SVid = get_pkid(); #else SVid = RC::get_pkid(); #endif decode(temp_key, &SVid); sprintf(log_text,"DL %s\n",temp_key); logstr(log_text); #ifdef USE_STL return rowIter; #endif } /******************************************************************************/ /* This routine will write-out (dump) all rows that meet the specified */ /* view to the specified file_name. The tbl indicates which table's row */ /* will be dumped. The open_file flag of 1 indicates open a file for dumping */ /* a single row. Otherwise doesn't open file because pr_dump had opened a */ /* file. If the mode of the view is write, the caller is allowed to specify a */ /* new_version flag of 1, which will cause a version number update. Finally, */ /* the modestr parameter indicates if a new file should be generated ('w'), */ /* or append to an existing file ('a'). */ /******************************************************************************/ #ifdef USE_STL void SVtable::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #else void SV::dump_table ( char *viewname, char *file_name, int new_version, char *modestr ) #endif { table_loop(viewname,SV) { #ifndef USE_STL SVcurr->dump_row(viewname,file_name,new_version,modestr); #else (*SVcurr)->dump_row(viewname,file_name,new_version,modestr); #endif /* USE_STL */ } } /******************************************************************************/ /* This routine will write-out (dump) a single row that meet the specified */ /* view to the specified file_name. The tbl indicates which table's row */ /* will be dumped. The open_file flag of 1 indicates open a file for dumping */ /* a single row. Otherwise doesn't open file because pr_dump had opened a */ /* file. If the mode of the view is write, the caller is allowed to specify a */ /* new_version flag of 1, which will cause a version number update. Finally, */ /* the modestr parameter indicates if a new file should be generated ('w'), */ /* or append to an existing file ('a'). */ /******************************************************************************/ void SV::dump_row (char *viewname, char *file_name, int new_version, char *modestr ) { char outkey[3][HCG_KEY_SIZE+1]; hcg_key SVid; if (open_file==1) { if ((hcg_dump_fp=fopen(file_name,modestr)) == NULL) { printf("Error: dump_row() cannot open %s using file mode %s\n", file_name,modestr); exit(1); } } #ifdef USE_STL SVid = get_pkid(); #else SVid = RC::get_pkid(); #endif hcg_update_version(&SVid,SV_idx,new_version); decode(outkey[0], &SVid); PrintCheck(fprintf(hcg_dump_fp, " %-8s %-8s %-30s %-6s %-12s %8d %-80s %-80s\n" , outkey[0], PVid, svname, sformat, sversion, lastMod, svpath, descr)); if (open_file==1) fclose(hcg_dump_fp); } #ifdef USE_STL void SV::insertChild_VVid(VV *childRow) { VVid_children.push_back(childRow); } void SV::removeChild_VVid(list::iterator rowIter) { VVid_children.remove((*rowIter)); } list::iterator SV::getFirstChild_VVid() { return VVid_children.begin(); } list::iterator SV::getLastChild_VVid() { list::iterator iter; iter = VVid_children.end(); if (!VVid_children.empty()) iter--; return iter; } list::iterator SV::VVid_Terminator() { return VVid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL void SV::insertChild_TTid(TT *childRow) { TTid_children.push_back(childRow); } void SV::removeChild_TTid(list::iterator rowIter) { TTid_children.remove((*rowIter)); } list::iterator SV::getFirstChild_TTid() { return TTid_children.begin(); } list::iterator SV::getLastChild_TTid() { list::iterator iter; iter = TTid_children.end(); if (!TTid_children.empty()) iter--; return iter; } list::iterator SV::TTid_Terminator() { return TTid_children.end(); } #endif /* USE_STL */ #ifdef USE_STL /********************************************************************************/ /* Default constructor for SV. */ /********************************************************************************/ SV::SV () { set_pkid(0); /* initialize */ set_PVid("\0"); set_svname("\0"); set_sformat("\0"); set_sversion("\0"); set_lastMod(0); set_svpath("\0"); set_descr("\0"); } #endif #ifdef USE_STL /********************************************************************************/ /* Destructor for SV. */ /********************************************************************************/ SV::~SV () { /* Empty */ } #endif /********************************************************************************/ /* This routine is used to log a call to pr_add to hcg_logfile */ /* The tbl indicates which table is having a row added. */ /* tbl_ptr points to the record to be added. */ /********************************************************************************/ void SV::add_row_log (char *viewname) { char outkey[3][HCG_KEY_SIZE+1]; int idx; hcg_key SVid; /* Return if logging not on */ if (hcg_log != 1) return; find_tbl_idx("SV"); idx=hcg_tbl_idx; /* Write to hcg_logfile based on idx */ #ifdef USE_STL SVid = get_pkid(); #else SVid = RC::get_pkid(); #endif hcg_update_version(&SVid,SV_idx,0); decode(outkey[0], &SVid); PrintCheck(fprintf(hcg_logfileptr, " %-8s %-8s %-30s %-6s %-12s %8d %-80s %-80s\n" , outkey[0], PVid, svname, sformat, sversion, lastMod , svpath, descr)); } /********************************************************************************/ /* This routine is used to to do the add given the viewname, the tablename */ /* and a string of the additional information */ /********************************************************************************/ void SV::log_do_add_row (char *view, char *theRest, int idx) { hcg_parse(theRest, hcg_t, &idx); mystrcpy(PVid, hcg_t, 8, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(svname, hcg_t, 30, 1); hcg_parse(theRest, hcg_t, &idx); mystrcpy(sformat, hcg_t, 6, 0); hcg_parse(theRest, hcg_t, &idx); mystrcpy(sversion, hcg_t, 12, 1); hcg_parse(theRest, hcg_t, &idx); lastMod = (atoi(hcg_t)); hcg_parse(theRest, hcg_t, &idx); mystrcpy(svpath, hcg_t, 80, 1); mystrcpy(descr, theRest+idx, 80, 1); add_row(view); } /********************************************************************************/ /* This routine is used to set the value of an int field. */ /********************************************************************************/ void SV::log_do_set_int_row (const char fieldname[NAMELENGTH+1], const int newval) { if(strcmp(fieldname,"lastMod")==0) lastMod = newval; } /********************************************************************************/ /* This routine is used to set the value of an float field. */ /********************************************************************************/ void SV::log_do_set_flt_row (const char fieldname[NAMELENGTH+1], const int newval) { } /********************************************************************************/ /* This routine is used to set the value of an key field. */ /********************************************************************************/ void SV::log_do_set_key_row (const char fieldname[NAMELENGTH+1], hcg_key new_key) { if (strcmp(fieldname,"SVid")==0) #ifdef USE_STL set_pkid (new_key); #else RC::set_pkid (new_key); #endif } /********************************************************************************/ /* This routine is used to set the value of an string field. */ /********************************************************************************/ void SV::log_do_set_str_row (const char fieldname[NAMELENGTH+1], const char newval[BUFSIZE+1]) { if (strcmp(fieldname,"PVid")==0) strcpy(PVid,newval); else if (strcmp(fieldname,"sformat")==0) strcpy(sformat,newval); }