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

Fix bug when reading short binary data #137

Merged
merged 2 commits into from
Oct 30, 2020
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
2 changes: 1 addition & 1 deletion odbc_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1789,7 +1789,7 @@ odbcIterateForeignScan(ForeignScanState *node)
}
else // NO_TRUNCATION: finish reading
{
used_buffer_size += effective_chunk_size;
used_buffer_size += result_size;
}
} while (truncation == STRING_TRUNCATION && chunk_size > 0);

Expand Down
6 changes: 6 additions & 0 deletions test/expected/postgres_20_query_test.out
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ varch | 123456789abcdef101112131415161718191a1b1c1d1e1f202122232425262728292a2b
varbin | \x123456789abcdef101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff10010110210310410510610710810910a10b10c10d10e10f11011111211311411511611711811911a11b11c11d11e11f12012112212312412512612712812912a12b12c12d12e12f13013113213313413513613713813913a13b13c13d13e13f14014114214314414514614714814914a14b14c14d14e14f15015115215315415515615715815915a15b15c15d15e15f16016116216316416516616716816916a16b16c16d16e16f17017117217317417517617717817917a17b17c17d17e17f18018118218318418518618718818918a18b18c18d18e18f19019119219319419519619719819919a19b19c19d19e19f1a01a11a21a31a41a51a61a71a81a91aa1ab1ac1ad1ae1af1b01b11b21b31b41b51b61b71b81b91ba1bb1bc1bd1be1bf1c01c11c21c31c41c51c61c71c81c91ca1cb1cc1cd1ce1cf1d01d11d21d31d41d51d61d71d81d91da1db1dc1dd1de1df1e01e11e21e31e41e51e61e71e81e91ea1eb1ec1ed1ee1ef1f01f11f21f31f41f51f61f71f81f91fa1fb1fc1fd1fe1ff20020120220320420520620720820920a20b20c20d20e20f21021121221321421521621721821921a21b21c21d21e21f22022122222322422522622722822922a22b22c22d22e22f23023123223323423523623723823923a23b23c23d23e23f24024124224324424524624724824924a24b24c24d24e24f25025125225325425525625725825925a25b25c25d25e25f26026126226326426526626726826926a26b26c26d26e26f27027127227327427527627727827927a27b27c27d27e27f28028128228328428528628728828928a28b28c28d28e28f29029129229329429529629729829929a29b29c29d29e29f2a02a12a22a32a42a52a62a72a82a92aa2ab2ac2ad2ae2af2b02b12b22b32b42b52b62b72b82b92ba2bb2bc2bd2be2bf2c02c12c22c32c42c52c62c72c82c92ca2cb2cc2cd2ce2cf2d02d12d22d32d42d52d62d72d82d92da2db2dc2dd2de2df2e02e12e22e32e42e52e62e72e82e92ea2eb2ec2ed2ee2ef2f02f12f22f32f42f52f62f72f82f92fa2fb2fc2fd2fe2ff30030130230330430530630730830930a30b30c30d30e30f31031131231331431531631731831931a31b31c31d31e31f32032132232332432532632732832932a32b32c32d32e32f33033133233333433533633733833933a33b33c33d33e33f34034134234334434534634734834934a34b34c34d34e34f35035135235335435535635735835935a35b35c35d35e35f36036136236336436536636736836936a36b36c36d36e36f37037137237337437537637737837937a37b37c37d37e37f38038138238338438538638738838938a38b38c38d38e38f39039139239339439539639739839939a39b39c39d39e39f3a03a13a23a33a43a53a63a73a83a93aa3ab3ac3ad3ae3af3b03b13b23b33b43b53b63b73b83b93ba3bb3bc3bd3be3bf3c03c13c23c33c43c53c63c73c83c93ca3cb3cc3cd3ce3cf3d03d13d23d33d43d53d63d73d83d93da3db3dc3dd3de3df3e03e13e23e33e43e53e63e73e83e93ea3eb3ec3ed3ee3ef3f03f13f23f33f43f53f63f73f83f93fa3fb3fc3fd3fe3ff40040140240340440540640740840940a40b40c40d40e40f41041141241341441541641741841941a41b41c41d41e41f42042142242342442542642742842942a42b42c42d42e42f43043143243343443543643743843943a43b43c43d43e43f44044144244344444544644744844944a44b44c44d44e44f45045145245345445545645745845945a45b45c45d45e45f46046146246346446546646746846946a46b46c46d46e46f47047147247347447547647747847947a47b47c47d47e47f48048148248348448548648748848948a48b48c48d48e48f49049149249349449549649749849949a49b49c49d49e49f4a04a14a24a34a44a54a64a74a84a94aa4ab4ac4ad4ae4af4b04b14b24b34b44b54b64b74b84b94ba4bb4bc4bd4be4bf4c04c14c24c34c44c54c64c74c84c94ca4cb4cc4cd4ce4cf4d04d14d24d34d44d54d64d74d84d94da4db4dc4dd4de4df4e04e14e24e34e44e54e64e74e84e94ea4eb4ec4ed4ee4ef4f04f14f24f34f44f54f64f74f84f94fa4fb4fc4fd4fe4ff50050150250350450550650750850950a50b50c50d50e50f51051151251351451551651751851951a51b51c51d51e51f52052152252352452552652752852952a52b52c52d52e52f53053153253353453553653753853953a53b53c53d53e53f54054154254354454554654754854954a54b54c54d54e54f55055155255355455555655755855955a55b55c55d55e55f56056156256356456556656756856956a56b56c56d56e56f57057157257357457557657757857957a57b57c57d57e57f58058158258358458558658758858958a58b58c58d58e58f59059159259359459559659759859959a59b59c59d59e59f5a05a15a25a35a45a55a65a75a85a95aa5ab5ac5ad5ae5af5b05b15b25b35b45b55b65b75b85b95ba5bb5bc5bd5be5bf5c05c15c25c35c45c55c65c75c85c95ca5cb5cc5cd5ce5cf5d05d15d25d35d45d55d65d75d85d95da5db5dc5dd5de5df5e05e15e25e35e45e55e65e75e85e95ea5eb5ec5ed5ee5ef5f05f15f25f35f45f55f65f75f85f95fa5fb5fc5fd5fe5ff60060160260360460560660760860960a60b60c60d60e60f61061161261361461561661761861961a61b61c61d61e61f62062162262362462562662762862962a62b62c62d62e62f63063163263363463563663763863963a63b63c63d63e63f64064164264364464564664764864964a64b64c64d64e64f65065165265365465565665765865965a65b65c65d65e65f66066166266366466566666766866966a66b66c66d66e66f67067167267367467567667767867967a67b67c67d67e67f68068168268368468568668768868968a68b68c68d68e68f69069169269369469569669769869969a69b69c69d69e69f6a06a16a26a36a46a56a66a76a86a96aa6ab6ac6ad6ae6af6b06b16b26b36b46b56b66b76b86b96ba6bb6bc6bd6be6bf6c06c16c26c36c46c56c66c76c86c96ca6cb6cc6cd6ce6cf6d06d16d26d36d46d56d66d76d86d96da6db6dc6dd6de6df6e06e16e26e36e46e56e66e76e86e96ea6eb6ec6ed6ee6ef6f06f16f26f36f46f56f66f76f86f96fa6fb6fc6fd6fe6ff70070170270370470570670770870970a70b70c70d70e70f71071171271371471571671771871971a71b71c71d71e71f72072172272372472572672772872972a72b72c72d72e72f73073173273373473573673773873973a73b73c73d73e73f74074174274374474574674774874974a74b74c74d74e74f75075175275375475575675775875975a75b75c75d75e75f76076176276376476576676776876976a76b76c76d76e76f77077177277377477577677777877977a77b77c77d77e77f78078178278378478578678778878978a78b78c78d78e78f79079179279379479579679779879979a79b79c79d79e79f7a07a17a27a37a47a57a67a77a87a97aa7ab7ac7ad7ae7af7b07b17b27b37b47b57b67b77b87b97ba7bb7bc7bd7be7bf7c07c17c27c37c47c57c67c77c87c97ca7cb7cc7cd7ce7cf7d07d17d27d37d47d57d67d77d87d97da7db7dc7dd7de7df7e07e17e27e37e47e57e67e77e87e97ea7eb7ec7ed7ee7ef7f07f17f27f37f47f57f67f77f87f97fa7fb7fc7fd7fe7ff80080180280380480580680780880980a80b80c80d80e80f81081181281381481581681781881981a81b81c81d81e81f82082182282382482582682782882982a82b82c82d82e82f83083183283383483583683783883983a83b83c83d83e83f84084184284384484584684784884984a84b84c84d84e84f85085185285385485585685785885985a85b85c85d85e85f86086186286386486586686786886986a86b86c86d86e86f87087187287387487587687787887987a87b87c87d87e87f88088188288388488588688788888988a88b88c88d88e88f89089189289389489589689789889989a89b89c89d89e89f8a08a18a28a38a48a58a68a78a88a98aa8ab8ac8ad8ae8af8b08b18b28b38b48b58b68b78b88b98ba8bb8bc8bd8be8bf8c08c18c28c38c48c58c68c78c88c98ca8cb8cc8cd8ce8cf8d08d18d28d38d48d58d68d78d88d98da8db8dc8dd8de8df8e08e18e28e38e48e58e68e78e88e98ea8eb8ec8ed8ee8ef8f08f18f28f38f48f58f68f78f88f98fa8fb8fc8fd8fe8ff90090190290390490590690790890990a90b90c90d90e90f91091191291391491591691791891991a91b91c91d91e91f92092192292392492592692792892992a92b92c92d92e92f93093193293393493593693793893993a93b93c93d93e93f94094194294394494594694794894994a94b94c94d94e94f95095195295395495595695795895995a95b95c95d95e95f96096196296396496596696796896996a96b96c96d96e96f97097197297397497597697797897997a97b97c97d97e97f98098198298398498598698798898998a98b98c98d98e98f99099199299399499599699799899999a99b99c99d99e99f9a09a19a29a39a49a59a69a79a89a99aa9ab9ac9ad9ae9af9b09b19b29b39b49b59b69b79b89b99ba9bb9bc9bd9be9bf9c09c19c29c39c49c59c69c79c89c99ca9cb9cc9cd9ce9cf9d09d19d29d39d49d59d69d79d89d99da9db9dc9dd9de9df9e09e19e29e39e49e59e69e79e89e99ea9eb9ec9ed9ee9ef9f09f19f29f39f49f59f69f79f89f99fa9fb9fc9fd9fe9ffa00a01a02a03a04a05a06a07a08a09a0aa0ba0ca0da0ea0fa10a11a12a13a14a15a16a17a18a19a1aa1ba1ca1da1ea1fa20a21a22a23a24a25a26a27a28a29a2aa2ba2ca2da2ea2fa30a31a32a33a34a35a36a37a38a39a3aa3ba3ca3da3ea3fa40a41a42a43a44a45a46a47a48a49a4aa4ba4ca4da4ea4fa50a51a52a53a54a55a56a57a58a59a5aa5ba5ca5da5ea5fa60a61a62a63a64a65a66a67a68a69a6aa6ba6ca6da6ea6fa70a71a72a73a74a75a76a77a78a79a7aa7ba7ca7da7ea7fa80a81a82a83a84a85a86a87a88a89a8aa8ba8ca8da8ea8fa90a91a92a93a94a95a96a97a98a99a9aa9ba9ca9da9ea9faa0aa1aa2aa3aa4aa5aa6aa7aa8aa9aaaaabaacaadaaeaafab0ab1ab2ab3ab4ab5ab6ab7ab8ab9abaabbabcabdabeabfac0ac1ac2ac3ac4ac5ac6ac7ac8ac9acaacbaccacdaceacfad0ad1ad2ad3ad4ad5ad6ad7ad8ad9adaadbadcaddadeadfae0ae1ae2ae3ae4ae5ae6ae7ae8ae9aeaaebaecaedaeeaefaf0af1af2af3af4af5af6af7af8af9afaafbafcafdafeaffb00b01b02b03b04b05b06b07b08b09b0ab0bb0cb0db0eb0fb10b11b12b13b14b15b16b17b18b19b1ab1bb1cb1db1eb1fb20b21b22b23b24b25b26b27b28b29b2ab2bb2cb2db2eb2fb30b31b32b33b34b35b36b37b38b39b3ab3bb3cb3db3eb3fb40b41b42b43b44b45b46b47b48b49b4ab4bb4cb4db4eb4fb50b51b52b53b54b55b56b57b58b59b5ab5bb5cb5db5eb5fb60b61b62b63b64b65b66b67b68b69b6ab6bb6cb6db6eb6fb70b71b72b73b74b75b76b77b78b79b7ab7bb7cb7db7eb7fb80b81b82b83b84b85b86b87b88b89b8ab8bb8cb8db8eb8fb90b91b92b93b94b95b96b97b98b99b9ab9bb9cb9db9eb9fba0ba1ba2ba3ba4ba5ba6ba7ba8ba9baababbacbadbaebafbb0bb1bb2bb3bb4bb5bb6bb7bb8

\x
SELECT * FROM postgres_short_test_table;
varch | varbin
----------------------------+------------------------------
ABCDEFGHIJKLMNOPQRST123456 | \x0701ef34a0a132979e23b3b017
(1 row)

7 changes: 6 additions & 1 deletion test/fixtures/postgres_fixtures.sql
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ CREATE TABLE test_schema.test_table_in_schema (
);
INSERT INTO test_schema.test_table_in_schema VALUES (1, 'example');

-- To test reading variable size data
-- To test reading long variable size data (larger than chunk size)
CREATE TABLE postgres_var_test_table(varch text, varbin bytea);
INSERT INTO postgres_var_test_table
SELECT string_agg(to_hex(n), ''), ('\x' || string_agg(to_hex(n),''))::bytea FROM generate_series(1,3000) n;

-- To test reading short variable size data (shorter than chunk size)
CREATE TABLE postgres_short_test_table(varch text, varbin bytea);
INSERT INTO postgres_short_test_table
SELECT 'ABCDEFGHIJKLMNOPQRST123456'::text, '\x0701EF34A0A132979E23B3B017'::bytea;
3 changes: 2 additions & 1 deletion test/sql/postgres_20_query_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ SELECT * FROM ODBCTableSize('postgres_fdw', 'postgres_test_table');
SELECT * FROM ODBCQuerySize('postgres_fdw', 'select * from postgres_test_table');
\x
SELECT * FROM postgres_var_test_table;
\x
\x
SELECT * FROM postgres_short_test_table;
8 changes: 8 additions & 0 deletions test/template/postgres_installation_test.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ IMPORT FOREIGN SCHEMA public
table 'postgres_var_test_table',
"odbc_BoolsAsChar" '0',
"odbc_ByteaAsLongVarBinary" '1'
);
IMPORT FOREIGN SCHEMA public
FROM SERVER postgres_fdw
INTO public
OPTIONS(
table 'postgres_short_test_table',
"odbc_BoolsAsChar" '0',
"odbc_ByteaAsLongVarBinary" '1'
);