0
votes

I am trying to import data from a csv to a sqlite3 database with an id integer primary key. After reading this SO question, I created a temporary table to import 11 columns from a csv file.

The Data:

a||b||c||d||e||f||g||h||i||j||k
l||m||n||o||p||q||r||s||t||u||v

I tried

.separator "||"
.import path/to/table tableName

I get the following error:

Error: path/to/table line 1: expected 11 columns of data but found 21

What am I doing wrong? Should the csv file be formatted differently?

NOTE: The list was built in AppleScript using a method similar to below. Could the echo in bash be causing a problem?

set delim to "||"
set myList to {"a", delim, "b", delim, "c", delim, "d", delim, "e", delim, "f", delim, "g", delim, "h", delim, "i", delim, "j", delim, "k", return, "l", delim, "m", delim, "n", delim, "o", delim, "p", delim, "q", delim, "r", delim, "s", delim, "t", delim, "u", delim, "v", return}
set myList to myList as text
set outPath to POSIX path of (path to desktop as text) & "data.csv"
do shell script "echo " & quoted form of myList & " > " & quoted form of outPath
1
What line separator are you using? - Joachim Isaksson
Is the line separator a sqlite3 options or are you referring to the csv file? - adayzdone
Asking since if the line feed would be removed, there'd be 21 fields. - Joachim Isaksson
Does the additional info posted above help? - adayzdone

1 Answers

1
votes

return (0x0d) by itself does not seem to be a recognised line separator for .import (although it may vary by version since my .import will also only accept single character separators)

Try replacing return with linefeed in your generating AppleScript.