SQLite from BASIC
Gavin Smith (1413) 95 posts |
Has anyone done anything with SQLite from BASIC? I’d like to run queries and do minor updates on a SQLite database from BASIC, and perhaps build a little WIMP around the commands eventually. I know of Richard Windley’s ports at https://www.reallysmall.co.uk/Pages/categories/riscos/database/sqlite.php but I’d like to use it from BASIC (and really wish it was installed by standard on RISC OS). |
Andy S (2979) 504 posts |
From BASIC I guess the easiest, but also very inefficient, way would be OSCLI commands to pass queries to the SQLite command line tool. Other than that, I would have thought you’d have to resort to something much more complicated: either to write some SWIs to call the library functions and then invoke those SWIs from BASIC, or call the library functions from the BASIC assembler. Maybe someone else will know of a better option. |
Bryan (8467) 468 posts |
Is there a way to get answers back from queries sent using OSCLI? If there is, then I would like to use that for another small project. |
Andy S (2979) 504 posts |
It’s getting even messier, but you could try running before you issue the commands with OSCLI. That should write all the commands’ output into MyDataFile, which you could later read. After the commands, just run to stop further output being redirected.
As well as OSCLI, there’s also the SWI OS_CLI and OS_ChangeRedirection to redirect OS_CLI’s output (or input) with a file handle and OS_FSControl 11 if you need to specify a filing system for the file handle, and OS_FSControl 19 to restore it. https://www.riscosopen.org/wiki/documentation/show/OS_CLI It would be a lot nicer if there was a way to just read directly what appears in standard output without writing to a file but I don’t know how you’d go about that in RISC OS. |
Stuart Swales (1481) 351 posts |
Just run the command specifying either C-style redirection: OSCLI\(“command > $.Temp.foo”) or OS-style: OSCLI\(“command { > $.Temp.foo }”) |
Rick Murray (539) 13851 posts |
While Andy’s For everything:
However there is a slightly different method available for C programs. To capture normal output to the screen, you can use one of:
Note that for C-style, there is no space between the greater than and the filename, and there are no curly braces.
You can combine these:
Note, though, that they cannot both point to the same filename, or you’ll get the C library returning the error “Cannot open XXX for I/O redirection”. There is no interactivity. Commands complete, file is closed, you can read it. If you want interactivity, you’ll need to be running in the Desktop and set up a TaskWindow and interact with that. It’s quite a bit more complicated.
I would say “cheat” and point you at PipeFS, but this appears to only hold/buffer 256 bytes at a time, meaning most output will stall awaiting the data being read. It works between two TaskWindows, one program can output data that the other can see, but a program started using OSCLI woul hang everything up (as OSCLI won’t return as the buffer will be full). Probably sticking a temporary file in !Scrap is the simplest bet. Note, by the way, that OS redirected output ( Edit: I see Stuart wrote a much shorter reply. ;-) It wasn’t there when I began writing this! |
Rick Murray (539) 13851 posts |
It’s a shame PipeFS can’t dynamically allocate space for what wants to be written (within reason!). |
Chris Johns (8262) 242 posts |
If you’re running in the desktop you could use a TaskWindow to do the work and capture the output. I’ve even written a module to help with that, which I need to do a proper release of :) |
David Feugey (2125) 2709 posts |
Where is it? Where is it? |
Chris Johns (8262) 242 posts |
I’ve shoved it on the interwebs here – http://cmj.orgfree.com/TaskRunner/index.html |
David Feugey (2125) 2709 posts |
Thanks Chris. I’ll need to make some tests on real hardware, as the demo simply block RPCEmu. |
Chris Johns (8262) 242 posts |
Ah, yes I forgot to say – you need run the demo in a TaskWindow, otherwise it will hang waiting for the task to run, which it won’t do because the system is waiting for it to run…. |