dblite
dblite copied to clipboard
Some .mode states not working
Seems to be a problem with setting the .mode and getting file output from the db unless I am missing something simple ....
MacOS 10.13.6 High Sierra Test Versions: dblite 1.0.1 sqlite 3.19.3 2017-06-27 16:48:08 (system install - usr/bin) sqlite3-tools-osx 3.27.2 2019-02-25 16:06:06 (app standalone) nwjs 0.37.1-sdk (node 11.11.0) nwjs 0.33.4-sdk (node 10.11.0) nwjs 0.19.6-sdk (node 7.4.0)
The code below is from dbcontrol.js and the dblite.bin is set for default (system install of sqlite). If I try the .dump and the save to csv via the Terminal using the same system install everything works fine
Test 1: Try to dump db to .sql file L293 ~ 295 - result is dumpo.sql file is produced but only contains the MagicNumber (eg: ---W8m6W0zRbPJz7VcaHszdnJA/CZsPeOWzaX7xrD87lzoqM7/OT0WuS9+y933s87Il5YlqHJMkI76fxDcHFcCqVg==---)
I tried setting the mode to ascii since the .dump is an ascii dump but no file is produced and the ascii setting doesn't appear to work. The .sql file is only produced if the .mode is set for column/line/list/tabs (tabs will set list) - all the other mode values (ascii/csv/html/insert/quote/tcl) do not seem to work and the following .show (L289) will not be captured via info filter.
Test 2: Try to save to .csv file L303 ~ 322 - csv mode setting doesn't appear to work and no file produced. If a workable mode (eg: list) is used then the .csv is produced but only contains the Magic Numbers.
288 db.query('.mode line');
289 db.query('.show');
290
291 // var newDb = 'Hippowaddler.db';
292 //sqlite3 music.db .dump > music.sql
293 var dumpPath = 'dumpo.sql';
294 db.query('.output ' + dumpPath);
295 db.query('.dump');
296
297 //db.query('.binary off');
298
299
300 // *****************************************************************************
301 // Save to csv file test
302
303 var csvPath = process.cwd() + '/hippo.csv';
304 db.query('.headers on');
305
306 //db.query('.mode ascii'); // FAILS
307 //db.query('.mode column'); // OK
308 db.query('.mode csv'); // FAILS
309 //db.query('.mode html'); // FAILS
310 //db.query('.mode insert'); // FAILS
311 //db.query('.mode line'); // OK
312 //db.query('.mode list'); // OK
313 //db.query('.mode quote'); // FAILS
314 //db.query('.mode tabs'); // sets as list
315 //db.query('.mode tcl'); // FAILS
316
317 db.query('.once ' + csvPath);
318
319 //db.query('.output ' + csvPath);
320
321 //db.query('SELECT * FROM playlists', ['playlistid', 'name']);
322 db.query('SELECT * FROM playlists');
323
324 db.query('.show');
Test app if required attached minus nwjs binary
For nwjs just download/unzip and plonk nwjs.app into the test app folder alongside package.json - double-click to run http://dl.nwjs.io/live-build/nw37/03-20-2019/b2357a9d6/v0.37.1/
Cheers
not sure I understand what you are doing, or why I would need another env to test a bug, but I can tell you I have pretty much zero time for this now, so if you find a way to reproduce on Mac or Linux and you provide an easy test case, I might investigate whenever I find time, otherwise feel free to file a PR if you find the issue.
This project is meant to do simple things, through a shell wrap, and some I/O operation.
OK, thanks - I'll try and figure out the .mode csv and .sql dump somehow. Update: Looks like some of the .mode settings don't work because of truncation after slicing. With the modes that do work then .clone works well but .once/.output to csv files and .dump to .sql don't complete.
Tested: 3.19.3 and 3.27.2
.mode list
STDIN STR .clone hippo.db (file is perfect) SELECT "---Ql/Ql3YslCKbALRIhjCy6XSGDXkTULfP1HgmhiTvhVuHmHAQBKmRCFrfkELKggRFtHo+VEWXkAKuL/WfD1tmxA==---" AS "---Ql/Ql3YslCKbALRIhjCy6XSGDXkTULfP1HgmhiTvhVuHmHAQBKmRCFrfkELKggRFtHo+VEWXkAKuL/WfD1tmxA==---"; STR-length 259 STDOUT-data playlists... .... etc
STDIN STR .output hippo.csv (file exists but only contains SUPER_SECRET value) SELECT "---Ql/Ql3YslCKbALRIhjCy6XSGDXkTULfP1HgmhiTvhVuHmHAQBKmRCFrfkELKggRFtHo+VEWXkAKuL/WfD1tmxA==---" AS "---Ql/Ql3YslCKbALRIhjCy6XSGDXkTULfP1HgmhiTvhVuHmHAQBKmRCFrfkELKggRFtHo+VEWXkAKuL/WfD1tmxA==---"; STR-length 100 code stops
282 if (selectResult.slice(SUPER_SECRET_LENGTH) === SUPER_SECRET) {
With .mode list line 282 works OK and code progresses to allow .clone and .output to produce files. The clone will work OK but the csv file will only contain the supersecret value.
With .mode csv line 282 does not equate and on inspection the value for selectResult.slice(SUPER_SECRET_LENGTH) is truncated at the start, progress will cease with no files produced. If the value for selectResult.slice(SUPER_SECRET_LENGTH) is adjusted (using substring/trim) so the statement equates then the code will progress and produce the files with the same results as for .mode list
The same slicing issue with selectResult.slice(SUPER_SECRET_LENGTH) also causes .mode ascii/html/insert/quote/tcl to fail.
So - .clone works well using .mode column/line/list/tabs - slicing issue at 282 prevents other modes from working.
unable to use .output or .once to csv file unable to .dump to .sql file
Normal create/read/write etc to db work great and far easier than trying to get sqlite3 going directly.