Hi,

https://picolisp.com/wiki/?RunExe

I optimized the code used in the example I previously added to the wiki. Being
able to pipe 1M inserts into a sqlite db in ~2.5secs from picolisp is all
kinds of awesome.

I also added a link to an additional example:
https://github.com/thinknlive/picolisp-lisp-basics/blob/master/sqlite.l

In the additional example, I have added a couple of functions to quote sql
parameters
and a (just) good enough parser for results returned as json, allowing
reliably correct handling of unicode and escaped characters on inserts and
queries. (see bench code below)

Happy Hacking
/Lindsay


: (bench (let (Sql '(
  ".mode quote"
  "drop table if exists test;"
  "create table test(id integer primary key, name text, cnt int default 1);"
  "create unique index uix_test_name on test(name);"
  ))
  (setq Sql
    (append
      Sql
      '("begin transaction;")
      (make (do 10000 (link (pack
        "insert into test (name) values (" (sqlQuote (makeRndName 4)) ") on
conflict (name) do update set cnt = cnt + 1;"))))
      '("commit;")
      '("select json_array(id, name, cnt, (hex(randomblob(8)))) from test
where cnt > 1;")
      '("select json_array('CollisionCount', count(*)) from test where cnt
> 1;")
      '("select json_array('RecordCount', count(*)) from test;")))
  (bench (mapc '((R) (let (Row (head -2 (nth (chop R) 3))
                           Flds (fldParseQ Row))
                     (prin R " --> ") (print Flds) (prinl  " : " (length
Flds))))
                (car (runExe Sql sqlite3 "testdb.sqlite"))) ]
'[31,"99\\,",2,"0A0427635B128F1B"]' --> ("31" "99\\," "2"
"0A0427635B128F1B") : 4
'[32,"6,👍3",2,"0A15EE4D50BA7DED"]' --> ("32" "6,👍3" "2"
"0A15EE4D50BA7DED") : 4
'[142,"👍238",2,"5FB33CBC8DC3B366"]' --> ("142" "👍238" "2"
"5FB33CBC8DC3B366") : 4
'[266,"CIᘐU",2,"4AB7193F10CEBB55"]' --> ("266" "CIᘐU" "2"
"4AB7193F10CEBB55") : 4
'[472,"\np👍\"",2,"979F6057BCD7C97B"]' --> ("472" "^Jp👍\"" "2"
"979F6057BCD7C97B") : 4
'[990,"\\n👍3",2,"5F3F9E2031EA3C52"]' --> ("990" "\\n👍3" "2"
"5F3F9E2031EA3C52") : 4
'[1546,"\n1,6",2,"0CB9CE64B32AFE6D"]' --> ("1546" "^J1,6" "2"
"0CB9CE64B32AFE6D") : 4
'[1836,",\\5ᘐ",2,"9FD2D32906D5081A"]' --> ("1836" ",\\5ᘐ" "2"
"9FD2D32906D5081A") : 4
'[2188,"8FZ👍",2,"C3D2C1661145BE91"]' --> ("2188" "8FZ👍" "2"
"C3D2C1661145BE91") : 4
'[2239,"\"9ᘐ\"",2,"C61BF491F245F996"]' --> ("2239" "\"9ᘐ\"" "2"
"C61BF491F245F996") : 4
'[3106,",\n2L",2,"C33A015041A908B0"]' --> ("3106" ",^J2L" "2"
"C33A015041A908B0") : 4
'[3731,"\\👍\"9",2,"AD7232A882E4BD03"]' --> ("3731" "\\👍\"9" "2"
"AD7232A882E4BD03") : 4
'[3748,"\n\",\\",2,"700011DF8C20EEED"]' --> ("3748" "^J\",\\" "2"
"700011DF8C20EEED") : 4
'[5288,"3g👍\\",2,"D5F23C683C48CA23"]' --> ("5288" "3g👍\\" "2"
"D5F23C683C48CA23") : 4
'[6579,"\"\"\n,",2,"8C594685D3E210CF"]' --> ("6579" "\"\"^J," "2"
"8C594685D3E210CF") : 4
'["CollisionCount",15]' --> ("CollisionCount" "15") : 2
'["RecordCount",9985]' --> ("RecordCount" "9985") : 2
0.135 sec
0.158 sec
-> 2
:

Reply via email to