SQLite Forum

SQLite3.exe fails to handle huge multi-line-comment
The solution, as mentioned above, is to write a preprocessor and pipe the output through it before it gets as input into the sqlite3.exe and/or to write a wrapper which scans the .sql file to remove all the multi-comment-lines. - As I wrote at the beginning, the sql file was generated. Where the generator is under my control I will try to work around at the source (as explained as my solution).

Regarding the explanation from Richard I was thinking that each line is read and checked before added to the realloc'd buffer. (That's what **C**ommand **L**ine **I**nterpreter means to me.) Once a multi line buffer has been started and if any next line does not contain the closing */ sequence then simple do NOT add that line to the realloc'd buffer. I understand now the issue and reason in the not required buffering, which is kept to let the SQLite3 core later on throw out the comment block. My suggestion would be to avoid adding not required lines to that buffer - then while the comment is to be continued with any next line the buffer would not grow.

There are some cases of combinations to consider:

* normal line, not collecting the lines of a multi-line-comment : add the line to buffer
* if a line starts with -- then such a line could be dropped from buffering
* line with starting single line comment (any /* to be ignored behind -- ) : add this line to buffer if -- is not starting the line
* line with starting multi-line comment ( /* detected ) : add this line to buffer, remember the state
* while state is 'multi-line-comment started check next line if */ is contained : if yes then add line to buffer if not then drop the line from buffer
* finally the buffer is handed into the sqlite3_prepare, sqlite3_exec, etc with not more than few lines of comment

I hope my thinking and explanations are understandable enough.