diff --git a/src/isql/isql.epp b/src/isql/isql.epp index d76410213aa..aab79f53704 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -4176,27 +4176,6 @@ static void do_isql() M__trans = 0; - // File used to edit sessions - { // scope - const Firebird::PathName filename = TempFile::create(SCRATCH); - const char* Tmpfile = filename.c_str(); - FILE* f = fopen(Tmpfile, "w+"); // It was w+b -#ifdef UNIX - unlink(Tmpfile); -#endif - if (f) - Filelist->Ofp().init(f, Tmpfile); - else - { - // If we can't open a temp file then bail - - ISQL_msg_get(FILE_OPEN_ERR, errbuf, SafeArg() << Tmpfile); - STDERROUT(errbuf); - Exit_value = FINI_ERROR; - return; - } - } - #if defined(_MSC_VER) && _MSC_VER >= 1400 _set_output_format(_TWO_DIGIT_EXPONENT); #endif @@ -4388,9 +4367,9 @@ static void do_isql() gds_trans = 0; InputDevices::indev& Ofp = Filelist->Ofp(); - // Should have a valid Temp file pointer - fb_assert(Ofp.indev_fpointer); - Ofp.drop(); + // Does it have a valid Temp file pointer? + if (Ofp.indev_fpointer) + Ofp.drop(); if (global_sqlda) ISQL_FREE(global_sqlda); @@ -4506,6 +4485,25 @@ static processing_state edit(const TEXT* const* cmd) Filelist->insertIfp(); // Close the file, edit it, then reopen and read from the top InputDevices::indev& Ofp = Filelist->Ofp(); + + if (!Ofp.indev_fpointer) + { + // File used to edit sessions + const Firebird::PathName filename = TempFile::create(SCRATCH); + const char* Tmpfile = filename.c_str(); + FILE* f = fopen(Tmpfile, "w+"); // It was w+b + if (f) + Ofp.init(f, Tmpfile); + else + { + // If we can't open a temp file then bail + TEXT errbuf[MSG_LENGTH]; + ISQL_msg_get(FILE_OPEN_ERR, errbuf, SafeArg() << Tmpfile); + STDERROUT(errbuf); + return ps_ERR; + } + } + Ofp.close(); const char* Tmpfile = Ofp.fileName(); gds__edit(Tmpfile, 0); @@ -4647,7 +4645,8 @@ static processing_state escape(const TEXT* cmd) //_flushall(); // Save Ofp position in case it's being used as input. See EDIT command. fpos_t OfpPos = 0; - Filelist->Ofp().getPos(&OfpPos); + if (Ofp.indev_fpointer) + Filelist->Ofp().getPos(&OfpPos); fflush(NULL); // Flush only output buffers. const char* emptyCmd = "%ComSpec%"; #else @@ -4663,7 +4662,7 @@ static processing_state escape(const TEXT* cmd) #ifdef WIN_NT // If we are reading from the temp file, restore the read position because // it's opened in r+ mode in this case, that's R/W. - if (Filelist->sameInputAndOutput()) + if (Ofp.indev_fpointer && Filelist->sameInputAndOutput()) Filelist->Ofp().setPos(&OfpPos); #endif @@ -5564,8 +5563,9 @@ static processing_state get_statement(TEXT* const statement, // If this is not tmpfile, close it - if (!Filelist->sameInputAndOutput()) - Filelist->Ifp().close(); + if (Filelist->Ofp().indev_fpointer) + if (!Filelist->sameInputAndOutput()) + Filelist->Ifp().close(); // Reset to previous after other input