Skip to content

Commit

Permalink
Postfix for CORE-3990
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPeshkoff committed Mar 1, 2013
1 parent cfbe804 commit 62f06e6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
41 changes: 36 additions & 5 deletions src/isql/InputDevices.cpp
Expand Up @@ -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);
}
}
}

Expand All @@ -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();
}
20 changes: 17 additions & 3 deletions src/isql/InputDevices.h
Expand Up @@ -27,6 +27,8 @@

#include "../common/classes/fb_string.h"
#include "../common/os/path_utils.h"
#include "../common/classes/array.h"

#include <stdio.h>

// This is basically a stack of input files caused by the INPUT command,
Expand Down Expand Up @@ -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<Command*, 32> commands;
};


Expand All @@ -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)
{
}

Expand Down
3 changes: 3 additions & 0 deletions src/isql/isql.epp
Expand Up @@ -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
Expand Down

0 comments on commit 62f06e6

Please sign in to comment.