Skip to content

Commit 99ea772

Browse files
authored
Merge pull request Segfault-Inc#216 (Fixes Segfault-Inc#102)
Fix for mishandling of None elements in sequence lines.
2 parents c259b61 + 54f2c10 commit 99ea772

File tree

5 files changed

+68
-13
lines changed

5 files changed

+68
-13
lines changed

python/multicorn/testfdw.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def __init__(self, options, columns):
1515
super(TestForeignDataWrapper, self).__init__(options, columns)
1616
self.columns = columns
1717
self.test_type = options.get('test_type', None)
18+
self.test_subtype = options.get('test_subtype', None)
1819
self.tx_hook = options.get('tx_hook', False)
1920
self._row_id_column = options.get('row_id_column',
2021
list(self.columns.keys())[0])
@@ -35,8 +36,11 @@ def _as_generator(self, quals, columns):
3536
if self.test_type == 'sequence':
3637
line = []
3738
for column_name in self.columns:
38-
line.append('%s %s %s' % (column_name,
39-
next(random_thing), index))
39+
if self.test_subtype == '1null' and len(line) == 0:
40+
line.append(None)
41+
else:
42+
line.append('%s %s %s' % (column_name,
43+
next(random_thing), index))
4044
else:
4145
line = {}
4246
for column_name, column in self.columns.items():

src/python.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,18 +1274,20 @@ pythonSequenceToTuple(PyObject *p_value,
12741274
if(p_object == NULL || p_object == Py_None){
12751275
nulls[i] = true;
12761276
values[i] = 0;
1277-
continue;
1278-
}
1279-
resetStringInfo(buffer);
1280-
values[i] = pyobjectToDatum(p_object, buffer,
1281-
cinfos[cinfo_idx]);
1282-
if (buffer->data == NULL)
1283-
{
1284-
nulls[i] = true;
12851277
}
12861278
else
12871279
{
1288-
nulls[i] = false;
1280+
resetStringInfo(buffer);
1281+
values[i] = pyobjectToDatum(p_object, buffer,
1282+
cinfos[cinfo_idx]);
1283+
if (buffer->data == NULL)
1284+
{
1285+
nulls[i] = true;
1286+
}
1287+
else
1288+
{
1289+
nulls[i] = false;
1290+
}
12891291
}
12901292
errorCheck();
12911293
Py_DECREF(p_object);

test-2.7/expected/multicorn_sequence_test.out

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,28 @@ NOTICE: ['test1', 'test2']
330330
test1 3 19 | test2 1 19
331331
(40 rows)
332332

333+
CREATE foreign table testmulticorn3 (
334+
test1 character varying,
335+
test2 character varying
336+
) server multicorn_srv options (
337+
option1 'option1',
338+
test_type 'sequence',
339+
test_subtype '1null'
340+
);
341+
select * from testmulticorn3 limit 1;
342+
NOTICE: [('option1', 'option1'), ('test_subtype', '1null'), ('test_type', 'sequence'), ('usermapping', 'test')]
343+
NOTICE: [('test1', 'character varying'), ('test2', 'character varying')]
344+
NOTICE: []
345+
NOTICE: ['test1', 'test2']
346+
test1 | test2
347+
-------+-----------
348+
| test2 1 0
349+
(1 row)
350+
333351
DROP USER MAPPING FOR postgres SERVER multicorn_srv;
334352
DROP EXTENSION multicorn cascade;
335-
NOTICE: drop cascades to 3 other objects
353+
NOTICE: drop cascades to 4 other objects
336354
DETAIL: drop cascades to server multicorn_srv
337355
drop cascades to foreign table testmulticorn
338356
drop cascades to foreign table testmulticorn2
357+
drop cascades to foreign table testmulticorn3

test-2.7/sql/multicorn_sequence_test.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,16 @@ CREATE foreign table testmulticorn2 (
4747
);
4848

4949
select * from testmulticorn union all select * from testmulticorn2;
50+
51+
CREATE foreign table testmulticorn3 (
52+
test1 character varying,
53+
test2 character varying
54+
) server multicorn_srv options (
55+
option1 'option1',
56+
test_type 'sequence',
57+
test_subtype '1null'
58+
);
59+
select * from testmulticorn3 limit 1;
60+
5061
DROP USER MAPPING FOR postgres SERVER multicorn_srv;
5162
DROP EXTENSION multicorn cascade;

test-3.3/expected/multicorn_sequence_test.out

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,28 @@ NOTICE: ['test1', 'test2']
330330
test1 3 19 | test2 1 19
331331
(40 rows)
332332

333+
CREATE foreign table testmulticorn3 (
334+
test1 character varying,
335+
test2 character varying
336+
) server multicorn_srv options (
337+
option1 'option1',
338+
test_type 'sequence',
339+
test_subtype '1null'
340+
);
341+
select * from testmulticorn3 limit 1;
342+
NOTICE: [('option1', 'option1'), ('test_subtype', '1null'), ('test_type', 'sequence'), ('usermapping', 'test')]
343+
NOTICE: [('test1', 'character varying'), ('test2', 'character varying')]
344+
NOTICE: []
345+
NOTICE: ['test1', 'test2']
346+
test1 | test2
347+
-------+-----------
348+
| test2 1 0
349+
(1 row)
350+
333351
DROP USER MAPPING FOR postgres SERVER multicorn_srv;
334352
DROP EXTENSION multicorn cascade;
335-
NOTICE: drop cascades to 3 other objects
353+
NOTICE: drop cascades to 4 other objects
336354
DETAIL: drop cascades to server multicorn_srv
337355
drop cascades to foreign table testmulticorn
338356
drop cascades to foreign table testmulticorn2
357+
drop cascades to foreign table testmulticorn3

0 commit comments

Comments
 (0)