SQLite Forum

SQLite3.exe fails to handle huge multi-line-comment
I think the following shell script demonstrates the problem:

> ~~~~
cat >script.tcl <<\EOF
  puts {/*}
  for {set i 0} {$i<10000} {incr i} {puts "SELECT null;"}
  puts {*/}
  puts {SELECT 1, 2, 3;}
tclsh script.tcl | time sqlite3

The TCL script generates 10000 lines of comment prior to a single SELECT
statement.  Each comment line ends with ";".

What I think is going wrong is this:  The sqlite3 shell reads its input
line by line.  As each line is input, it asks "do I have a complete SQL
statement, or do I need to wait for more?"  To implement this test, it
first checks to see if the input ended with ";".  If it did, then it also
calls "sqlite3_complete()" to see whether the input really is complete, or
if the final ";" was perhaps in the middle of a string literal or CREATE
TRIGGER statement or within a comment.  Only if sqlite3_complete() returns
true does the sqlite3 shell try to process the input.

So what is happening here is that because each line of the input comment
ends with ";", sqlite3_complete() gets called over and over again, each
time on successively larger inputs.