Skip to content

Commit 254364d

Browse files
authored
Merge pull request #8691 from FirebirdSQL/work/gh-8690
Fix for bug #8690 : On Windows 7 isql exits silently right after the start.
2 parents f63a83d + 91826b6 commit 254364d

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!-- compatibility.manifest -->
2+
<!-- see https://learn.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1 -->
3+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
4+
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
5+
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
6+
<application>
7+
<!-- Windows 10 and Windows 11 -->
8+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
9+
<!-- Windows 8.1 -->
10+
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
11+
<!-- Windows 8 -->
12+
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
13+
<!-- Windows 7 -->
14+
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
15+
<!-- Windows Vista -->
16+
<!-- supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/ -->
17+
</application>
18+
</compatibility>
19+
</assembly>

builds/win32/msvc15/FirebirdCommon.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@
4343
<ResourceCompile>
4444
<PreprocessorDefinitions>RC_ARH_$(Platform);RC_TARGET_$(TargetName);RC_TARGET_NAME=$(TargetName);RC_TARGET_FILENAME=$(TargetFileName);%(PreprocessorDefinitions)</PreprocessorDefinitions>
4545
</ResourceCompile>
46+
<Manifest>
47+
<AdditionalManifestFiles>..\defs\compatibility.manifest %(AdditionalManifestFiles)</AdditionalManifestFiles>
48+
</Manifest>
4649
</ItemDefinitionGroup>
4750
</Project>

src/isql/isql.epp

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ enum literal_string_type
9999

100100
#if defined(WIN_NT)
101101
#include <windows.h>
102+
#include <VersionHelpers.h>
102103
#endif
103104
#include "ibase.h"
104105
#include "../isql/isql.h"
@@ -349,14 +350,21 @@ static int win32ReadConsole(FILE* file, CharBuffer& mbBuffer)
349350
SetConsoleMode(handle, oldMode);
350351
});
351352

352-
const size_t MAX_LINE_LENGTH = MAX_USHORT;
353-
WCHAR* wideBuf = wideBuffer->getBuffer(MAX_LINE_LENGTH, false);
353+
// Before Windows 10, ReadConsole() can't work with relatively large input
354+
// buffers and set ERROR_NOT_ENOUGH_MEMORY error. Thus, use initial buffer size
355+
// twice less than for Windows 10 and handle error by reducing the buffer size.
356+
357+
static size_t maxLineLength = IsWindows10OrGreater() ? MAX_USHORT : MAX_SSHORT;
358+
WCHAR* wideBuf = wideBuffer->getBuffer(maxLineLength, false);
354359

355360
DWORD charsRead;
356-
if (!ReadConsoleW(handle, wideBuf, MAX_LINE_LENGTH, &charsRead, NULL))
361+
while (!ReadConsoleW(handle, wideBuf, maxLineLength, &charsRead, NULL))
357362
{
358-
fb_assert(false);
359-
return -1;
363+
const DWORD error = GetLastError();
364+
if (error == ERROR_NOT_ENOUGH_MEMORY && maxLineLength > 256)
365+
maxLineLength -= 256;
366+
else
367+
Firebird::system_error::raise("ReadConsoleW", error);
360368
}
361369

362370
if (!charsRead)
@@ -764,20 +772,17 @@ static void atexit_fb_shutdown()
764772

765773
int CLIB_ROUTINE main(int argc, char* argv[])
766774
{
767-
/**************************************
768-
*
769-
* m a i n
770-
*
771-
**************************************
772-
*
773-
* Functional description
774-
* This calls ISQL_main, and exists to
775-
* isolate main which does not exist under
776-
* MS Windows.
777-
*
778-
**************************************/
779-
780-
return ISQL_main(argc, argv);
775+
try
776+
{
777+
return ISQL_main(argc, argv);
778+
}
779+
catch (const Firebird::Exception& ex)
780+
{
781+
Firebird::StaticStatusVector st;
782+
ex.stuffException(st);
783+
isc_print_status(st.begin());
784+
}
785+
return 1;
781786
}
782787

783788

0 commit comments

Comments
 (0)