diff --git a/src/isql/InputDevices.cpp b/src/isql/InputDevices.cpp index c630a3998b0..ed66b364f6b 100644 --- a/src/isql/InputDevices.cpp +++ b/src/isql/InputDevices.cpp @@ -247,11 +247,18 @@ void InputDevices::saveCommand(const char* statement, const char* term) if (m_ifp.indev_fpointer == stdin) { FILE* f = m_ofp.indev_fpointer; - fb_assert(f); - fputs(statement, f); - fputs(term, f); - // Add newline to make the file more readable. - fputc('\n', f); + if (f) + { + fputs(statement, f); + fputs(term, f); + // Add newline to make the file more readable. + fputc('\n', f); + } + else + { + Command* command = new Command(statement, term); + commands.add(command); + } } } @@ -270,3 +277,27 @@ void InputDevices::gotoEof() fseek(m_ifp.indev_fpointer, 0, SEEK_END); } +InputDevices::Command::Command(const char* statement, const char* term) + : m_statement(getPool()) +{ + m_statement = statement; + m_statement += term; +} + +void InputDevices::Command::toFile(FILE* f) +{ + fputs(m_statement.c_str(), f); + // Add newline to make the file more readable. + fputc('\n', f); +} + +void InputDevices::commandsToFile(FILE* f) +{ + for (unsigned n = 0; n < commands.getCount(); ++n) + { + commands[n]->toFile(f); + delete commands[n]; + } + + commands.clear(); +} diff --git a/src/isql/InputDevices.h b/src/isql/InputDevices.h index 90b37147818..1b4566a8494 100644 --- a/src/isql/InputDevices.h +++ b/src/isql/InputDevices.h @@ -27,6 +27,8 @@ #include "../common/classes/fb_string.h" #include "../common/os/path_utils.h" +#include "../common/classes/array.h" + #include // This is basically a stack of input files caused by the INPUT command, @@ -83,12 +85,24 @@ class InputDevices void saveCommand(const char* statement, const char* term); bool readingStdin() const; void gotoEof(); + void commandsToFile(FILE* fpointer); private: size_t m_count; indev* m_head; indev m_ifp; indev m_ofp; + + class Command : public Firebird::GlobalStorage + { + public: + Command(const char* statement, const char* term); + void toFile(FILE* fpointer); + private: + Firebird::string m_statement; + }; + + Firebird::HalfStaticArray commands; }; @@ -105,12 +119,12 @@ inline void InputDevices::indev::close() inline InputDevices::InputDevices() - : m_count(0), m_head(0), m_ifp(0, "", ""), m_ofp(0, "", "") + : m_count(0), m_head(0), m_ifp(0, "", ""), m_ofp(0, "", ""), commands(*getDefaultMemoryPool()) { } -inline InputDevices::InputDevices(Firebird::MemoryPool&) - : m_count(0), m_head(0), m_ifp(0, "", ""), m_ofp(0, "", "") +inline InputDevices::InputDevices(Firebird::MemoryPool& p) + : m_count(0), m_head(0), m_ifp(0, "", ""), m_ofp(0, "", ""), commands(p) { } diff --git a/src/isql/isql.epp b/src/isql/isql.epp index dfe6ee0c506..2a0aa5918d4 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -4465,7 +4465,10 @@ static processing_state edit(const TEXT* const* cmd) const char* Tmpfile = filename.c_str(); FILE* f = fopen(Tmpfile, "w+"); // It was w+b if (f) + { Ofp.init(f, Tmpfile, Tmpfile); + Filelist->commandsToFile(f); + } else { // If we can't open a temp file then bail