Skip to content

Commit 7dd696c

Browse files
authored
Refactor data conversion errors and diagnostics, tests, headers and test data directory (#91)
1 parent a387b2f commit 7dd696c

File tree

249 files changed

+12303
-8201
lines changed

Some content is hidden

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

249 files changed

+12303
-8201
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,19 +167,19 @@ SQLite `NULL` affinity always can be transparent converted for a nullable column
167167
- **database** as *string*, **required**, no default
168168

169169
SQLite database path.
170-
170+
171171
- **updatable** as *boolean*, optional, default *true*
172172

173173
This option allow or disallow write operations on SQLite database file.
174-
174+
175175
- **truncatable** as *boolean*, optional, default *true*
176176

177177
Allows foreign tables to be truncated using the `TRUNCATE` command.
178-
178+
179179
- **keep_connections** as *boolean*, optional, default *true*
180-
180+
181181
Allows to keep connections to SQLite while there is no SQL operations between PostgreSQL and SQLite.
182-
182+
183183
- **batch_size** as *integer*, optional, default *1*
184184

185185
Specifies the number of rows which should be inserted in a single `INSERT` operation. This setting can be overridden for individual tables.
@@ -203,17 +203,17 @@ In OS `sqlite_fdw` works as executed code with permissions of user of PostgreSQL
203203
SQLite table name. Use if not equal to name of foreign table in PostgreSQL. Also see about [identifier case handling](#identifier-case-handling).
204204

205205
- **truncatable** as *boolean*, optional, default from the same `CREATE SERVER` option
206-
206+
207207
See `CREATE SERVER` options section for details.
208208

209209
- **batch_size** as *integer*, optional, default from the same `CREATE SERVER` option
210210

211211
See `CREATE SERVER` options section for details.
212-
212+
213213
- **updatable** as *boolean*, optional, default *true*
214214

215215
This option can allow or disallow write operations on a SQLite table independed of the same server option.
216-
216+
217217
`sqlite_fdw` accepts the following column-level options via the
218218
`CREATE FOREIGN TABLE` command:
219219

@@ -225,7 +225,7 @@ In OS `sqlite_fdw` works as executed code with permissions of user of PostgreSQL
225225

226226
Set preferred SQLite affinity for some PostgreSQL data types can be stored in different ways
227227
in SQLite (mixed affinity case). Updated and inserted values will have this affinity. Default preferred SQLite affinity for `timestamp` and `uuid` PostgreSQL data types is `text`.
228-
228+
229229
- Use `INT` value for SQLite column (epoch Unix Time) to be treated/visualized as `timestamp` in PostgreSQL.
230230
- Use `BLOB` value for SQLite column to be treated/visualized as `uuid` in PostgreSQL 14+.
231231

@@ -327,7 +327,7 @@ with names composed from ASCII base latin letters *only*.
327327
CREATE TABLE T_dia (
328328
"Ä" INTEGER,
329329
"ä" NUMERIC
330-
);
330+
);
331331
```
332332

333333
For SQLite there is no difference between
@@ -340,7 +340,7 @@ For SQLite there is no difference between
340340
```
341341
For PostgreSQL the query with comment `№4` is independend query to table `T`, not to table `t` as other queries.
342342
Please note this table name composed from ASCII base latin letters *only*. This is not applicable for other
343-
alphabet systems or mixed names. This is because `toLower` operation in PostgreSQL is Unicode opration but
343+
alphabet systems or mixed names. This is because `toLower` operation in PostgreSQL is Unicode opration but
344344
ASCII only operation in SQLite, hence other characters will not be changed.
345345

346346
```sql
@@ -586,6 +586,8 @@ You can execute test by test.sh directly.
586586
The version of PostgreSQL is detected automatically by $(VERSION) variable in Makefile.
587587
The corresponding sql and expected directory will be used to compare the result. For example, for Postgres 15.0, you can execute "test.sh" directly, and the sql/15.0 and expected/15.0 will be used to compare automatically.
588588

589+
Test data directory is `/tmp/sqlite_fdw_test`. If you have `/tmp` mounted as `tmpfs` the tests will be up to 800% faster.
590+
589591
Contributing
590592
------------
591593

connection.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@
1111
*/
1212

1313
#include "postgres.h"
14-
1514
#include "sqlite_fdw.h"
1615

1716
#include "access/xact.h"
18-
#include "mb/pg_wchar.h"
19-
#include "funcapi.h"
20-
#include "miscadmin.h"
21-
#include "utils/hsearch.h"
17+
#include "commands/defrem.h"
18+
#if (PG_VERSION_NUM >= 140000 && PG_VERSION_NUM < 150000)
19+
#include "miscadmin.h"
20+
#endif
21+
#include "optimizer/cost.h"
22+
#include "utils/builtins.h"
2223
#include "utils/inval.h"
23-
#include "utils/memutils.h"
24-
#include "utils/resowner.h"
2524
#include "utils/syscache.h"
26-
#include "utils/builtins.h"
27-
#include "commands/defrem.h"
2825

29-
/* Length of host */
30-
#define HOST_LEN 256
3126

3227
/*
3328
* Connection cache hash table entry

deparse.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,29 @@
1111
*/
1212

1313
#include "postgres.h"
14-
1514
#include "sqlite_fdw.h"
1615

17-
#include "pgtime.h"
18-
#include "access/heapam.h"
19-
#include "access/htup_details.h"
20-
#include "access/sysattr.h"
2116
#include "catalog/pg_aggregate.h"
2217
#include "catalog/pg_collation.h"
2318
#include "catalog/pg_namespace.h"
2419
#include "catalog/pg_operator.h"
25-
#include "catalog/pg_opfamily.h"
2620
#include "catalog/pg_proc.h"
2721
#if PG_VERSION_NUM >= 160000
28-
#include "catalog/pg_ts_config.h"
22+
#include "catalog/pg_ts_config.h"
2923
#endif
3024
#include "catalog/pg_ts_dict.h"
31-
#include "catalog/pg_type.h"
25+
#if (PG_VERSION_NUM < 130000)
26+
#include "catalog/pg_type.h"
27+
#endif
3228
#include "commands/defrem.h"
29+
#include "mb/pg_wchar.h"
3330
#include "nodes/nodeFuncs.h"
34-
#include "nodes/plannodes.h"
35-
#include "optimizer/clauses.h"
3631
#include "optimizer/tlist.h"
3732
#include "parser/parsetree.h"
3833
#include "utils/builtins.h"
3934
#include "utils/lsyscache.h"
4035
#include "utils/syscache.h"
41-
#include "utils/timestamp.h"
4236
#include "utils/typcache.h"
43-
#include "commands/tablecmds.h"
44-
#include "mb/pg_wchar.h"
4537

4638
/*
4739
* Global context for sqlite_foreign_expr_walker's search of an expression tree.

expected/12.16/aggregate.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
CREATE EXTENSION sqlite_fdw;
55
--Testcase 17:
66
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
7-
OPTIONS (database '/tmp/sqlitefdw_test.db');
7+
OPTIONS (database '/tmp/sqlite_fdw_test/common.db');
88
--Testcase 18:
99
CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr;
1010
-- test for aggregate pushdown
@@ -17,7 +17,7 @@ DROP EXTENSION IF EXISTS sqlite_fdw CASCADE;
1717
CREATE EXTENSION sqlite_fdw;
1818
--Testcase 11:
1919
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
20-
OPTIONS (database '/tmp/sqlitefdw_test.db');
20+
OPTIONS (database '/tmp/sqlite_fdw_test/common.db');
2121
--Testcase 12:
2222
CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr;
2323
--Testcase 1:

expected/12.16/extra/aggregates.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
CREATE EXTENSION sqlite_fdw;
66
--Testcase 267:
77
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
8-
OPTIONS (database '/tmp/sqlitefdw_test_core.db');
8+
OPTIONS (database '/tmp/sqlite_fdw_test/core.db');
99
--Testcase 268:
1010
CREATE FOREIGN TABLE onek(
1111
unique1 int4 OPTIONS (key 'true'),

0 commit comments

Comments
 (0)