/*{ ** Name: RSblob_gcCallback - IIapi_getColumns callback for blobs ** ** Description: ** If the blob is smaller than DB_MAXTUP-2 bytes, set the blob size and ** return. Otherwise, open a temporary file in II_TEMPORARY and write the ** blob segments to it. ** ** Inputs: ** closure - closure (unused) ** parmBlock - IIAPI_GETCOLPARM parameter block ** ** Outputs: ** RS_BLOB buffer is updated. ** ** Returns: ** none */ II_VOID II_FAR II_CALLBACK RSblob_gcCallback( II_PTR closure, II_PTR parmBlock) { IIAPI_GETCOLPARM *gcolParm = (IIAPI_GETCOLPARM *)parmBlock; RS_BLOB *blob = (RS_BLOB *)gcolParm->gc_columnData[0].dv_value; LOCATION loc; char *p; i4 cnt; if (!blob->fp && !blob->size) { /* ** If this is the only segment, just set the size from the ** length. */ if (!gcolParm->gc_moreSegments) { blob->size = blob->len; return; } /* ** If there are more segments and the file hasn't been opened, ** create a new temporary file. */ NMloc(TEMP, PATH, NULL, &loc); LOuniq(ERx("bl"), ERx("tmp"), &loc); LOtos(&loc, &p); STcopy(p, blob->filename); if (SIfopen(&loc, ERx("w"), SI_VAR, sizeof blob->buf, &blob->fp) != OK) { gcolParm->gc_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY; return; } } /* write the current segment to a file and add to the size */ if (SIwrite((i4)blob->len, blob->buf, &cnt, blob->fp) != OK) { gcolParm->gc_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY; return; } blob->size += blob->len; /* if this is the last segment, close the temporary file */ if (!gcolParm->gc_moreSegments) { if (SIclose(blob->fp) != OK) { gcolParm->gc_genParm.gp_status = IIAPI_ST_OUT_OF_MEMORY; return; } blob->fp = NULL; } }
/*{ ** Name: open_outfile - creates or appends to an output file ** ** Description: ** Creates or opens (for append) a file in a directory and sets a ** LOCATION structure. ** ** Inputs: ** out_filename - output file name ** out_dir - output directory ** create_or_append - create a new file or append to existing file ** uniq - make a unique filename ** ** Outputs: ** loc_name - output file path ** ** Returns: ** NULL - open failed ** FILE * - file pointer */ FILE * open_outfile( char *out_filename, char *out_dir, char *create_or_append, char *loc_name, bool uniq) { FILE *out_file; char *p; char filename[MAX_LOC+1]; LOCATION loc; if (loc_name == NULL) return (NULL); if (CMcmpcase(create_or_append, ERx("c")) == 0) { STcopy(out_dir, filename); LOfroms(PATH, filename, &loc); /* if uniq is 1, create a unique filename */ if (uniq == 1) LOuniq(out_filename, ERx(""), &loc); else LOfstfile(out_filename, &loc); if (SIfopen(&loc, ERx("w"), SI_TXT, SI_MAX_TXT_REC, &out_file) != OK) { IIUGerr(E_RM00F2_Err_open_outfile, UG_ERR_ERROR, 1, out_filename); return (NULL); } LOtos(&loc, &p); STcopy(p, loc_name); } else { LOfroms(PATH & FILENAME, loc_name, &loc); if (SIfopen(&loc, ERx("a"), SI_TXT, SI_MAX_TXT_REC, &out_file) != OK) { IIUGerr(E_RM00F2_Err_open_outfile, UG_ERR_ERROR, 1, out_filename); return (NULL); } } return (out_file); }
VOID gca_save( GCA_SVC_PARMS *svc_parms ) { GCA_ACB *acb = svc_parms->acb; GCA_SV_PARMS *sv_parms = (GCA_SV_PARMS *)svc_parms->parameter_list; GCA_SAVE_DATA save_data; PTR user_buf = sv_parms->gca_ptr_user_data; i4 user_size = sv_parms->gca_length_user_data; char cl_buf[ GCA_MAX_CL_SAVE_SIZE ]; i4 cl_size; LOCATION file_loc; LOCATION tmp_loc; char loc_buf[ MAX_LOC ]; FILE *save_file; char *save_ptr; char file_id[ MAX_LOC ]; i4 j; /* Initialize status in service invoker's parameter list */ sv_parms->gca_status = E_GCFFFF_IN_PROCESS; /* Get CL save info */ svc_parms->gc_parms.svc_buffer = (PTR)cl_buf; svc_parms->gc_parms.reqd_amount = sizeof( cl_buf ); GCsave( &svc_parms->gc_parms ); if ( svc_parms->gc_parms.status != OK ) goto complete; cl_size = svc_parms->gc_parms.rcv_data_length; /* Format GCA_SAVE_DATA structure */ save_data.save_level_major = GCA_SAVE_LEVEL_MAJOR; save_data.save_level_minor = GCA_SAVE_LEVEL_MINOR; save_data.cl_save_size = cl_size; save_data.user_save_size = user_size; save_data.assoc_id = acb->assoc_id; save_data.size_advise = acb->size_advise; save_data.heterogeneous = acb->flags.heterogeneous; /* Create the save file name. */ file_id[0] = '\0'; (VOID) LOfroms(PATH & FILENAME, file_id, &tmp_loc); (VOID) LOuniq("IIGC", "TMP", &tmp_loc); (VOID) NMloc(TEMP, FILENAME, file_id, &tmp_loc); (VOID) LOcopy( &tmp_loc, loc_buf, &file_loc ); (VOID) LOtos( &file_loc, &save_ptr ); (VOID) STcopy( save_ptr, sv_parms->gca_save_name ); /* Open save file. */ if( SIfopen( &file_loc, "w", SI_VAR, 0, &save_file ) != OK ) { GCA_DEBUG_MACRO(1)( "gca_send bad file open\n" ); svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL; goto complete; } /* Write GCA, CL, and user data to save file. */ if( SIwrite( sizeof( save_data ), (PTR)&save_data, &j, save_file ) != OK || cl_size && SIwrite( cl_size, (PTR)cl_buf, &j, save_file ) != OK || user_size && SIwrite( user_size, user_buf, &j, save_file ) != OK || SIclose( save_file ) != OK ) { GCA_DEBUG_MACRO(1)( "gca_send bad file write/close\n" ); (VOID) SIclose( save_file ); (VOID) LOdelete( &file_loc ); svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL; } complete: return; }
void main(int argc, char *argv[]) { #define MAXBUF 4095 #define MAX_NAME 32 char buf[ MAXBUF+1 ]; char repbuf[ MAXBUF+1 ]; int iarg, ibuf, ichr; char *database = NULL; char username[MAX_NAME] = {""}; LOCATION tloc; LOCATION loc_out; LOCATION loc_in; char loc_buf[MAX_LOC + 1]; char tmp_buf[MAX_LOC + 1]; char otmp_buf[MAX_LOC + 1]; char dev[MAX_LOC + 1]; char path[MAX_LOC + 1]; char fprefix[MAX_LOC + 1]; char fsuffix[MAX_LOC + 1]; char version[MAX_LOC + 1]; char odev[MAX_LOC + 1]; char opath[MAX_LOC + 1]; char ofprefix[MAX_LOC + 1]; char ofsuffix[MAX_LOC + 1]; char oversion[MAX_LOC + 1]; char *new_filename; char *temploc; CL_ERR_DESC err_code; char *p1 = NULL; bool usergiven = FALSE; bool Repmod = FALSE; bool nowait = TRUE; char waitflag[3]; if (argc < 2) { usage(); PCexit(FAIL); } /* Get the temporary path location */ NMloc(TEMP, PATH, NULL, &tloc); LOcopy(&tloc, tmp_buf, &loc_in); LOtos(&tloc, &temploc); LOcopy(&tloc, otmp_buf, &loc_out); /* Get the new filename for path location */ LOuniq(ERx("usrmod"), ERx("sql"), &loc_in); LOtos(&loc_in, &new_filename); LOuniq(ERx("usrmod"), ERx("out"), &loc_out); /* Get just the filename for copydb code */ LOdetail(&loc_in, dev, path, fprefix, fsuffix, version); if ( *fsuffix != '\0' ) { STcat(fprefix, "."); STcat(fprefix, fsuffix); } /* Get just the filename for copydb code */ LOdetail(&loc_out, odev, opath, ofprefix, ofsuffix,oversion); STcat(ofprefix, "."); STcat(ofprefix, ofsuffix); STprintf(buf, ERx("copydb -with_modify -nodependency_check -with_index -with_comments -no_persist -parallel -no_repmod -group_tab_idx -no_warn -d\"%s\" -infile=\"%s\" -outfile=\"%s\"" ), temploc, fprefix,ofprefix); ibuf = STlength(buf); for (iarg = 1; (iarg < argc) && (ibuf < MAXBUF); iarg++) { if( STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) == 0 ) { p1 = argv[ iarg ]; (void) CMnext( p1 ); if ( (STlength(p1) == 0) || !(((STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) || (STscompare( p1, 5, ERx( "noint" ), 5 ) == 0 ) || (STscompare( p1, 6, ERx( "repmod" ), 6 ) == 0 ) || (STscompare( p1, 1, ERx( "w" ), 6 ) == 0 ) || (STscompare( p1, 6, ERx( "online"), 6 ) == 0 )) && ( argc > 2 ) )) { usage(); PCexit(FAIL); } /* ** Get the username if the -u flag is passed in ** with the input */ if (STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) { STcopy(&argv[iarg][2] , (char *)&username); usergiven = TRUE; } else if (STscompare( p1, 1, ERx( "r" ), 1 ) == 0 ) { Repmod = TRUE; continue; } else if (STscompare( p1, 1, ERx( "w"), 1 ) == 0) { nowait = TRUE; continue; } } if( STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) == 0 ) { p1 = argv[ iarg ]; (void) CMnext( p1 ); if (STscompare( p1, 1, ERx( "w" ), 1 ) == 0 ) { nowait = FALSE; continue; } else { usage(); PCexit(FAIL); } } if((database == NULL) && (STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) != 0) && (STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) != 0)) { database = argv[ iarg ]; } buf[ibuf++] = ' '; for (ichr = 0; (argv[iarg][ichr] != '\0') && (ibuf < MAXBUF); ichr++, ibuf++) { buf[ibuf] = argv[iarg][ichr]; } buf[ibuf] = '\0'; } /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) PCexit(FAIL); /* ** we should run the sql script ** sql dbname < new_filename ** if -u flag given then run: ** sql -uusername dbname < new_filename */ if (usergiven) STprintf(buf, ERx( "sql -u%s -s %s <%s" ), username, database, new_filename ); else STprintf(buf, ERx( "sql -s %s <%s" ), database, new_filename ); /* ** Execute the command. */ if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) { STprintf(buf, ERx(" Warning: Non-persistent objects associated with the base table\n in the failed query may have been lost. Please refer to\n %s\n to determine whether any corrective action is required.\n"), new_filename); SIfprintf(stdout, buf); PCexit(FAIL); } /* Now execute the repmod command if the replicator ** modify is also required by the user (-repmod) */ if (Repmod) { if (nowait) STcopy("-w", waitflag) ; else STcopy("+w", waitflag) ; if (usergiven) STprintf(repbuf, ERx( "repmod -u%s %s %s" ), username, database, waitflag ); else STprintf(repbuf, ERx( "repmod %s %s" ), database, waitflag ); if( PCcmdline((LOCATION *) NULL, repbuf, PC_WAIT, (LOCATION *) NULL, &err_code) != OK ) PCexit(FAIL); } /* ** Delete the location */ LOdelete(&loc_in); LOdelete(&loc_out); PCexit(OK); }
edit() { register char *p; LOCATION t_loc, loc; FILE *fp; char errbuf[ER_MAX_LEN + 1]; char input[MAX_LOC + 1]; char *editfile; char *ingedit; i4 rflag; STATUS status; i4 c; #ifdef CMS i4 Notempty = 1; #endif /* CMS */ GLOBALREF char *IIMOildInitLnDraw; FUNC_EXTERN char *getfilenm(); FUNC_EXTERN char *macro(); if (!Newline) { q_putc(Qryiop, '\n'); Newline = TRUE; } Autoclear = 0; editfile = getfilenm(); rflag = 0; if (*editfile == '\0') { rflag = 1; input[0] = EOS; if ((status = NMloc( TEMP, PATH, (char *)NULL, &t_loc)) || (status = LOuniq( ERx( "query" ), ERx( "edt" ), &t_loc))) { STcopy( ERx( "queryXXX" ), input ); } else { LOcopy( &t_loc, input, &loc ); } status = SIfopen( &loc, ERx( "w" ), (i4)SI_TXT, (i4)SI_MAX_TXT_REC, &fp ); } else { /* use the path and file name the user gave you */ STcopy(editfile, input); if (!(status = LOfroms(PATH & FILENAME, input, &loc))) status = SIfopen( &loc, ERx("w"), (i4)SI_TXT, (i4)SI_MAX_TXT_REC, &fp ); } if (status) { if (status == FAIL) errbuf[0] = '\0'; else ERreport(status, errbuf); putprintf(ERget(F_MO000C_Cant_create_qry_file), input, errbuf); cgprompt(); return(0); } if (q_ropen(Qryiop, 'r') == (struct qbuf *)NULL) /* edit: q_ropen 1 */ ipanic(E_MO0044_1500400); while ((c = (i4)q_getc(Qryiop)) > 0) SIputc((char)c, fp); SIclose(fp); if (Nodayfile >= 0) { putprintf(ERget(F_MO000D_editor_prompt)); SIflush(stdout); } /* ** macro returns NULL if undefined, UTedit uses ** default editor if passed NULL. */ /* Bug 4875 - Use editor defined by environment variable ING_EDIT. If that is not set then use the macro(editor). */ NMgtAt((ERx("ING_EDIT")), &ingedit); if ( ingedit != NULL && *ingedit != EOS ) p = ingedit; else p = macro(ERx("{editor}")); if (status = UTedit(p, &loc)) { ERreport(status, errbuf); putprintf(ERget(F_MO000E_Can_t_start_up_editor), errbuf); cgprompt(); return(0); } if (!rflag) { if (q_ropen(Qryiop, 'a') == (struct qbuf *)NULL) /* edit: q_ropen 2 */ ipanic(E_MO0045_1500401); } else { if (q_ropen(Qryiop, 'w') == (struct qbuf *)NULL) /* edit: q_ropen 3 */ ipanic(E_MO0046_1500402); if (status = SIfopen( &loc, ERx("r"), (i4)SI_TXT, (i4)SI_MAX_TXT_REC, &fp )) #ifdef CMS { Notempty = 0; } #else { ERreport(status, errbuf); /* can't reopen editfile %s: %s\n */ ipanic(E_MO0047_1500403, editfile, errbuf); } #endif /* CMS */ #ifdef CMS if (Notempty) { #endif /* CMS */ Notnull = 0; while ((c = SIgetc(fp)) != EOF) { if (status) { ERreport(status, errbuf); /* Error reading edit file: %s\n */ ipanic(E_MO0048_1500404, errbuf); } Notnull = 1; q_putc(Qryiop, (char)c); } SIclose(fp); if (status = LOpurge(&loc, 0)) { ERreport(status, errbuf); putprintf(ERget(F_MO000F_Cant_delete_file), editfile, errbuf); } #ifdef CMS } /* endif Notempty */ #endif /* CMS */ } #ifndef FT3270 /* Re-Initialize IT line drawing */ { if (Outisterm && IIMOildInitLnDraw != NULL) SIprintf(ERx("%s"), IIMOildInitLnDraw); } #endif cgprompt(); return(0); }