最近接了个美国的小项目,主要需求是把盘点机导出的数据(DBF格式)和另外的数据(csv格式)合并生成新的数据表,方便查询纠错。对方没有安装ms Access,考虑到对方使用方便,就采用了sqlite,开发语言使用.net 2.0。 下面简单罗列下用过程中的几点体会。

Provider:通过使用其他开源软件的体会和网上搜索,Provider决定使用System.Data.SQLite

 

事务(DbTransaction):因为涉及数据导入合并,批量插入和更新等工作是必须的了,一开始没有显式调用事务,速度别提多慢,于是想当然觉得sqlite速度比access还慢,后来搜索发现,原来SQLite 缺省为每个操作启动一个事务,其实这是数据库操作的基本常识,不仅仅Sqlite需要注意这些,当然Access等不支持事务的不在此列。

索引(index):数据导入合并,插入和更新时都需要查询数据是否有重复以及存在,所以索引是不可以缺少的。

SQLiteParameter:批量插入的时候,为了省懒事,使用string.format来格式化插入,结果碰到“near "s": syntex error.”,经过跟踪,原来是单引号(')的问题,看来还是乖乖使用SQLiteParameter来规范地导入,并可以避免很多字符上的问题。

Update ...From(Cross Join in Update):Sqlite 不支持类似

UPDATE tbl1 SET col2 = tbl2.col2
FROM table1 tbl1 INNER JOIN table2 tbl2 ON tbl1.col1 = tbl2.col1

的update,替代的解决办法是:

UPDATE table1 SET col2 = (select col2 from table2 where table2.col1=table1.col1 limit 1)

where exists(select * from table2 where table2.col1=table1.col1); 

查询分析器:我选择SQLite Administrator,后来发现Firefox的插件(addons) Sqlite Manager也是不错的选择。

下面顺便列些和DotNet开发的和SQLite有关的项目:

Convert SQL Server DB to SQLite DB:C# utility to automatically do the conversion from SQL Server DB to SQLite DB(一个把ms SQL Server数据库自动转为SQLite DB的工具,包括源代码)。

SQLite Membership, Role, and Profile Providers:Complete, production-ready Membership, Role, and Profile providers for SQLite. Includes instructions for migrating data between SQL Server and SQLite.




posted on 2009-02-15 20:34  RubyPDF  阅读(11302)  评论(37编辑  收藏  举报