I'm working on converting a number of CSV files into SQLite3 tables. As of now 
I export the SQL statements to a text file and import them afterwards. 

```
(define (csv->sqlfiles)
  (for-each
   (λ (e)
     (let* ([csv_filepath (string-append csv_dir (path->string e))]
            [table_name (path->string (path-replace-extension e #""))]
            [sql_filepath (string-append sql_dir table_name ".sql")]
            [contents (file->lines csv_filepath #:mode 'text)]
            [columns (length (string-split (first contents) "\t"))]
            [sql-create
             (format "create table ~s ( ~a );"
                     table_name
                     (string-join
                      (map
                       (λ (e) (format "~s text" e))
                       (string-split (first contents) "\t"))
                      ", "))]
            [sql-inserts
             (map
              (λ (e)
                (format "insert into ~s values ( ~a );" table_name
                        (string-join
                         (map (λ (e) (format "~s" e)) (regexp-split #px"\t" e))
                         ",")))
              (list-tail contents 1))]
            [outfile (open-output-file sql_filepath #:exists 'truncate)])
       (displayln sql-create outfile)
       (for-each
        (λ (e)
          (let ()
            (displayln e outfile)))
        sql-inserts)
       (close-output-port outfile)))
   (directory-list csv_dir)))
```

I end up with something looking like this:

```
create table "actionname-e" ( 
        "tag" text, 
        "id" text, 
        "type" text, 
        "category" text, 
        "cat2_cnt" text, 
        "c[0]" text, 
        "c[1]" text, 
        ... );
insert into "actionname-e" values ( 
        "1",
        "0",
        "-1",
        "1",
        "1",
        "-2",
        ...
        ,"a,Sit/Stand\\0","a,icon.action001\\0","a,Toggle Sit/Stand. (/sit, 
/stand)\\0","sitstand" );
```

If I use `.read` from sqlite than it works perfectly fine. When I try to swap 
the file output statements for queries though:


```
       (query-exec sql sql-create)
       (for-each
        (λ (e)
          (let ()
            (query-exec sql e)))
        sql-inserts)))
```

I assume there's a syntax issue but the error being reported is 'multiple 
statements'.

```
query-exec: multiple statements given
  given: "create table \"actionname-e\" ( \"tag\" text, \"id\" text, \"type\" 
text, \"category\" text, \"cat2_cnt\" text, \"c[0]\" text, \"c[1]\" text, 
\"c[2]\" text, \"c[3]\" text, \"c[4]\" text, \"c[5]\" text, \"c[6]\" text, 
\"c[7]\" text, \"c[8]\" text,...
```

I'm not sure though what exactly is going wrong because the statements in the 
file run perfectly fine. I assume racket formats the string in a way but I have 
no way to tell. 


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to