diff --git a/builds/win32/defs/compatibility.manifest b/builds/win32/defs/compatibility.manifest
new file mode 100644
index 00000000000..7c39e910875
--- /dev/null
+++ b/builds/win32/defs/compatibility.manifest
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/builds/win32/msvc15/FirebirdCommon.props b/builds/win32/msvc15/FirebirdCommon.props
index 56c69ad71ef..f60c800e00e 100644
--- a/builds/win32/msvc15/FirebirdCommon.props
+++ b/builds/win32/msvc15/FirebirdCommon.props
@@ -43,5 +43,8 @@
RC_ARH_$(Platform);RC_TARGET_$(TargetName);RC_TARGET_NAME=$(TargetName);RC_TARGET_FILENAME=$(TargetFileName);%(PreprocessorDefinitions)
+
+ ..\defs\compatibility.manifest %(AdditionalManifestFiles)
+
diff --git a/src/isql/isql.epp b/src/isql/isql.epp
index fe32f54219c..8e09c24f535 100644
--- a/src/isql/isql.epp
+++ b/src/isql/isql.epp
@@ -99,6 +99,7 @@ enum literal_string_type
#if defined(WIN_NT)
#include
+#include
#endif
#include "ibase.h"
#include "../isql/isql.h"
@@ -349,14 +350,21 @@ static int win32ReadConsole(FILE* file, CharBuffer& mbBuffer)
SetConsoleMode(handle, oldMode);
});
- const size_t MAX_LINE_LENGTH = MAX_USHORT;
- WCHAR* wideBuf = wideBuffer->getBuffer(MAX_LINE_LENGTH, false);
+ // Before Windows 10, ReadConsole() can't work with relatively large input
+ // buffers and set ERROR_NOT_ENOUGH_MEMORY error. Thus, use initial buffer size
+ // twice less than for Windows 10 and handle error by reducing the buffer size.
+
+ static size_t maxLineLength = IsWindows10OrGreater() ? MAX_USHORT : MAX_SSHORT;
+ WCHAR* wideBuf = wideBuffer->getBuffer(maxLineLength, false);
DWORD charsRead;
- if (!ReadConsoleW(handle, wideBuf, MAX_LINE_LENGTH, &charsRead, NULL))
+ while (!ReadConsoleW(handle, wideBuf, maxLineLength, &charsRead, NULL))
{
- fb_assert(false);
- return -1;
+ const DWORD error = GetLastError();
+ if (error == ERROR_NOT_ENOUGH_MEMORY && maxLineLength > 256)
+ maxLineLength -= 256;
+ else
+ Firebird::system_error::raise("ReadConsoleW", error);
}
if (!charsRead)
@@ -764,20 +772,17 @@ static void atexit_fb_shutdown()
int CLIB_ROUTINE main(int argc, char* argv[])
{
-/**************************************
- *
- * m a i n
- *
- **************************************
- *
- * Functional description
- * This calls ISQL_main, and exists to
- * isolate main which does not exist under
- * MS Windows.
- *
- **************************************/
-
- return ISQL_main(argc, argv);
+ try
+ {
+ return ISQL_main(argc, argv);
+ }
+ catch (const Firebird::Exception& ex)
+ {
+ Firebird::StaticStatusVector st;
+ ex.stuffException(st);
+ isc_print_status(st.begin());
+ }
+ return 1;
}