int main(int argc, char *argv[]) { #define MAXBUF 4095 char buf[ MAXBUF+1 ]; int iarg, ibuf, ichr; bool debug = FALSE; CL_ERR_DESC err_code; char *p1 = NULL; char pid[MAXBUF]; char *database = ERx(""); char *user = ERx(""); char *xmlfile = ERx(""); char sql_fname[LO_NM_LEN + 1]; char *work_dir = NULL; char directory[MAX_LOC + 1]; char *tmp_dir = NULL; char tmp_buf[MAX_LOC + 1]; char subdir_buf[MAX_LOC + 1]; char sql_loc_buf[MAX_LOC + 1]; char *progname; LOCATION tmp_dir_loc; LOCATION tmp_subdir_loc; LOCATION tmp_buff_loc; LOCATION curr_loc; LOCATION sql_file_loc; char *password = ERx(""); char *groupid = ERx(""); ARGRET rarg; i4 pos; LOCATION xmlfile_loc; FILE *xmlfile_read; STATUS stat = FAIL; char dbuf[256]; char encode[32]; u_i4 tmppid; TM_STAMP tm_stamp; /* Tell EX this is an ingres tool. */ (void) EXsetclient(EX_INGRES_TOOL); /* Call IIUGinit to initialize character set attribute table */ if ( IIUGinit() != OK) PCexit(FAIL); progname = ERget(F_XM0006_IMPXML); FEcopyright(progname, ERx("2001")); /* ** Get arguments from command line */ /* required parameters */ if (FEutaopen(argc, argv, ERx("xmlimport")) != OK) PCexit(FAIL); /* database name is required */ if (FEutaget(ERx("database"), 0, FARG_PROMPT, &rarg, &pos) != OK) PCexit(FAIL); database = rarg.dat.name; if (FEutaget(ERx("xmlfile"), 0, FARG_PROMPT, &rarg, &pos) != OK) PCexit(FAIL); xmlfile = rarg.dat.name; if (FEutaget(ERx("user"), 0, FARG_FAIL, &rarg, &pos) == OK) user = rarg.dat.name; if (FEutaget(ERx("password"), 0, FARG_FAIL, &rarg, &pos) == OK) { char *IIUIpassword(); if ((password = IIUIpassword(ERx("-P"))) == NULL) { FEutaerr(BADARG, 1, ERx("")); PCexit(FAIL); } } if (FEutaget(ERx("groupid"), 0, FARG_FAIL, &rarg, &pos) == OK) groupid = rarg.dat.name; if (FEutaget(ERx("debug"), 0, FARG_FAIL, &rarg, &pos) == OK) debug = TRUE; ibuf = STlength(buf); /* b121678: pid is no longer based on process id, but it's ** a random number instead. */ PCpid(&tmppid); TMget_stamp(&tm_stamp); MHsrand2(tmppid * tm_stamp.tms_usec); STprintf(pid, "%x", MHrand2()); #ifdef xDEBUG SIprintf(" the pid is: %s \n", pid); #endif /* create the sql file */ /* Avoid a name like "foo.xml.sql" on VMS, use pid.sql instead */ STcopy(pid, sql_fname); STcat(sql_fname, ".sql"); /* ** create in the temp location a directory ** with the name pid. set this directory ** as the working directory for impxml */ NMloc (TEMP, PATH, NULL, &tmp_dir_loc); /* make a location for TMP loc */ /* print location name */ LOcopy (&tmp_dir_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &tmp_dir); #ifdef xDEBUG SIprintf ("temploc: %s \n", tmp_dir); #endif /* make a subdir location with filename, pid */ STcopy (pid, subdir_buf); /* Initialize result loc so that everyone is happy */ LOcopy (&tmp_dir_loc, sql_loc_buf, &sql_file_loc); /* Generate location for temp subdirectory */ if (LOfaddpath (&tmp_dir_loc, subdir_buf, &sql_file_loc) != OK) { IIUGerr(E_XM0007_Locname_Failed, UG_ERR_FATAL, 2, tmp_dir, subdir_buf); /* NOTREACHED */ } /* print the location name */ LOcopy (&sql_file_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &work_dir); #ifdef xDEBUG SIprintf ("work dir loc: %s \n", work_dir); #endif /* create the subdir */ if (LOcreate (&sql_file_loc) != OK) { IIUGerr(E_XM0008_Create_Temp_Dir, UG_ERR_ERROR, 1, work_dir); PCexit(FAIL); } STcopy(work_dir, directory); #ifdef xDEBUG SIprintf ("sql file name: %s \n", sql_fname); SIprintf ("xml file name: %s \n", xmlfile); #endif /* Execute the command impxml */ STprintf (buf, ERx( "impxml -d=\"%s\" -o=\"%s\" " ), directory, sql_fname); /* encoding? */ if ( (LOfroms(PATH & FILENAME, xmlfile, &xmlfile_loc) != OK) || (SIopen(&xmlfile_loc, "r", &xmlfile_read) != OK) || (xmlfile_read == NULL) ) { IIUGerr(E_XM0009_Cannot_Open_File, UG_ERR_ERROR, 1, xmlfile); PCexit(FAIL); } /* scan XML declaration for encoding, if any */ if (stat = SIgetrec(dbuf, sizeof(dbuf) - 1, xmlfile_read) == OK) { char *d = dbuf; i4 i = 0; for (d = dbuf; d != (dbuf + sizeof(dbuf)); d++) { if (MEcmp(d, ERx("encoding="), sizeof(ERx("encoding=")) - 1) == 0) { d += sizeof(ERx("encoding=")); while (MEcmp (d, "\'", sizeof(char)) && MEcmp(d, "\"", sizeof(char))) MEcopy(d++, sizeof(char), &encode[i++]); encode[i++] = MIN_CHAR; encode[i] = EOS; STcat(buf, ERx("-x=")); STcat(buf, encode); break; } } } else if (stat != ENDFILE) { /* unable to read file, report error */ IIUGerr(E_XM000A_Cannot_Read_File, UG_ERR_ERROR, 1, xmlfile); PCexit(FAIL); } stat = SIclose(xmlfile_read); STcat(buf, xmlfile); #ifdef xDEBUG SIprintf ( " query send: %s \n", buf); #endif /* Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *)NULL, &err_code) != OK ) { if (!debug) LOdelete(&sql_file_loc); PCexit(FAIL); } /* ** we should run the sql script ** sql dbname < new_filename */ /* save the current location */ LOcopy(&sql_file_loc, tmp_buf, &curr_loc); /* make a full location path to the location first */ LOfroms(FILENAME, sql_fname, &tmp_buff_loc); LOstfile(&tmp_buff_loc, &curr_loc); LOcopy (&curr_loc, tmp_buf, &tmp_buff_loc); LOtos (&tmp_buff_loc, &tmp_dir); #ifdef xDEBUG SIprintf ("sql file is: %s \n", tmp_dir); #endif /* No space between < and input file for VMS */ STprintf(buf, ERx( "sql -s %s %s %s %s <%s" ), database, user, password, groupid, tmp_dir); #ifdef xDEBUG SIprintf (" query send: %s \n", buf); #endif /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *)NULL, &err_code) != OK ) { if (!debug) LOdelete(&sql_file_loc); PCexit(FAIL); } /* ** Delete the location */ if (!debug) LOdelete(&sql_file_loc); PCexit(OK); }
void IIodbc_timeOutThread() { QUEUE *q, *p, *pq; pENV penv; pDBC pdbc; RETCODE rc; SYSTIME expire_time; TM_STAMP stamp; char stampStr[TM_SIZE_STAMP]; ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread() with timeout %d\n", IIodbc_cb.timeout); while(TRUE) { /* ** Search the pool every thirty seconds and check for expired ** connections. Force disconnect and free from the pool ** if the connection handle has passed the expiration time. ** Note that the CLI and driver connection handles are not ** freed. */ PCsleep(30000); TMget_stamp(&stamp); TMstamp_str(&stamp, stampStr); ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread woke up at %s\n", stampStr); TMnow(&expire_time); if (IIodbc_cb.pooling == DRIVER_POOL) { applyLock(SQL_HANDLE_IIODBC_CB, NULL); for (q = IIodbc_cb.pool_q.q_prev; q!= &IIodbc_cb.pool_q; q = p) { ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread: driver pool count is %d\n", IIodbc_cb.pool_count); p = q->q_prev; pdbc = (pDBC)((pPOOL)q)->pdbc; ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread: found conn handle %p with time diff %d\n",pdbc, expire_time.TM_secs - pdbc->expire_time.TM_secs); if (expire_time.TM_secs - pdbc->expire_time.TM_secs > IIodbc_cb.timeout) { /* ** Note that the connection handle is not freed, only ** removed from the pool. */ ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread: EXPIRED. pdbc time is %d vs %d\n", pdbc->expire_time.TM_secs, expire_time.TM_secs); rc = IIDisconnect(pdbc->hdr.driverHandle); QUremove(q); MEfree((PTR)q); IIodbc_cb.pool_count -= 1; ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("new pool count is %d\n",IIodbc_cb.pool_count); applyLock(SQL_HANDLE_DBC, pdbc); pdbc->hdr.state = C2; releaseLock(SQL_HANDLE_DBC, pdbc); } } releaseLock(SQL_HANDLE_IIODBC_CB, NULL); } else { for (q = IIodbc_cb.env_q.q_prev; q!= &IIodbc_cb.env_q; q = q->q_prev) { penv = (pENV)q; TRdisplay("Found env handle %p\n",penv); applyLock(SQL_HANDLE_ENV, penv); for (pq = penv->pool_q.q_prev; pq != &penv->pool_q; pq = p) { ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("Env pool count is %d\n",penv->pool_count); p = q->q_prev; pdbc = (pDBC)((pPOOL)pq)->pdbc; ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_TimeOutThread: Found conn handle %p with time diff %d\n",pdbc, expire_time.TM_secs - pdbc->expire_time.TM_secs); if (expire_time.TM_secs - pdbc->expire_time.TM_secs > 1) { ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread: EXPIRED. pdbc time is %d vs %d\n", pdbc->expire_time.TM_secs, expire_time.TM_secs); rc = IIDisconnect(pdbc->hdr.driverHandle); QUremove(q); MEfree((PTR)q); penv->pool_count -= 1; ODBC_EXEC_TRACE(ODBC_EX_TRACE) ("IIodbc_timeOutThread: new pool count is %d\n", penv->pool_count); } } releaseLock(SQL_HANDLE_ENV, penv); } /* for (q = IIodbc_cb.env_q.q_prev; q!= &IIodbc_cb.env_q; q = q->q_prev) */ } /* if (IIodbc_cb.pooling == DRIVER_POOL) */ } /* while (TRUE) */ }