Skip to content

Commit 7bfc8e6

Browse files
committed
JSON operators pushing down implementation + new SQLite err codes
1 parent fe112d6 commit 7bfc8e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+5462
-142
lines changed

.github/workflows/CI.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- main
1010
jobs:
1111
detect-pgversion:
12-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-24.04
1313
outputs:
1414
pgversion: ${{ steps.detect-pgversion.outputs.targets }}
1515
steps:
@@ -36,7 +36,7 @@ jobs:
3636
config: ["default", "postgis"]
3737

3838
name: Test on PostgreSQL ${{ matrix.pg }}, ${{ matrix.config }} mode
39-
runs-on: ubuntu-22.04
39+
runs-on: ubuntu-24.04
4040
steps:
4141
- uses: actions/checkout@v4
4242

@@ -46,10 +46,16 @@ jobs:
4646
- name: set_proxy
4747
run: bash GitHubActions/env.sh
4848

49+
- name: download PostGIS, ${{ matrix.config }} mode
50+
run: |
51+
if [[ "${{ matrix.config }}" == "postgis" ]]; then
52+
bash GitHubActions/download_postgis.sh ${{ env.POSTGIS_VERSION }}
53+
fi
54+
4955
- name: install locales
5056
run: bash GitHubActions/install_locales.sh
5157

52-
- name: build PostgreSQL ${{ matrix.pg }} with ${{ matrix.config }}
58+
- name: build PostgreSQL ${{ matrix.pg }}
5359
run: bash GitHubActions/build_postgres.sh ${{ matrix.pg }}
5460

5561
- name: build PostGIS ${{ env.POSTGIS_VERSION }} for PostgreSQL ${{ matrix.pg }}, ${{ matrix.config }} mode
@@ -83,3 +89,4 @@ jobs:
8389
workdir/postgresql-${{ matrix.pg }}/contrib/sqlite_fdw/regression.out
8490
workdir/postgresql-${{ matrix.pg }}/contrib/sqlite_fdw/results
8591
retention-days: 7
92+

GitHubActions/build_postgis.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
################################################################################
44
#
5-
# This script downloads PostgreSQL from the official web site into ./workdir
5+
# This script downloads PostGIS from the official web site into ./workdir
66
# then builds it.
77
#
88
# Usage: ./build_postgis.sh pg_version postgis_version
@@ -17,23 +17,18 @@
1717
POSTGRESQL_VERSION=$1
1818
POSTGIS_VERSION=$2
1919

20-
cd ./workdir
21-
cd postgresql-${POSTGRESQL_VERSION}
22-
2320
# Install necessary dependencies
2421
sudo apt update
2522
sudo apt install -y build-essential libxml2-dev libgeos-dev libproj-dev libgdal-dev libjson-c-dev libprotobuf-c-dev protobuf-c-compiler
2623

27-
GEOS_CONFIG_PATH=$(which geos-config)
28-
24+
cd ./workdir
2925
# Download and compile PostGIS
30-
cd contrib
31-
wget http://download.osgeo.org/postgis/source/postgis-${POSTGIS_VERSION}.tar.gz
32-
tar -xzf postgis-${POSTGIS_VERSION}.tar.gz
33-
mv postgis-${POSTGIS_VERSION} postgis -v
34-
cd postgis
26+
cp -vr postgis postgresql-${POSTGRESQL_VERSION}/contrib
27+
cd postgresql-${POSTGRESQL_VERSION}/contrib/postgis
3528
echo " - PostGIS directory"
29+
GEOS_CONFIG_PATH=$(which geos-config)
3630
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
3731
./configure --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=$GEOS_CONFIG_PATH
3832
make
3933
sudo make install
34+

GitHubActions/build_sqlite_fdw.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@ VERSION="$1"
1818
MODE="$2"
1919

2020
mkdir -p ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw
21-
tar zxvf ./sqlite_fdw.tar.gz -C ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw/
21+
tar zxf ./sqlite_fdw.tar.gz -C ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw/
2222
cd ./workdir/postgresql-${VERSION}/contrib/sqlite_fdw
23-
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
23+
24+
# show locally compiled sqlite library
25+
ls -la /usr/local/lib
2426

2527
if [ "$MODE" == "postgis" ]; then
26-
make ENABLE_GIS=1
28+
make CI_ENV=1 ENABLE_GIS=1
2729
else
28-
make
30+
make CI_ENV=1
2931
fi
3032

3133
sudo make install

GitHubActions/download_postgis.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
################################################################################
4+
#
5+
# This script downloads PostGIS from the official web site into ./workdir
6+
# then builds it.
7+
#
8+
# Usage: ./download_postgis.sh postgis_version
9+
# postgis_version is a PostGIS version to be installed.
10+
#
11+
# Requirements
12+
# - be able to connect to the PostGIS official web site by wget.
13+
#
14+
################################################################################
15+
16+
POSTGIS_VERSION=$1
17+
18+
mkdir -p ./workdir
19+
cd ./workdir
20+
pgisfile="postgis-${POSTGIS_VERSION}.tar.gz"
21+
if [ ! -f "$pgisfile" ]; then
22+
wget -nv "http://download.osgeo.org/postgis/source/$pgisfile"
23+
tar -xzf "$pgisfile"
24+
mv postgis-${POSTGIS_VERSION} postgis -v
25+
echo "PostGIS source code directory " $(dirname $(readlink -f postgis))
26+
else
27+
echo "PostGIS downloaded"
28+
fi

GitHubActions/install_locales.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ sudo apt-get install locales language-pack-ja
1717
sudo locale-gen ja_JP.EUC-JP
1818
sudo apt-get install language-pack-ko-base language-pack-ko
1919
sudo locale-gen ko_KR.EUC-KR
20-
sudo apt -get install language-pack-bg-base language-pack-bg
20+
sudo apt-get install language-pack-bg-base language-pack-bg
2121
sudo locale-gen bg_BG
22+
sudo apt-get install libreadline8 libreadline-dev

GitHubActions/install_sqlite.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ done
3232

3333
mkdir -p ./workdir
3434
cd ./workdir
35-
curl -O https://www.sqlite.org/${YEAR}/sqlite-src-${VERSION}.zip
36-
unzip sqlite-src-${VERSION}.zip > /dev/null
37-
cd sqlite-src-${VERSION}
38-
39-
if [ -z "$CONFIGURE_OPTIONS" ]; then
40-
./configure --enable-fts5
41-
else
42-
./configure --enable-fts5 $CONFIGURE_OPTIONS
35+
vsrc="sqlite-src-${VERSION}"
36+
adr="https://www.sqlite.org/${YEAR}/$vsrc.zip"
37+
echo "SQLite source code archive: $adr"
38+
curl -O "$adr"
39+
unzip "$vsrc.zip" > /dev/null
40+
cd "$vsrc"
41+
42+
confcom="./configure --enable-fts5"
43+
if [ ! -z "$CONFIGURE_OPTIONS" ]; then
44+
confcom+="$CONFIGURE_OPTIONS"
4345
fi
46+
echo "SQLite configure call: $confcom"
47+
$confcom
4448

4549
make
4650
sudo make install

Makefile

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,29 @@ OBJS = connection.o option.o deparse.o sqlite_query.o sqlite_fdw.o sqlite_data_n
1515
EXTENSION = sqlite_fdw
1616
DATA = sqlite_fdw--1.0.sql sqlite_fdw--1.0--1.1.sql
1717

18+
# Use local downloaded and compiled SQLite library instead of system
19+
ifdef CI_ENV
20+
override PG_LDFLAGS += -L/usr/local/lib
21+
endif
22+
1823
ifdef ENABLE_GIS
1924
override PG_CFLAGS += -DSQLITE_FDW_GIS_ENABLE
20-
GISTEST=postgis
25+
GISTEST = postgis
2126
else
22-
GISTEST=nogis
27+
GISTEST = nogis
2328
endif
2429

30+
# Tests for PostgreSQL data types support
31+
TYPETESTS = types/bitstring types/bool types/float4 types/float8 types/int4 types/int8 types/json types/numeric types/$(GISTEST) types/macaddr types/macaddr8 types/out_of_range types/timestamp types/uuid
32+
2533
ifndef REGRESS
26-
REGRESS = extra/sqlite_fdw_post types/bitstring types/bool types/float4 types/float8 types/int4 types/int8 types/numeric types/$(GISTEST) types/macaddr types/macaddr8 types/out_of_range types/timestamp types/uuid extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/encodings sqlite_fdw type_$(GISTEST) aggregate selectfunc
34+
# System tests, full default sequence
35+
REGRESS = extra/sqlite_fdw_post $(TYPETESTS) extra/join extra/limit extra/aggregates extra/prepare extra/select_having extra/select extra/insert extra/update extra/encodings sqlite_fdw type_$(GISTEST) aggregate selectfunc
2736
endif
2837

38+
# Other encodings also sre tested. Client encoding should be UTF-8-
2939
REGRESS_OPTS = --encoding=utf8
3040

31-
SQLITE_LIB = sqlite3
32-
3341
UNAME = uname
3442
OS := $(shell $(UNAME))
3543
ifeq ($(OS), Darwin)
@@ -71,8 +79,17 @@ REGRESS := $(addprefix $(REGRESS_PREFIX_SUB)/,$(REGRESS))
7179
$(shell mkdir -p results/$(REGRESS_PREFIX_SUB)/extra)
7280
$(shell mkdir -p results/$(REGRESS_PREFIX_SUB)/types)
7381

82+
# $(info ENABLE_GIS is $(ENABLE_GIS))
83+
$(info CI_ENV is $(CI_ENV))
84+
# $(info SHLIB_LINK is $(SHLIB_LINK))
85+
# $(info LD_LIBRARY_PATH is $(LD_LIBRARY_PATH))
86+
$(info PG_CFLAGS is $(PG_CFLAGS))
87+
# $(info REGRESS is $(REGRESS))
88+
# $(info DLSUFFIX is $(DLSUFFIX))
89+
7490
ifdef ENABLE_GIS
7591
check: temp-install
7692
temp-install: EXTRA_INSTALL+=contrib/postgis
7793
checkprep: EXTRA_INSTALL+=contrib/postgis
7894
endif
95+

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ SQLite Foreign Data Wrapper for PostgreSQL
44
This is a foreign data wrapper (FDW) to connect [PostgreSQL](https://www.postgresql.org/)
55
to [SQLite](https://sqlite.org/) database file. This FDW works with PostgreSQL 13, 14, 15, 16, 17 and confirmed with SQLite 3.46.0.
66

7-
<img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" align="center" height="100" alt="PostgreSQL"/> + <img src="https://upload.wikimedia.org/wikipedia/commons/3/38/SQLite370.svg" align="center" height="100" alt="SQLite"/>
7+
<img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" align="center" height="100" alt="PostgreSQL"/> + <img src="SQLite.png" align="center" height="100" alt="SQLite"/>
88

99
Also this foreign data wrapper (FDW) can connect PostgreSQL with [PostGIS](https://www.postgis.net/)
1010
to [SpatiaLite](https://www.gaia-gis.it/fossil/libspatialite/index) SQLite database file. This FDW works with PostGIS 2+ and confirmed with SpatiaLite 5.1. See [GIS support description](GIS.md).

SQLite.png

22.5 KB
Loading

connection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ sqlite_open_db(const char *dbpath, int flags)
199199
ereport(ERROR,
200200
(errcode(ERRCODE_FDW_UNABLE_TO_ESTABLISH_CONNECTION),
201201
errmsg("Failed to open SQLite DB, file '%s', result code %d", dbpath, rc)));
202+
sqlite3_extended_result_codes(conn, true);
202203
/* make 'LIKE' of SQLite case sensitive like PostgreSQL */
203204
rc = sqlite3_exec(conn, "pragma case_sensitive_like=1",
204205
NULL, NULL, &err);

0 commit comments

Comments
 (0)