您好,欢迎访问一九零五行业门户网

sqlite加载CSV文件

sqlite加载csv文件 sqlite加载外部的csv文件算是一个比较常见的需求. 假设有一sqlite数据库test.db内有一表名为test.对应sql语句为: create table test (id integer not null,name text not null,phone text not null,primary key (id)); 有一外部csv文件dat
sqlite加载csv文件
sqlite加载外部的csv文件算是一个比较常见的需求.
假设有一sqlite数据库test.db内有一表名为test.对应sql语句为:
create table test (id integer not null,name text not null,phone text not null,primary key (id));
有一外部csv文件data.csv内容如下
5,aaaa,139******
2,bbbb,138******
3,cccc,136******
要把此csv数据弄到数据库test表中有两种方式.
1. 自己解析csv文件,然后把数据逐行insert into 到表内.
因为文件格式其实自己已经知道,所以其实要解析这样的csv文件没什么难度,某些语言(或者某些库)在字符串处理上有spilt就更为方便.
数据可能比较多,不要直接insert into,开启事务节能约不少时间.下面有我写的qt的代码可供参考
[html] qfile file(filepath); if(!file.open(qfile::readonly)) { qdebug() < str; qdebug() <> tmp echo .import data.csv test >> tmp sqlite3.exe test.db 0 然后从外部调用这个批处理即可.
其它类似信息

推荐信息