Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:38 25 Nov 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : mmsql 1.2 - SQLite manager for the CMM2

Author Message
homa

Guru

Joined: 05/11/2021
Location: Germany
Posts: 785
Posted: 05:27pm 20 Nov 2026
Copy link to clipboard 
Print this post

mmsql 1.2 - SQLite manager for the CMM2

Hi all,

a new release of mmsql, the interactive SQLite manager for the Colour Maximite 2 (G1, G2, G3). It needs MMBasic 8.00.00b1 or later, 8.00.00b2 is recommended.

The big change: SQL is no longer squeezed into one line of 255 characters.

New in 1.2
- A real editor at the prompt: statements over up to 20 lines with a status line - F3 new line, F2 run, Esc discard
- Paste SQL from the PC: pasted lines are recognised and kept together
- One rule for input: one line runs with Enter; several lines are a block, each statement ends with ;
- Statements and queries over 255 characters, with results - at the prompt, in blocks and in scripts
- History of statements of any length, also after a restart; PgUp/PgDn
- Scripts as in sqlite3: .read takes statements over several lines, shows query results and knows dot commands
- No more 20-column limit: .import without limits for columns and long fields, .insert up to 64 columns
- Database in memory (:memory:) - mmsql starts without a file
- New output: .mode markdown, .mode json, .width, .print
- .dump keeps the real type of every value: BLOB or text, 2.0 stays REAL, very large integers stay exact
- More: .restore, .version, search patterns for .tables/.schema/.indexes/.triggers, .set screen, .set width 0
- Shorter prompt [retro.db]>, and terminal and screen show exactly the same

Note: .read now needs a ; at the end of every statement, as sqlite3 does. Old scripts with one statement per line without ; need a ; at the end of each line. Dumps from mmsql have always had it.

A query over several lines looks like this (F3 after each line, F2 to run - or just paste it), here with computers.db from the firmware zip:
SELECT maker, count(*) AS models, min(year) AS since
 FROM computer
 WHERE year < 1990
 GROUP BY maker
 ORDER BY since;


Three downloads
- mmsql.zip - the program, help files (English and German), README, CHANGES, and the full manual as PDF: MANUAL_mmsql.pdf (English) and HANDBUCH_mmsql.pdf (German)
- mmsql_tutorial.zip - TUTORIAL_mmsql.pdf with demo.sql: SQL and mmsql for beginners, step by step, using computers.db from the firmware zip
- mmsql_testsuite.zip - an automatic test suite for the CMM2: 51 tests of SQLite, .read, .dump, .import and export, run from mmsql itself. Expected results are in README.txt.

To start:
RUN "mmsql", "A:/sql/computers.db"

and then type .help

Thanks
A big thank you to Peter for 8.00.00b2: the history at the MMBasic prompt in the terminal and LGETSTR$ with 255 characters are both fixed.

@Peter: two things from the work on 1.2
- OPTION CONSOLE in a program spoils characters arriving on the serial port. If a program switches OPTION CONSOLE while text is pasted into the terminal, characters get lost or arrive as rubbish - as if the port were set up again each time. mmsql 1.2 no longer switches while it reads keys, so it is not urgent for me. Small example in fw8_option_console.zip - still the same on 8.00.00b2. Is this expected, and is there another way to write to the terminal only, or the screen only?
fw8_option_console.zip

- A wish: SQL(TYPE n). SQL(n) cannot tell a BLOB from a TEXT, or REAL 2.0 from INTEGER 2. To dump correctly, mmsql adds a typeof() column for every column to the query. A function next to SQL(ISNULL n) - for example 1 = INTEGER, 2 = FLOAT, 3 = TEXT, 4 = BLOB, 5 = NULL, as sqlite3_column_type() - would make that easy for any query. Small example in fw8_sql_type.zip.
fw8_sql_type.zip


A question to you
SQLite on the CMM2 is still quite new, and I would like to know how it is used out there:
- Do you already use SQLite on the CMM2? What for - a collection, a logger, a game, something else?
- Do you work with the SQL commands in your own programs, with mmsql, or both?
- Is mmsql useful for you, or does something keep you from using it?
- What is missing? A command, an export format, an example in the tutorial?

A one-line answer is fine - it helps me decide what comes next. Bugs and anything unclear in the manual or tutorial are very welcome, too.

Matthias


mmsql.zip
mmsql_tutorial.zip
mmsql_testsuite.zip

MANUAL_mmsql.pdf
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 12272
Posted: 07:09pm 24 Nov 2026
Copy link to clipboard 
Print this post

SQL on the PicoMite, and mmsql running on it
Matthias,

SQL has now come to the PicoMite, with the same commands as on the CMM2: SQL OPEN, EXEC, QUERY, CREATE, INSERT, CLOSE and the SQL( function, with SQLite loaded as a module. It is in the two builds that run loadable programs: the PicoMitePC3 and the PicoMiteHDMIUSB (with PSRAM).

mmsql 1.2 runs on a PicoComputer 3 with only a handful of lines changed, and your test suite gives part 1 24 of 24, part 2 27 of 27, fail 0. It also found two bugs for me. The PicoMite's FORMAT$ was not exact with "%.17g" (-2.5e-10 came out as -2.4999999999999973e-10), and it printed an infinity as "INFe-2147483648", so five of the .dump round trips failed. FORMAT$ now gives exactly what C's printf gives. The other bug is in the next section.

The attached zip has a test firmware for both builds, the SQLite module and app, the sample database with its example program, the SQL guide, and a PicoMite copy of mmsql (mmsql_pm.bas). The README in the zip says how to install it all; your test suite goes in unchanged.


PicoMite_SQL_test.zip


PicoMitePC3 users: to make room for SQL the PC3's flash region has moved up 16 KB, so its options reset at the first boot of this firmware (the A: drive is kept). Save them first with OPTION DISK SAVE.

Two things that matter on the CMM2 too
• SQL(SELECT with a string joined by + among its arguments returned the joined string instead of the row count. For example, n% = SQL(SELECT "SELECT * FROM t WHERE " + w$, a()) gave "Expected a number". It is fixed on both machines, and the CMM2's fix comes with its next firmware.
• The sample database's CPU column is now PROCESSOR, on both machines. On the PicoMite a TYPE member line that starts with CPU is taken as the CPU command, and SQL matches members to columns by name.

What mmsql meets on the PicoMite
These are the only changes in mmsql_pm.bas; mmsql_pm_changes.txt in the zip has the diff.

1. OPTION CRLF CR is allowed only at the command prompt on the PicoMite ("Invalid in a program"), so it is left out.
2. MM.INFO(HARDWARE) doesn't exist on the PicoMite, so MS_g2% is set to 1 (a PC3 has PSRAM).
3. MM.INFO(MODE) doesn't exist either; it is used only by .set screen.
4. MM.INFO(FILESIZE f$) gives 0 for a missing file (and for a folder) where the CMM2 gives -1 (and -2). A small FSize%() function gives -1 for a missing file.

And two for the README:

• A database must be on B: (the SD card) or C: (a USB drive). A:, the flash, is refused, because each commit would rewrite most of the file. So the test suite goes in B:/sql.
• CHDIR can't change drive on the PicoMite: use DRIVE "B:" : CHDIR "sql".

If you'd like one mmsql for both machines, INSTR(MM.DEVICE$, "PicoMite") tells them apart. It would be great to have it in a future version.

I'd be grateful if you could try it and let me know what you find, particularly anything mmsql does that the test suite doesn't cover.

Peter
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026