Skip to content

Commit 861b2c9

Browse files
authored
fix: fix hang caused by empty INSERT statements (#361)
2 parents 964b120 + 6123ace commit 861b2c9

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Client/ClientBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ void ClientBase::processInsertQuery(String query, ASTPtr parsed_query)
17751775

17761776
/// Process the query that requires transferring data blocks to the server.
17771777
const auto & parsed_insert_query = parsed_query->as<ASTInsertQuery &>();
1778-
if ((!parsed_insert_query.data && !parsed_insert_query.infile) && (is_interactive || (!stdin_is_a_tty && !isStdinNotEmptyAndValid(*std_in))))
1778+
if ((!parsed_insert_query.data && !parsed_insert_query.infile) && (true /* is_interactive || (!stdin_is_a_tty && !isStdinNotEmptyAndValid(*std_in)) */))
17791779
{
17801780
const auto & settings = client_context->getSettingsRef();
17811781
if (settings[Setting::throw_if_no_data_to_insert])

tests/test_insert_error_handling.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
3+
import unittest
4+
import shutil
5+
import os
6+
from chdb import session
7+
8+
test_dir = ".test_insert_error"
9+
10+
class TestInsertErrorHandling(unittest.TestCase):
11+
"""Test cases for INSERT query error handling to ensure proper exceptions are thrown."""
12+
13+
def setUp(self) -> None:
14+
shutil.rmtree(test_dir, ignore_errors=True)
15+
self.sess = session.Session(test_dir)
16+
return super().setUp()
17+
18+
def tearDown(self) -> None:
19+
"""Clean up test environment."""
20+
shutil.rmtree(test_dir, ignore_errors=True)
21+
return super().tearDown()
22+
23+
def test_incomplete_insert_values_throws_error(self):
24+
"""Test that incomplete INSERT VALUES query throws RuntimeError instead of hanging."""
25+
26+
self.sess.query(
27+
"CREATE TABLE test_table(id UInt32, name String, value Float64) ENGINE = Memory"
28+
)
29+
30+
# This should throw an error because VALUES clause is incomplete (no actual values provided)
31+
with self.assertRaises(RuntimeError) as context:
32+
self.sess.query("INSERT INTO test_table (id, name, value) VALUES")
33+
34+
35+
if __name__ == "__main__":
36+
unittest.main()

0 commit comments

Comments
 (0)