如何编译sqlite3扩展-CSV虚拟表 [英] How to compile sqlite3 extension - CSV virtual table

查看:218
本文介绍了如何编译sqlite3扩展-CSV虚拟表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为sqlite3使用 CSV虚拟表扩展名。我陷入了在Mac(MacOS High Sierra 10.13.6)上编译扩展的第一步。

I am trying to use the CSV Virtual Table extension for sqlite3. I get stuck on the first step of compiling the extension on a Mac (MacOS High Sierra 10.13.6).

我从此页面。我还从此处中获取了sqlite源代码合并。

I downloaded the source code for csv.c from this page. I also grabbed the sqlite source code amalgamation from here.

我使用以下命令进行编译:

I used the following command to compile:

gcc -g -fPIC -dynamiclib csv.c -o csv.dylib

但是,出现以下错误:

csv.c:115:3: error: no member named '__builtin___vsnprintf_chk' in 'struct sqlite3_api_routines'
  sqlite3_vsnprintf(CSV_MXERR, p->zErr, zFormat, ap);
  ^~~~~~~~~~~~~~~~~
/usr/include/sqlite3ext.h:437:53: note: expanded from macro 'sqlite3_vsnprintf'
#define sqlite3_vsnprintf              sqlite3_api->vsnprintf
                                       ~~~~~~~~~~~  ^
/usr/include/secure/_stdio.h:75:3: note: expanded from macro 'vsnprintf'
  __builtin___vsnprintf_chk (str, len, 0, __darwin_obsz(str), format, ap)
  ^
csv.c:115:21: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'const void *' [-Wint-conversion]
  sqlite3_vsnprintf(CSV_MXERR, p->zErr, zFormat, ap);
                    ^~~~~~~~~
csv.c:67:19: note: expanded from macro 'CSV_MXERR'
#define CSV_MXERR 200
                  ^~~
/usr/include/secure/_stdio.h:75:57: note: expanded from macro 'vsnprintf'
  __builtin___vsnprintf_chk (str, len, 0, __darwin_obsz(str), format, ap)
                                                        ^~~
/usr/include/secure/_common.h:39:54: note: expanded from macro '__darwin_obsz'
#define __darwin_obsz(object) __builtin_object_size (object, _USE_FORTIFY_LEVEL > 1 ? 1 : 0)
                                                     ^~~~~~
csv.c:568:5: error: use of undeclared identifier 'sqlite3_str'
    sqlite3_str *pStr = sqlite3_str_new(0);
    ^
csv.c:568:18: error: use of undeclared identifier 'pStr'
    sqlite3_str *pStr = sqlite3_str_new(0);
                 ^
csv.c:568:25: warning: implicit declaration of function 'sqlite3_str_new' is invalid in C99 [-Wimplicit-function-declaration]
    sqlite3_str *pStr = sqlite3_str_new(0);
                        ^
csv.c:571:5: warning: implicit declaration of function 'sqlite3_str_appendf' is invalid in C99 [-Wimplicit-function-declaration]
    sqlite3_str_appendf(pStr, "CREATE TABLE x(");
    ^
csv.c:571:25: error: use of undeclared identifier 'pStr'
    sqlite3_str_appendf(pStr, "CREATE TABLE x(");
                        ^
csv.c:581:29: error: use of undeclared identifier 'pStr'
        sqlite3_str_appendf(pStr, "%sc%d TEXT", zSep, iCol);
                            ^
csv.c:588:31: error: use of undeclared identifier 'pStr'
          sqlite3_str_appendf(pStr,"%s\"%w\" TEXT", zSep, z);
                              ^
csv.c:597:31: error: use of undeclared identifier 'pStr'
          sqlite3_str_appendf(pStr,"%sc%d TEXT", zSep, ++iCol);
                              ^
csv.c:603:25: error: use of undeclared identifier 'pStr'
    sqlite3_str_appendf(pStr, ")");
                        ^
csv.c:604:18: warning: implicit declaration of function 'sqlite3_str_finish' is invalid in C99 [-Wimplicit-function-declaration]
    CSV_SCHEMA = sqlite3_str_finish(pStr);
                 ^
csv.c:604:37: error: use of undeclared identifier 'pStr'
    CSV_SCHEMA = sqlite3_str_finish(pStr);
                                    ^
csv.c:643:27: error: use of undeclared identifier 'SQLITE_VTAB_DIRECTONLY'
  sqlite3_vtab_config(db, SQLITE_VTAB_DIRECTONLY);
                          ^
4 warnings and 10 errors generated.

我在做什么错了?

推荐答案

Richard Hipp在sqlite.org 发布了解决方案有关如何编译SQLite扩展。

Richard Hipp at sqlite.org posted a solution on how to compile an SQLite extension.

用于编译CSV扩展的脚本如下所示(基于 https://www.sqlite.org/loadext.html https://github.com/sqlite/sqlite/blob/master/README.md ):

The script for compiling the CSV extension looks like this (based on https://www.sqlite.org/loadext.html and https://github.com/sqlite/sqlite/blob/master/README.md):

wget https://www.sqlite.org/src/tarball/sqlite.tar.gz
tar xzf sqlite.tar.gz
mkdir bld
cd bld
../sqlite/configure
make
gcc -g -I. -fPIC -dynamiclib ../sqlite/ext/misc/csv.c -o csv.dylib

测试脚本:

echo -e 'col_text,col_int\napples,3\noranges,5' > sample.csv
./sqlite3 '' '.load csv' 'CREATE VIRTUAL TABLE temp.t1 USING csv(filename="sample.csv");' 'SELECT * FROM t1;'

就是这样。

您也可以尝试编译 csv.c 和现有的 sqlite3 安装。对于与Homebrew一起安装的 sqlite3 ,它将是:

You can also try compiling csv.c with an existing sqlite3 installation. For sqlite3 installed with Homebrew, it would be:

curl -O https://raw.githubusercontent.com/sqlite/sqlite/master/ext/misc/csv.c
gcc -g -I/usr/local/opt/sqlite/include -fPIC -dynamiclib csv.c -o csv.dylib
/usr/local/opt/sqlite/bin/sqlite3 '' '.load csv'

最后一行正在测试Homebrew sqlite3 中新编译的库。默认的 $ sqlite3 来自MacOS捆绑软件,有时会过时。

The last line is testing the newly compiled library in the Homebrew sqlite3. The default $ sqlite3 comes from the MacOS bundle and is outdated sometimes.

这篇关于如何编译sqlite3扩展-CSV虚拟表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆