• 8586阅读
  • 1回复

请问如何在Qt自带的sqlite中执行.import语句? [复制链接]

上一主题 下一主题
离线mpfishere
 
只看楼主 倒序阅读 楼主  发表于: 2010-09-05
— 本帖被 XChinux 从 General Qt Programming 移动到本区(2011-01-02) —
SQLite3定义了一些非常有用的语句,如.separator,.import等等。
但我在调用QSqlQuery(const QString &query)时,参数query只能为基本的SQL语句,请问怎么才能让它执行像.import这种语句呢?
我查了Qt手册,里边是这样写的:
“The query string must use syntax appropriate for the SQL database being queried, for example, standard SQL. ”
如果我没有理解错的话,它的意思应该是说query的语句取决于要查询的数据库是否支持,这样的话,SQLite应该支持像.import这样的查询。
请知道的人帮帮忙吧,谢谢!!:)
离线guitarfeng
只看该作者 1楼 发表于: 2011-03-17
我也遇到同样问题,官网有解决方案
createtable的时候直接导入
http://www.sqlite.org/cvstrac/wiki?p=ImportingFiles


==============================================================
Import using a virtual table

The attached file csvfile.zip includes an implementation of a virtual table to read CSV files.

It needs to be compiled as an sqlite extension and loaded using the ".load" mechanism.

Then use it like this:

  CREATE VIRTUAL TABLE [<database>.]<table_name>
        USING CSVFILE( ?file? [, <charset> [, <delims>] ] );

    * <charset> is the character set name to pass to iconv(). The default character set is "CP1252" (Windows Western Europe).

    * <delims> is a string where the first character is the csv file field delimiter and the second character is the string delimiter. The default field delimiter is the ";" character and the default string delimiter is the "\"" character.

You may need to tweak the code for your system.

Correction for attachment csvmbpg.tgz: In file virtual_csvmbpg.c:

  char charset[32] = "ISO-8859-1";

instead of

  char charset[32] = "";
快速回复
限100 字节
 
上一个 下一个