Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

SQLite - Importing .csv data to database every day

So I need to import some .csv file every day in our firm. My idea was to write a .bat file and run it everyday automatically through Task Scheduler. The problem is that i can't succeed at writting .bat file correctly. It's working when I type physically in CMD (sqlite3) but don't do anything when I transform it to .bat file and run it.

CMD:

C:WINDOWSsystem32>sqlite3.exe
SQLite version 3.34.0 2020-12-01 16:14:00
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> ATTACH DATABASE "C:...database.db" AS "name";
sqlite> .mode csv
sqlite> .separator ;
sqlite> .headers on
sqlite> .import "\\path\..." "dbname"
sqlite> SELECT * from "dbname"

The result is the way I want, so all the data is in the database correctly.

Do anyone has an idea how to transform this to a .bat file?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  • Create a text file for the sqlite script
  • The batch file will be something like sqlite3 ":memory:" ".read sqlite.script"

Et voilà! The first argument to sqlite3 is the database name, the following arguments are CLI "executables".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...