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

Restore bit and varbit support with tests #83

Merged
merged 16 commits into from
Nov 16, 2023
Merged
12 changes: 10 additions & 2 deletions deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2621,8 +2621,16 @@ sqlite_deparse_const(Const *node, deparse_expr_cxt *context, int showtype)
break;
case BITOID:
case VARBITOID:
extval = OidOutputFunctionCall(typoutput, node->constvalue);
appendStringInfo(buf, "B\'%s\'", extval);
{
extval = OidOutputFunctionCall(typoutput, node->constvalue);
if (strlen(extval) > SQLITE_FDW_BIT_DATATYPE_BUF_SIZE - 1 )
{
ereport(ERROR, (errcode(ERRCODE_FDW_INVALID_DATA_TYPE),
errmsg("SQLite FDW dosens't support very long bit/varbit data"),
errhint("bit length %ld, maxmum %ld", strlen(extval), SQLITE_FDW_BIT_DATATYPE_BUF_SIZE - 1)));
}
appendStringInfo(buf, "%lld", binstr2int(extval));
}
break;
case BOOLOID:
{
Expand Down
177 changes: 176 additions & 1 deletion expected/12.15/type.out
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ SELECT * FROM "type_DOUBLE"; -- OK

--Testcase 107:
ALTER FOREIGN TABLE "type_DOUBLE" ALTER COLUMN col TYPE float8;

--Testcase 108:
DROP FOREIGN TABLE "type_UUID";
--Testcase 109:
Expand Down Expand Up @@ -995,9 +996,179 @@ SELECT * FROM "type_UUID+" WHERE "u" IS NOT NULL;
SQLite query: SELECT `i`, coalesce(sqlite_fdw_uuid_blob(`u`),`u`), `t`, `l` FROM main."type_UUID+" WHERE ((coalesce(sqlite_fdw_uuid_blob(`u`),`u`) IS NOT NULL))
(3 rows)

--Testcase 199:
DROP FOREIGN TABLE "type_BIT";
--Testcase 200:
CREATE FOREIGN TABLE "type_BIT"( "i" int OPTIONS (key 'true'), "b" bit(6)) SERVER sqlite_svr OPTIONS (table 'type_BIT');
--Testcase 201:
DROP FOREIGN TABLE "type_BIT+";
ERROR: foreign table "type_BIT+" does not exist
--Testcase 202:
CREATE FOREIGN TABLE "type_BIT+"( "i" int OPTIONS (key 'true'), "b" bit(6), "t" text, "l" smallint, "bi" bigint OPTIONS (column_name 'b')) SERVER sqlite_svr OPTIONS (table 'type_BIT+');
--Testcase 203:
INSERT INTO "type_BIT" ("i", "b") VALUES (1, 1);
ERROR: column "b" is of type bit but expression is of type integer
LINE 1: INSERT INTO "type_BIT" ("i", "b") VALUES (1, 1);
^
HINT: You will need to rewrite or cast the expression.
--Testcase 204:
INSERT INTO "type_BIT" ("i", "b") VALUES (2, 2);
ERROR: column "b" is of type bit but expression is of type integer
LINE 1: INSERT INTO "type_BIT" ("i", "b") VALUES (2, 2);
^
HINT: You will need to rewrite or cast the expression.
--Testcase 205:
INSERT INTO "type_BIT" ("i", "b") VALUES (3, '1');
ERROR: bit string length 1 does not match type bit(6)
--Testcase 206:
INSERT INTO "type_BIT" ("i", "b") VALUES (4, '10');
ERROR: bit string length 2 does not match type bit(6)
--Testcase 207:
INSERT INTO "type_BIT" ("i", "b") VALUES (5, '101');
ERROR: bit string length 3 does not match type bit(6)
--Testcase 208:
INSERT INTO "type_BIT" ("i", "b") VALUES (6, '110110');
--Testcase 209:
INSERT INTO "type_BIT" ("i", "b") VALUES (7, '111001');
--Testcase 210:
INSERT INTO "type_BIT" ("i", "b") VALUES (8, '110000');
--Testcase 211:
INSERT INTO "type_BIT" ("i", "b") VALUES (9, '100001');
--Testcase 212:
INSERT INTO "type_BIT" ("i", "b") VALUES (10, 53);
ERROR: column "b" is of type bit but expression is of type integer
LINE 1: INSERT INTO "type_BIT" ("i", "b") VALUES (10, 53);
^
HINT: You will need to rewrite or cast the expression.
--Testcase 213:
SELECT * FROM "type_BIT+";
i | b | t | l | bi
---+--------+---------+---+----
6 | 110110 | integer | 2 | 54
7 | 111001 | integer | 2 | 57
8 | 110000 | integer | 2 | 48
9 | 100001 | integer | 2 | 33
(4 rows)

--Testcase 214:
SELECT * FROM "type_BIT" WHERE b < '110110';
i | b
---+--------
8 | 110000
9 | 100001
(2 rows)

--Testcase 215:
SELECT * FROM "type_BIT" WHERE b > '110110';
i | b
---+--------
7 | 111001
(1 row)

--Testcase 216:
SELECT * FROM "type_BIT" WHERE b = '110110';
i | b
---+--------
6 | 110110
(1 row)

--Testcase 217:
DROP FOREIGN TABLE "type_VARBIT";
--Testcase 218:
CREATE FOREIGN TABLE "type_VARBIT"( "i" int OPTIONS (key 'true'), "b" varbit(70)) SERVER sqlite_svr OPTIONS (table 'type_VARBIT');
--Testcase 219:
DROP FOREIGN TABLE "type_VARBIT+";
ERROR: foreign table "type_VARBIT+" does not exist
--Testcase 220:
CREATE FOREIGN TABLE "type_VARBIT+"( "i" int OPTIONS (key 'true'), "b" varbit(70), "t" text, "l" smallint) SERVER sqlite_svr OPTIONS (table 'type_VARBIT+');
--Testcase 221:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (1, '1');
--Testcase 222:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (2, '10');
--Testcase 223:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (3, '11');
--Testcase 224:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (4, '100');
--Testcase 225:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (5, '101');
--Testcase 226:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (6, '110110');
--Testcase 227:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (7, '111001');
--Testcase 228:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (8, '110000');
--Testcase 229:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (9, '100001');
--Testcase 230:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (10, '0100100101011001010010101000111110110101101101111011000101010');
--Testcase 231:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (11, '01001001010110010100101010001111101101011011011110110001010101');
--Testcase 232
SELECT * FROM "type_VARBIT+";
i | b | t | l
----+---------------------------------------------------------------+---------+----
1 | 1 | integer | 1
2 | 10 | integer | 1
3 | 11 | integer | 1
4 | 100 | integer | 1
5 | 101 | integer | 1
6 | 110110 | integer | 2
7 | 111001 | integer | 2
8 | 110000 | integer | 2
9 | 100001 | integer | 2
10 | 100100101011001010010101000111110110101101101111011000101010 | integer | 18
11 | 1001001010110010100101010001111101101011011011110110001010101 | integer | 19
(11 rows)

--Testcase 233:
SELECT * FROM "type_VARBIT+" WHERE b < '110110';
i | b | t | l
---+--------+---------+---
1 | 1 | integer | 1
2 | 10 | integer | 1
3 | 11 | integer | 1
4 | 100 | integer | 1
5 | 101 | integer | 1
8 | 110000 | integer | 2
9 | 100001 | integer | 2
(7 rows)

--Testcase 234:
SELECT * FROM "type_VARBIT+" WHERE b > '110110';
i | b | t | l
----+---------------------------------------------------------------+---------+----
7 | 111001 | integer | 2
10 | 100100101011001010010101000111110110101101101111011000101010 | integer | 18
11 | 1001001010110010100101010001111101101011011011110110001010101 | integer | 19
(3 rows)

--Testcase 235:
SELECT * FROM "type_VARBIT+" WHERE b = '110110';
i | b | t | l
---+--------+---------+---
6 | 110110 | integer | 2
(1 row)

--Testcase 236:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (12, '010010010101100101001010100011111011010110110111101100010101010');
--Testcase 237:
INSERT INTO "type_VARBIT" ("i", "b") VALUES (13, '0100100101011001010010101000111110110101101101111011000101010101');
--Testcase 238: 65 b
INSERT INTO "type_VARBIT" ("i", "b") VALUES (14, '01001001010110010100101010001111101101011011011110110001010101010');
ERROR: SQLite FDW dosens't support very long bit/varbit data
HINT: bit length 65, maxmum 64
--Testcase 239:
SELECT * FROM "type_VARBIT+" WHERE "i" > 10;
i | b | t | l
----+-----------------------------------------------------------------+---------+----
11 | 1001001010110010100101010001111101101011011011110110001010101 | integer | 19
12 | 10010010101100101001010100011111011010110110111101100010101010 | integer | 19
13 | 100100101011001010010101000111110110101101101111011000101010101 | integer | 19
(3 rows)

--Testcase 47:
DROP EXTENSION sqlite_fdw CASCADE;
NOTICE: drop cascades to 44 other objects
NOTICE: drop cascades to 48 other objects
DETAIL: drop cascades to server sqlite_svr
drop cascades to foreign table department
drop cascades to foreign table employee
Expand Down Expand Up @@ -1041,4 +1212,8 @@ drop cascades to foreign table type_json
drop cascades to foreign table "type_BOOLEAN"
drop cascades to foreign table "type_UUID"
drop cascades to foreign table "type_UUID+"
drop cascades to foreign table "type_BIT"
drop cascades to foreign table "type_BIT+"
drop cascades to foreign table "type_VARBIT"
drop cascades to foreign table "type_VARBIT+"
drop cascades to server sqlite2
Loading