diff --git a/src/isql/InputDevices.cpp b/src/isql/InputDevices.cpp index 47a24a22ef..80a7550c9a 100644 --- a/src/isql/InputDevices.cpp +++ b/src/isql/InputDevices.cpp @@ -226,11 +226,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); + } } } @@ -249,3 +256,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 8dab9f6f46..56334b11c1 100644 --- a/src/isql/InputDevices.h +++ b/src/isql/InputDevices.h @@ -35,6 +35,8 @@ // Do not confuse this "Ofp" with the user defined redirection of isql output to a file. // The logic could be simpler but changing Borland code is tricky here. +#include "../common/classes/array.h" + class InputDevices { public: @@ -78,12 +80,24 @@ public: 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; }; @@ -100,12 +114,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 aab79f5370..91774469fc 100644 --- a/src/isql/isql.epp +++ b/src/isql/isql.epp @@ -4493,7 +4493,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); + Filelist->commandsToFile(f); + } else { // If we can't open a temp file then bail