COMMIT fails with "SQL: disk I/O error" - CMM2 G2, MMBasic 8.00.00b1
=====================================================================

Peter,

COMMIT fails with "SQL: disk I/O error" when a program reads a SQL file
line by line and runs the lines, and one line is longer than 255
characters (so it is collected in a LONGSTRING). It is reproducible,
also right after a restart, with a file written on the CMM2 itself.
I found it with .read of a dump in my SQLite tool; these programs show
it without the tool.

How to reproduce (all files in one folder):

  RUN "mkio3"                writes io3.sql (410 bytes):
                               BEGIN TRANSACTION;
                               CREATE TABLE t(id INTEGER PRIMARY KEY, note TEXT);
                               INSERT INTO t VALUES(1,'AAA...');  (327 chars)
                               COMMIT;
  RUN "iotest5", "io3.sql"

My output (three times the same, also after a restart):

Run 1: read and run line by line
   BEGIN TRANSACTION                        OK
   CREATE TABLE t(id INTEGER PRIMARY KEY, n OK
   (long, 327 chars) INSERT INTO t VALUES(1 OK
   COMMIT                                   ERROR: SQL: disk I/O error
   journal left over
   iot.db: 0 bytes
Run 2: read all lines first, then run them
   ... all OK, COMMIT OK, iot.db: 8192 bytes
Run 3: for each line open, SEEK, read, CLOSE #7, then run it
   ... COMMIT  ERROR: SQL: disk I/O error, journal left over, 0 bytes

So:
- Run 1 fails: the lines are read while the transaction is open.
- Run 3 fails too, although the file is closed whenever SQL runs.
- Run 2 works: the same lines read before the transaction starts.
- Contrast: RUN "mkio4" and RUN "iotest5", "io4.sql" - the same
  but with 12 short INSERTs (no line over 255): runs 1 and 3 work.

So it seems to need: reading the long line (INPUT$ blocks + LONGSTRING
APPEND/RESIZE/LGETSTR$ in iotest5's RdLine) while the transaction is
open. After a failure the database file is empty and the journal is
left; once, CLOSE #7 afterwards gave "The file/directory object is
invalid".

What I tested and found working (each case: new database, BEGIN ...,
COMMIT OK):
- a LONGSTRING statement, and a LONGSTRING value, inside a transaction
- a file open and read with INPUT$ between the statements; reading to
  EOF inside the transaction, before or after the INSERT
- DIR$() before or inside the transaction; file #1 instead of #7
- a failing BEGIN ("cannot start a transaction within a transaction")
- LLEN, LGETSTR$, LONGSTRING RESIZE, LINSTR, CLEAR, APPEND of 200, 254
  and 255 characters, each on its own inside a transaction
- SQL EXEC of a LONGSTRING after RESIZE or after CLEAR + shorter text
  runs exactly LLEN characters (does not read past the length)
Only the whole line reader of iotest5 inside the transaction fails.
On 7.00.00RC6 the same .read of dumps worked.

Matthias
