问题描述
在Mac上,我有一个包含两列的txt文件,一列是sqlite表中的自动增量:
On a Mac, I have a txt file with two columns, one being an autoincrement in an sqlite table:
, "mytext1"
, "mytext2"
, "mytext3"
当我尝试导入此文件,我得到一个数据类型不匹配错误:
When I try to import this file, I get a datatype mismatch error:
.separator ","
.import mytextfile.txt mytable
如何构造txt文件以便它使用自动增量?
How should the txt file be structured so that it uses the autoincrement?
另外,如何输入会有换行符的文字?例如:
Also, how do I enter in text that will have line breaks? For example:
"this is a description of the code below.
The text might have some line breaks and indents. Here's
the related code sample:
foreach (int i = 0; i < 5; i++){
//do some stuff here
}
this is a little more follow up text."
我需要将上面插入一行。我需要对格式化做些什么特别的事情吗?
I need the above inserted into one row. Is there anything special I need to do to the formatting?
对于一个特定的表,我希望每行都作为一个文件并以这种方式导入它们。我猜这是创建某种运行多个导入的批处理文件的问题。
For one particular table, I want each of my rows as a file and import them that way. I'm guessing it is a matter of creating some sort of batch file that runs multiple imports.
编辑
这正是我发布的语法,减去了一个标签,因为我使用的是逗号。我的帖子中缺少的换行符并没有表现得那么明显。无论如何,这给出了不匹配错误。
That's exactly the syntax I posted, minus a tab since I'm using a comma. The missing line break in my post didn't make it as apparent. Anyways, that gives the mismatch error.
推荐答案
我正在寻找同样的问题。看起来我找到了一个问题的第一部分 - 关于将文件导入带有ID字段的表格。
I was looking on the same problem. Looks like I've found an answer on the first part of your question — about importing a file into a table with ID field.
所以是的,创建一个没有ID的临时表,将文件导入其中,然后执行insert..select将其数据复制到目标表中。 (从mytextfile.txt中删除前导逗号)。
So yes, create a temporary table without ID, import your file into it, then do insert..select to copy its data into your target table. (Remove leading commas from mytextfile.txt).
-- assuming your table is called Strings and
-- was created like this:
-- create table Strings( ID integer primary key, Code text )
create table StringsImport( Code text );
.import mytextfile.txt StringsImport
insert into Strings ( Code ) select * from StringsImport;
drop table StringsImport;
不知道如何处理换行符。我已经读到一些提到以CSV模式导入将起到作用(.mode csv),但是当我尝试它时似乎没有用。
Do not know what to do with newlines. I've read some mentions that importing in CSV mode will do the trick (.mode csv), but when I tried it did not seem to work.
这篇关于如何将文件导入sqlite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!