如何自动化与sqlite3.exe命令行工具的过程? [英] How to automate a process with the sqlite3.exe command line tool?
问题描述
我想批量大量的数据(550万行)加载到SQLite数据库文件。
通过加载的INSERT似乎是太慢,所以我尝试使用sqlite3的命令行工具和.IMPORT命令。
I'm trying to bulk load a lot of data ( 5.5 million rows ) into an SQLite database file. Loading via INSERTs seems to be far too slow, so I'm trying to use the sqlite3 command line tool and the .import command.
它完美,如果我手工输入命令,但我不能为我的生活工作如何从一个脚本自动(.bat文件或python脚本;我正在Windows机器上)
It works perfectly if I enter the commands by hand, but I can't for the life of me work out how to automate it from a script ( .bat file or python script; I'm working on a Windows machine ).
我在命令行发出的命令有这些:
The commands I issue at the command line are these:
> sqlite3 database.db
sqlite> CREATE TABLE log_entry ( <snip> );
sqlite> .separator "\t"
sqlite> .import logfile.log log_entry
但没有我尝试将得到这个从一个bat文件或Python脚本工作。
But nothing I try will get this to work from a bat file or python script.
我一直在努力的事情,如:
I've been trying things like:
sqlite3 "database.db" .separator "\t" .import logfile.log log_entry
echo '.separator "\t" .import logfile.log log_entry' | sqlite3 database.db
当然,我可以以某种方式做到这一点?
Surely I can do this somehow?
推荐答案
与您要进入sqlite的命令行程序的线条,像这样创建一个文本文件:
Create a text file with the lines you want to enter into the sqlite command line program, like this:
CREATE TABLE log_entry ( );
.separator "\t"
.import logfile.log log_entry
然后就叫 sqlite3的database.db&LT; commands.txt中
这篇关于如何自动化与sqlite3.exe命令行工具的过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!