@@ -304,9 +304,7 @@ def test_execute_from_commented_file_that_executes_another_file(
304304
305305@dbtest
306306def test_execute_commented_first_line_and_special (executor , pgspecial , tmpdir ):
307- # https://github.com/dbcli/pgcli/issues/1362
308-
309- # just some base caes that should work also
307+ # just some base cases that should work also
310308 statement = "--comment\n select now();"
311309 result = run (executor , statement , pgspecial = pgspecial )
312310 assert result != None
@@ -317,12 +315,14 @@ def test_execute_commented_first_line_and_special(executor, pgspecial, tmpdir):
317315 assert result != None
318316 assert result [1 ].find ("now" ) >= 0
319317
320- statement = "/*comment\n comment line2*/\n select now();"
318+ # https://github.com/dbcli/pgcli/issues/1362
319+ statement = "--comment\n \\ h"
321320 result = run (executor , statement , pgspecial = pgspecial )
322321 assert result != None
323- assert result [1 ].find ("now" ) >= 0
322+ assert result [1 ].find ("ALTER" ) >= 0
323+ assert result [1 ].find ("ABORT" ) >= 0
324324
325- statement = "--comment \n \\ h"
325+ statement = "--comment1 \n --comment2 \n \\ h"
326326 result = run (executor , statement , pgspecial = pgspecial )
327327 assert result != None
328328 assert result [1 ].find ("ALTER" ) >= 0
@@ -334,6 +334,24 @@ def test_execute_commented_first_line_and_special(executor, pgspecial, tmpdir):
334334 assert result [1 ].find ("ALTER" ) >= 0
335335 assert result [1 ].find ("ABORT" ) >= 0
336336
337+ statement = """/*comment1
338+ comment2*/
339+ \h"""
340+ result = run (executor , statement , pgspecial = pgspecial )
341+ assert result != None
342+ assert result [1 ].find ("ALTER" ) >= 0
343+ assert result [1 ].find ("ABORT" ) >= 0
344+
345+ statement = """/*comment1
346+ comment2*/
347+ /*comment 3
348+ comment4*/
349+ \\ h"""
350+ result = run (executor , statement , pgspecial = pgspecial )
351+ assert result != None
352+ assert result [1 ].find ("ALTER" ) >= 0
353+ assert result [1 ].find ("ABORT" ) >= 0
354+
337355 statement = " /*comment*/\n \h;"
338356 result = run (executor , statement , pgspecial = pgspecial )
339357 assert result != None
@@ -352,6 +370,126 @@ def test_execute_commented_first_line_and_special(executor, pgspecial, tmpdir):
352370 assert result [1 ].find ("ALTER" ) >= 0
353371 assert result [1 ].find ("ABORT" ) >= 0
354372
373+ statement = """\\ h /*comment4 */"""
374+ result = run (executor , statement , pgspecial = pgspecial )
375+ print (result )
376+ assert result != None
377+ assert result [0 ].find ("No help" ) >= 0
378+
379+ # TODO: we probably don't want to do this but sqlparse is not parsing things well
380+ # we relly want it to find help but right now, sqlparse isn't dropping the /*comment*/
381+ # style comments after command
382+
383+ statement = """/*comment1*/
384+ \h
385+ /*comment4 */"""
386+ result = run (executor , statement , pgspecial = pgspecial )
387+ assert result != None
388+ assert result [0 ].find ("No help" ) >= 0
389+
390+ # TODO: same for this one
391+ statement = """/*comment1
392+ comment3
393+ comment2*/
394+ \\ h
395+ /*comment4
396+ comment5
397+ comment6*/"""
398+ result = run (executor , statement , pgspecial = pgspecial )
399+ assert result != None
400+ assert result [0 ].find ("No help" ) >= 0
401+
402+
403+ @dbtest
404+ def test_execute_commented_first_line_and_normal (executor , pgspecial , tmpdir ):
405+ # https://github.com/dbcli/pgcli/issues/1403
406+
407+ # just some base cases that should work also
408+ statement = "--comment\n select now();"
409+ result = run (executor , statement , pgspecial = pgspecial )
410+ assert result != None
411+ assert result [1 ].find ("now" ) >= 0
412+
413+ statement = "/*comment*/\n select now();"
414+ result = run (executor , statement , pgspecial = pgspecial )
415+ assert result != None
416+ assert result [1 ].find ("now" ) >= 0
417+
418+ # this simulates the original error (1403) without having to add/drop tables
419+ # since it was just an error on reading input files and not the actual
420+ # command itself
421+
422+ # test that the statement works
423+ statement = """VALUES (1, 'one'), (2, 'two'), (3, 'three');"""
424+ result = run (executor , statement , pgspecial = pgspecial )
425+ assert result != None
426+ assert result [5 ].find ("three" ) >= 0
427+
428+ # test the statement with a \n in the middle
429+ statement = """VALUES (1, 'one'),\n (2, 'two'), (3, 'three');"""
430+ result = run (executor , statement , pgspecial = pgspecial )
431+ assert result != None
432+ assert result [5 ].find ("three" ) >= 0
433+
434+ # test the statement with a newline in the middle
435+ statement = """VALUES (1, 'one'),
436+ (2, 'two'), (3, 'three');"""
437+ result = run (executor , statement , pgspecial = pgspecial )
438+ assert result != None
439+ assert result [5 ].find ("three" ) >= 0
440+
441+ # now add a single comment line
442+ statement = """--comment\n VALUES (1, 'one'), (2, 'two'), (3, 'three');"""
443+ result = run (executor , statement , pgspecial = pgspecial )
444+ assert result != None
445+ assert result [5 ].find ("three" ) >= 0
446+
447+ # doing without special char \n
448+ statement = """--comment
449+ VALUES (1,'one'),
450+ (2, 'two'), (3, 'three');"""
451+ result = run (executor , statement , pgspecial = pgspecial )
452+ assert result != None
453+ assert result [5 ].find ("three" ) >= 0
454+
455+ # two comment lines
456+ statement = """--comment\n --comment2\n VALUES (1,'one'), (2, 'two'), (3, 'three');"""
457+ result = run (executor , statement , pgspecial = pgspecial )
458+ assert result != None
459+ assert result [5 ].find ("three" ) >= 0
460+
461+ # doing without special char \n
462+ statement = """--comment
463+ --comment2
464+ VALUES (1,'one'), (2, 'two'), (3, 'three');
465+ """
466+ result = run (executor , statement , pgspecial = pgspecial )
467+ assert result != None
468+ assert result [5 ].find ("three" ) >= 0
469+
470+ # multiline comment + newline in middle of the statement
471+ statement = """/*comment
472+ comment2
473+ comment3*/
474+ VALUES (1,'one'),
475+ (2, 'two'), (3, 'three');"""
476+ result = run (executor , statement , pgspecial = pgspecial )
477+ assert result != None
478+ assert result [5 ].find ("three" ) >= 0
479+
480+ # multiline comment + newline in middle of the statement
481+ # + comments after the statement
482+ statement = """/*comment
483+ comment2
484+ comment3*/
485+ VALUES (1,'one'),
486+ (2, 'two'), (3, 'three');
487+ --comment4
488+ --comment5"""
489+ result = run (executor , statement , pgspecial = pgspecial )
490+ assert result != None
491+ assert result [5 ].find ("three" ) >= 0
492+
355493
356494@dbtest
357495def test_multiple_queries_same_line (executor ):
0 commit comments