Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing CSV to sqlite3 fails due to invalid command-line syntax #482

Open
giladarnold opened this issue Oct 7, 2016 · 5 comments
Open

Comments

@giladarnold
Copy link

When importing a CSV odo invokes sqlite3 with command-line arguments: sqlite3 -nullvalue '' -separator , -cmd '.import "/path/to/csv/file" tablename' /path/to/db/file

However, current sqlite3 (version 3.6.20) does not support a -cmd option. Instead, the invocation should look like this: sqlite3 -nullvalue '' -separator , /path/to/db/file '.import "/path/to/csv/file" tablename'

I patched odo/backends/sql_csv.py:compile_from_csv_sqlite() accordingly and it works like a charm. Happy to submit the patch if that'll speed things up. Please advise, thanks!

@kwmsmith
Copy link
Member

kwmsmith commented Oct 7, 2016

@giladarnold yes, please submit the patch, thanks.

@giladarnold
Copy link
Author

From 064c7f131247bc904fd7144f051f13a76b5caea4 Mon Sep 17 00:00:00 2001
From: Gilad Arnold <[email protected]>
Date: Fri, 7 Oct 2016 15:32:22 -0700
Subject: [PATCH] Fix sqlite CSV import command.

Current sqlite3 binaries do not take a -cmd option. They use positional
arguments instead. This fixes the problem for CSV import.
---
 odo/backends/sql_csv.py |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/odo/backends/sql_csv.py b/odo/backends/sql_csv.py
index d2277e5..307da65 100644
--- a/odo/backends/sql_csv.py
+++ b/odo/backends/sql_csv.py
@@ -85,11 +85,11 @@ def compile_from_csv_sqlite(element, compiler, **kwargs):
     cmd = ['sqlite3',
            '-nullvalue', repr(element.na_value),
            '-separator', element.delimiter,
-           '-cmd', '.import "%s" %s' % (
+           element.bind.url.database,
+           '.import "%s" %s' % (
                # FIXME: format_table(t) is correct, but sqlite will complain
                fullpath, compiler.preparer.format_table(t)
-           ),
-           element.bind.url.database]
+           )]
     stderr = subprocess.check_output(
         cmd,
         stderr=subprocess.STDOUT,
-- 
1.7.1

@giladarnold
Copy link
Author

@kwmsmith this looks okay?

@giladarnold
Copy link
Author

Created pull request: #488

@rand-Mal-Function
Copy link

I Just got it working by replacing the filename with pandas.read_csv(filename)
example :
db = odo(pandas.read_csv(filename) , "sqlite:///mydb.db::tablename" , dshape=dshape)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants