/////////////////////////////////////////////////////////////////////////// // Name: AddData // // Description: // Add a multiple data record to the database (this can be either writing a new one // or rewriting an existing one) // // Declaration: // int CGrandData::AddData(CString &pstrErrorMsg) // // Input: // mbFillingExitingRec true(rewriting an existing record)/false(creating a new record) // mpdbFloatDataRec record that is to be written // // Output: pstrErrorMsg error msg from problem, if any // // mbFillingExistingRec set to false if wrote an existing record // // Return: true (data successfully written) / false (some kind of error, see miErrorNum and pstrErroMsg) // // date / author revision // ----------------- -------- // 17-Dec-2001 SFK Created from part of ImportData in DbImport.cpp ////////////////////////////////////////////////////////////////// bool CGrandData::AddData(CString *pstrErrorMsg) { bool bSuccess = true; int dbvstat = S_OKAY; if (!mbFillingExistingRec) { if ((dbvstat = d_fillnew(DB_FLOAT_DATA_REC,(char *)&mdbFloatDataRec, CURR_DB)) != S_OKAY) bSuccess = false; if (bSuccess) { if ((dbvstat = d_connect(DAY_TO_FLOAT_DATA_SET, CURR_DB)) != S_OKAY) bSuccess = false; } } else { // special case if adding to an existing record in the dat if ((dbvstat = d_recwrite((char *)&mdbFloatDataRec, CURR_DB)) !=S_OKAY) bSuccess = false; mbFillingExistingRec = false; } if (!bSuccess) { miErrorNum = iDB_BAD; NewDbVistaError(pstrErrorMsg, false, dbvstat); return(false); } return(true); }
/////////////////////////////////////////////////////////////////////////// // Name: CreateDayRecInMainDb // // Description: // Create a new day record for the given station and insert in the Rad dbVista main db. // If the day already exists in the db, do nothing. // Uses unadjusted times. // // Declaration: // int CreateDayRecInMainDb(short sSta, DATE dDay) // // Input: sSta number of station want to find day for // dDay day (DATE format) searching for // // Output: none // // Return: TRUE - day exists // uiDAY_NOT_IN_DB - day does not exist // STA_NOT_IN_DB - sSta does not exist // DB_BAD - unexpected db error // // date / author revision // ----------------- -------- // 23-May-1995 SFK Created // 02-Aug-2002 SFK Changed to use DATE timebase (doubles in event rec) ////////////////////////////////////////////////////////////////// int CDbDay::CreateDayRecInMainDb(short sSta, DATE dDay) { struct db_day_rec dbDay; int status, db_stat; /* ------------------------------------------------------------------ * If the day is already in the db do nothing. * ----------------------------------------------------------------*/ status = FindDayRecInMainDb(sSta, dDay); if (status != uiDAY_NOT_IN_DB_STATUS) return(status); /* ------------------------------------------------------------------ * Find the sSta that will own this day and make it the owner of * the set. * ----------------------------------------------------------------*/ db_stat = d_keyfind(S_STA_NUM_KEY, (char *)&sSta, CURR_DB); if (db_stat != S_OKAY) goto db_exit; db_stat = d_setor(STATION_TO_DAY_SET, CURR_DB); if (db_stat != S_OKAY) goto db_exit; /* ------------------------------------------------------------------ * Fill the new record you want to write and connect into the database * ----------------------------------------------------------------*/ dbDay.d_day_beg_time_key = dDay; dbDay.d_day_beg_time = dDay; dbDay.d_day_end_time = 0.0; dbDay.ul_day_total_pts = 0; db_stat = d_fillnew(DB_DAY_REC,(char *)&dbDay, CURR_DB); if (db_stat != S_OKAY) goto db_exit; db_stat = d_connect(STATION_TO_DAY_SET, CURR_DB); if (db_stat != S_OKAY) goto db_exit; return(TRUE); db_exit: RadReviewMsg(uiDB_BAD_ERR, "CreateDayRecInMainDb", db_stat); // had unexpected db error if get here return(uiDB_BAD_ERR); }
/* 1. CREATE or find database dictionary (.dbd file). * 2. CREATE empty 'dtsearch' database files. * 3. OPEN 'dtsearch' database. * 4. INITIALIZE the database. * 5. WRITE dbrec after initializing it. * 6. RENAME each database file. * 7. UNLINK (delete) d9x files. */ int main (int argc, char *argv[]) { int i; char *ptr; FILE *f; struct or_miscrec miscrec; struct or_swordrec swordrec; struct or_lwordrec lwordrec; setlocale (LC_ALL, ""); dtsearch_catd = catopen (FNAME_DTSRCAT, 0); aa_argv0 = argv[0]; max_ormisc_size = sizeof (miscrec.or_misc); maxwidth_sword = sizeof (swordrec.or_swordkey) - 1; maxwidth_lword = sizeof (lwordrec.or_lwordkey) - 1; printf (catgets (dtsearch_catd, MS_misc, 4, "%s Version %s.\n"), aa_argv0, DtSrVERSION ); /* Handle cmd line args. Init global variables. */ user_args_processor (argc, argv); /* ------- copy model .dbd to new .dbd ------- */ /* CASE 1: If user specified -d special alternative * directory for model .dbd, it should be there. */ if (modelpath[0] != 0) { if (debug_mode) printf (PROGNAME"628 Try opening '%s' (-d dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"638 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"302", modelpath, strerror(errno)); DtSearchExit (4); } } /* end CASE 1 */ /* CASE 2: If model .dbd is in current directory, use it. * If error is anything other than 'cant find file', quit now. */ if (debug_mode) printf (PROGNAME"649 Try opening '%s' (curr dir).\n", FNAME_MODEL); if ((f = fopen (FNAME_MODEL, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"660 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } else if (errno != ENOENT) { print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"655", FNAME_MODEL, strerror(errno)); DtSearchExit (4); } /* end else CASE 2 */ /* CASE 3: Last chance. Look for model .dbd in target directory. * At this point have to quit on any error. */ strcpy (modelpath, newpath); strcpy (modelpath + path_offset, FNAME_MODEL); if (debug_mode) printf (PROGNAME"672 Try opening '%s' (new dir).\n", modelpath); if ((f = fopen (modelpath, "rb")) != NULL) { if (debug_mode) puts (PROGNAME"675 Found it!"); create_new_dbd (f); fclose (f); goto DBD_OKAY; } if (debug_mode) puts (PROGNAME"682 Never found it!"); print_usage(); printf (catgets (dtsearch_catd, MS_initausd, 213, default_unable_to_open_msg), "\n"PROGNAME"686", FNAME_MODEL, "Not found in either current or target directories. Use -d option\a"); DtSearchExit (4); DBD_OKAY: /* Open a new database */ *newextp = 0; /* use no extension when opening database */ if (debug_mode) printf ("040*** d_open newpath = '%s'.\n", newpath); d_open (newpath, "o"); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 230, PROGNAME "230 Could not open database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "231")); DtSearchExit (3); } austext_exit_dbms = (void (*) (int)) d_close; /* emerg exit func */ /* initialize the 'dtsearch' database */ if (debug_mode) printf ("042*** d_initialize.\n"); d_initialize (0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 239, PROGNAME "239 Could not initialize database '%s'.\n"), newpath); puts (vista_msg (PROGNAME "240")); DtSearchExit (3); } /* Create and initialize dbrec database header record in first slot. * First fill entire record with binary zeros. * Then set specific values as specified by flavor on command line. * For now most values are hard-coded. */ if (debug_mode) printf ("050*** create dbrec.\n"); memset (&dbrec, 0, sizeof (dbrec)); /* Init fields that are completely independent */ dbrec.or_language = (DtSrINT16) language; dbrec.or_maxwordsz = (DtSrINT16) maxwordsz; dbrec.or_minwordsz = (DtSrINT16) minwordsz; dbrec.or_fzkeysz = (DtSrINT16) fzkeysz; dbrec.or_abstrsz = (DtSrINT16) abstrsz; dbrec.or_dbflags = ORD_NONOTES | ORD_NOMARKDEL | ORD_XWORDS; strncpy (dbrec.or_version, SCHEMA_VERSION, sizeof(dbrec.or_version)); dbrec.or_version [sizeof(dbrec.or_version) - 1] = 0; /* Load dbrec's recslots fields based on correct number * of misc recs required to hold user's abstract. * Round abstrsz upward if there is any space left on last misc rec. */ dbrec.or_recslots = 1; /* start with obj rec itself */ for (i = dbrec.or_fzkeysz + dbrec.or_abstrsz; i > 0; i -= max_ormisc_size) dbrec.or_recslots++; if (i < 0) { /* Add in difference to INCREASE abstrsz */ dbrec.or_abstrsz -= i; printf (catgets (dtsearch_catd, MS_misc, 433, "%1$sAdjusted maximum abstract size upward to %2$hd.\n"), PROGNAME "433 ", dbrec.or_abstrsz); } /* Init fields that are dependent on language */ switch (language) { case DtSrLaENG: case DtSrLaENG2: dbrec.or_dbflags |= ORD_XSTEMS; break; default: break; } /* Init fields that are dependent on flavor */ if (flavor == AUSTEXT_FLAVOR) { dbrec.or_dbaccess = ORA_BLOB; dbrec.or_compflags = ORC_COMPBLOB; dbrec.or_hufid = -1L; /* -1 = use huffman compression, but * hufid not yet known. */ dbrec.or_dbotype = DtSrObjTEXT; } else { /* default flavor == DTSEARCH_FLAVOR */ dbrec.or_dbaccess = ORA_NOTAVAIL; } if (!quiet_mode) { /******putchar ('\n');******/ print_dbrec (newpath, &dbrec); fflush (stdout); } swab_dbrec (&dbrec, HTON); if (debug_mode) printf ("060*** fillnew dbrec.\n"); d_fillnew (OR_DBREC, &dbrec, 0); if (db_status != S_OKAY) { printf (catgets (dtsearch_catd, MS_initausd, 509, PROGNAME "509 Could not initialize database header record.\n")); puts (vista_msg (PROGNAME "510")); DtSearchExit (3); } /* Close the database */ d_close (); austext_exit_dbms = NULL; /* emerg exit no longer required */ /* Delete all nonvista (inverted index) database files (.d9x) */ remove_d9x_file (".d97"); remove_d9x_file (".d98"); remove_d9x_file (".d99"); *newextp = 0; /* no extension suffixes for next msgs */ printf (catgets (dtsearch_catd, MS_initausd, 24, PROGNAME " Successfully initialized database '%s'.\n"), newpath); return 0; } /* main() */