Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor data conversion errors and diagnostics, tests, headers and test data directory #91

Merged
merged 19 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,19 @@ SQLite `NULL` affinity always can be transparent converted for a nullable column
- **database** as *string*, **required**, no default

SQLite database path.

- **updatable** as *boolean*, optional, default *true*

This option allow or disallow write operations on SQLite database file.

- **truncatable** as *boolean*, optional, default *true*

Allows foreign tables to be truncated using the `TRUNCATE` command.

- **keep_connections** as *boolean*, optional, default *true*

Allows to keep connections to SQLite while there is no SQL operations between PostgreSQL and SQLite.

- **batch_size** as *integer*, optional, default *1*

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

- **truncatable** as *boolean*, optional, default from the same `CREATE SERVER` option

See `CREATE SERVER` options section for details.

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

See `CREATE SERVER` options section for details.

- **updatable** as *boolean*, optional, default *true*

This option can allow or disallow write operations on a SQLite table independed of the same server option.

`sqlite_fdw` accepts the following column-level options via the
`CREATE FOREIGN TABLE` command:

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

Set preferred SQLite affinity for some PostgreSQL data types can be stored in different ways
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`.

- Use `INT` value for SQLite column (epoch Unix Time) to be treated/visualized as `timestamp` in PostgreSQL.
- Use `BLOB` value for SQLite column to be treated/visualized as `uuid` in PostgreSQL 14+.

Expand Down Expand Up @@ -327,7 +327,7 @@ with names composed from ASCII base latin letters *only*.
CREATE TABLE T_dia (
"Ä" INTEGER,
"ä" NUMERIC
);
);
```

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

```sql
Expand Down Expand Up @@ -586,6 +586,8 @@ You can execute test by test.sh directly.
The version of PostgreSQL is detected automatically by $(VERSION) variable in Makefile.
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.

Test data directory is `/tmp/sqlite_fdw_test`. If you have `/tmp` mounted as `tmpfs` the tests will be up to 800% faster.

Contributing
------------

Expand Down
17 changes: 6 additions & 11 deletions connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@
*/

#include "postgres.h"

#include "sqlite_fdw.h"

#include "access/xact.h"
#include "mb/pg_wchar.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "utils/hsearch.h"
#include "commands/defrem.h"
#if (PG_VERSION_NUM >= 140000 && PG_VERSION_NUM < 150000)
#include "miscadmin.h"
#endif
#include "optimizer/cost.h"
#include "utils/builtins.h"
#include "utils/inval.h"
#include "utils/memutils.h"
#include "utils/resowner.h"
#include "utils/syscache.h"
#include "utils/builtins.h"
#include "commands/defrem.h"

/* Length of host */
#define HOST_LEN 256

/*
* Connection cache hash table entry
Expand Down
18 changes: 5 additions & 13 deletions deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,29 @@
*/

#include "postgres.h"

#include "sqlite_fdw.h"

#include "pgtime.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/sysattr.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_operator.h"
#include "catalog/pg_opfamily.h"
#include "catalog/pg_proc.h"
#if PG_VERSION_NUM >= 160000
#include "catalog/pg_ts_config.h"
#include "catalog/pg_ts_config.h"
#endif
#include "catalog/pg_ts_dict.h"
#include "catalog/pg_type.h"
#if (PG_VERSION_NUM < 130000)
#include "catalog/pg_type.h"
#endif
#include "commands/defrem.h"
#include "mb/pg_wchar.h"
#include "nodes/nodeFuncs.h"
#include "nodes/plannodes.h"
#include "optimizer/clauses.h"
#include "optimizer/tlist.h"
#include "parser/parsetree.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/timestamp.h"
#include "utils/typcache.h"
#include "commands/tablecmds.h"
#include "mb/pg_wchar.h"

/*
* Global context for sqlite_foreign_expr_walker's search of an expression tree.
Expand Down
4 changes: 2 additions & 2 deletions expected/12.16/aggregate.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
CREATE EXTENSION sqlite_fdw;
--Testcase 17:
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
OPTIONS (database '/tmp/sqlitefdw_test.db');
OPTIONS (database '/tmp/sqlite_fdw_test/common.db');
--Testcase 18:
CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr;
-- test for aggregate pushdown
Expand All @@ -17,7 +17,7 @@ DROP EXTENSION IF EXISTS sqlite_fdw CASCADE;
CREATE EXTENSION sqlite_fdw;
--Testcase 11:
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
OPTIONS (database '/tmp/sqlitefdw_test.db');
OPTIONS (database '/tmp/sqlite_fdw_test/common.db');
--Testcase 12:
CREATE FOREIGN TABLE multiprimary(a int, b int OPTIONS (key 'true'), c int OPTIONS(key 'true')) SERVER sqlite_svr;
--Testcase 1:
Expand Down
2 changes: 1 addition & 1 deletion expected/12.16/extra/aggregates.out
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
CREATE EXTENSION sqlite_fdw;
--Testcase 267:
CREATE SERVER sqlite_svr FOREIGN DATA WRAPPER sqlite_fdw
OPTIONS (database '/tmp/sqlitefdw_test_core.db');
OPTIONS (database '/tmp/sqlite_fdw_test/core.db');
--Testcase 268:
CREATE FOREIGN TABLE onek(
unique1 int4 OPTIONS (key 'true'),
Expand Down
Loading