Skip to content

Commit 281e2de

Browse files
committed
Fix logic defect of get data
1 parent 2f2ba9c commit 281e2de

1 file changed

Lines changed: 48 additions & 42 deletions

File tree

src/gstype_python.i

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -210,26 +210,22 @@ static void cleanString(const GSChar* string, int alloc){
210210
fragment = "convertStrToObj", fragment = "convertTimestampToObject") {
211211
static PyObject* convertFieldToObject(GSValue* value, GSType type, bool timestampToFloat = true) {
212212

213-
size_t size;
214213
PyObject* list;
215214
int i;
216215
switch (type) {
217216
case GS_TYPE_LONG:
218217
return PyLong_FromLong(value->asLong);
219218
case GS_TYPE_STRING:
220219
return convertStrToObj(value->asString);
221-
case GS_TYPE_NULL:
222-
Py_RETURN_NONE;
223220
case GS_TYPE_INTEGER:
224221
return PyInt_FromLong(value->asInteger);
225222
case GS_TYPE_DOUBLE:
226223
return PyFloat_FromDouble(value->asDouble);
227224
case GS_TYPE_TIMESTAMP:
228225
return convertTimestampToObject(&value->asTimestamp, timestampToFloat);
229226
default:
230-
return NULL;
227+
Py_RETURN_NONE;
231228
}
232-
return NULL;
233229
}
234230
}
235231

@@ -325,16 +321,15 @@ static bool convertObjectToBool(PyObject* value, GSBool* boolValPtr) {
325321
return false;
326322
}
327323
*boolValPtr = ((intVal != 0) ? GS_TRUE : GS_FALSE);
328-
return true;
329324
} else {
330325
//input is boolean
331326
checkConvert = SWIG_AsVal_bool(value, &tmpBool);
332327
if (!SWIG_IsOK(checkConvert)) {
333328
return false;
334329
}
335330
*boolValPtr = ((tmpBool == true) ? GS_TRUE : GS_FALSE);
336-
return true;
337331
}
332+
return true;
338333
}
339334
}
340335

@@ -964,6 +959,28 @@ static bool convertToFieldWithType(GSRow *row, int column, PyObject* value, GSTy
964959
PyErr_SetString(PyExc_ValueError, "Expected a List as List element");
965960
SWIG_fail;
966961
}
962+
int tupleLength = (int)PyInt_AsLong(PyLong_FromSsize_t(PyList_Size(list)));
963+
if (tupleLength == 3) {
964+
if (!PyInt_Check(PyList_GetItem(list, 2))) {
965+
PyErr_SetString(PyExc_ValueError, "Expected an Integer as column option");
966+
SWIG_fail;
967+
}
968+
$1[i].options = (int) PyInt_AsLong(PyList_GetItem(list, 2));
969+
if ($1[i].options != GS_TYPE_OPTION_NULLABLE && $1[i].options != GS_TYPE_OPTION_NOT_NULL) {
970+
PyErr_SetString(PyExc_ValueError, "Invalid value for column option");
971+
SWIG_fail;
972+
}
973+
} else if (tupleLength == 2) {
974+
if (i == 0) {
975+
$1[i].options = GS_TYPE_OPTION_NOT_NULL;
976+
} else {
977+
$1[i].options = GS_TYPE_OPTION_NULLABLE;
978+
}
979+
} else {
980+
PyErr_SetString(PyExc_ValueError, "Invalid element number for List");
981+
SWIG_fail;
982+
}
983+
967984
res = SWIG_AsCharPtrAndSize(PyList_GetItem(list, 0), &v, &size, &alloc[i]);
968985
if (!SWIG_IsOK(res)) {
969986
%variable_fail(res, "String", "name");
@@ -984,23 +1001,7 @@ static bool convertToFieldWithType(GSRow *row, int column, PyObject* value, GSTy
9841001
PyErr_SetString(PyExc_ValueError, "Expected an Integer as column type");
9851002
SWIG_fail;
9861003
}
987-
9881004
$1[i].type = (int) PyInt_AsLong(PyList_GetItem(list, 1));
989-
int tupleLength = (int)PyInt_AsLong(PyLong_FromSsize_t(PyList_Size(list)));
990-
//Case user input option parameter
991-
if (tupleLength == 3) {
992-
if (!PyInt_Check(PyList_GetItem(list, 2))) {
993-
PyErr_SetString(PyExc_ValueError, "Expected an Integer as column option");
994-
SWIG_fail;
995-
}
996-
$1[i].options = (int) PyInt_AsLong(PyList_GetItem(list, 2));
997-
if ($1[i].options != GS_TYPE_OPTION_NULLABLE && $1[i].options != GS_TYPE_OPTION_NOT_NULL) {
998-
PyErr_SetString(PyExc_ValueError, "Invalid value for column option");
999-
SWIG_fail;
1000-
}
1001-
} else if (tupleLength == 2) {
1002-
$1[i].options = 0;
1003-
}
10041005
i++;
10051006
}
10061007
}
@@ -1445,7 +1446,6 @@ static bool convertToFieldWithType(GSRow *row, int column, PyObject* value, GSTy
14451446
static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool timestampOutput, int* columnError,
14461447
GSType* fieldTypeError, PyObject* outList) {
14471448
GSResult ret;
1448-
GSValue mValue;
14491449
bool retVal = true;
14501450
for (int i = 0; i < columnCount; i++) {
14511451
//Check NULL value
@@ -2102,8 +2102,21 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
21022102
SWIG_fail;
21032103
}
21042104
size_t sizeColumn = (size_t)PyInt_AsLong(PyLong_FromSsize_t(PyList_Size(columInfoList)));
2105-
if (sizeColumn < 2) {
2106-
PyErr_SetString(PyExc_ValueError, "Expect column info has 3 elements");
2105+
if (sizeColumn == 3) {
2106+
option = PyInt_AsLong(PyList_GetItem(columInfoList, 2));
2107+
$1.columnInfo[i].options = option;
2108+
if (option != GS_TYPE_OPTION_NULLABLE && option != GS_TYPE_OPTION_NOT_NULL) {
2109+
PyErr_SetString(PyExc_ValueError, "Invalid value for column option");
2110+
SWIG_fail;
2111+
}
2112+
} else if (sizeColumn == 2) {
2113+
if (i == 0) {
2114+
$1.columnInfo[i].options = GS_TYPE_OPTION_NOT_NULL;
2115+
} else {
2116+
$1.columnInfo[i].options = GS_TYPE_OPTION_NULLABLE;
2117+
}
2118+
} else {
2119+
PyErr_SetString(PyExc_ValueError, "Invalid element number for List");
21072120
SWIG_fail;
21082121
}
21092122

@@ -2114,16 +2127,6 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
21142127
}
21152128
$1.columnInfo[i].name = v;
21162129
$1.columnInfo[i].type = PyLong_AsLong(PyList_GetItem(columInfoList, 1));
2117-
if (sizeColumn == 3) {
2118-
option = PyInt_AsLong(PyList_GetItem(columInfoList, 2));
2119-
$1.columnInfo[i].options = option;
2120-
if (option != GS_TYPE_OPTION_NULLABLE && option != GS_TYPE_OPTION_NOT_NULL) {
2121-
PyErr_SetString(PyExc_ValueError, "Invalid value for column option");
2122-
SWIG_fail;
2123-
}
2124-
} else if (sizeColumn == 2) {
2125-
$1.columnInfo[i].options = 0;
2126-
}
21272130
}
21282131
}
21292132
}
@@ -2195,7 +2198,7 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
21952198
int errorColumn;
21962199
if (*$2 == false) {
21972200
PyErr_SetNone(PyExc_StopIteration);
2198-
$result= NULL;
2201+
return NULL;
21992202
} else {
22002203
GSRow* row = arg1->getGSRowPtr();
22012204
PyObject *outList = PyList_New(arg1->getColumnCount());
@@ -2218,8 +2221,7 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
22182221
case (GS_ROW_SET_AGGREGATION_RESULT): {
22192222
std::shared_ptr< griddb::AggregationResult > *aggResult = NULL;
22202223
if (*$2 == false) {
2221-
PyErr_SetNone(PyExc_StopIteration);
2222-
$result= NULL;
2224+
Py_RETURN_NONE;
22232225
} else {
22242226
aggResult = *$4 ? new std::shared_ptr< griddb::AggregationResult >(*$4 SWIG_NO_NULL_DELETER_SWIG_POINTER_OWN) : 0;
22252227
$result = SWIG_NewPointerObj(SWIG_as_voidptr(aggResult), SWIGTYPE_p_std__shared_ptrT_griddb__AggregationResult_t, SWIG_POINTER_OWN | SWIG_POINTER_OWN);
@@ -2228,8 +2230,12 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
22282230
}
22292231
case (GS_ROW_SET_QUERY_ANALYSIS): {
22302232
std::shared_ptr< griddb::QueryAnalysisEntry >* queryAnalyResult = NULL;
2231-
queryAnalyResult = *$3 ? new std::shared_ptr< griddb::QueryAnalysisEntry >(*$3 SWIG_NO_NULL_DELETER_SWIG_POINTER_OWN) : 0;
2232-
$result = SWIG_NewPointerObj(SWIG_as_voidptr(queryAnalyResult), SWIGTYPE_p_std__shared_ptrT_griddb__QueryAnalysisEntry_t, SWIG_POINTER_OWN | SWIG_POINTER_OWN);
2233+
if (*$2 == false) {
2234+
Py_RETURN_NONE;
2235+
} else {
2236+
queryAnalyResult = *$3 ? new std::shared_ptr< griddb::QueryAnalysisEntry >(*$3 SWIG_NO_NULL_DELETER_SWIG_POINTER_OWN) : 0;
2237+
$result = SWIG_NewPointerObj(SWIG_as_voidptr(queryAnalyResult), SWIGTYPE_p_std__shared_ptrT_griddb__QueryAnalysisEntry_t, SWIG_POINTER_OWN | SWIG_POINTER_OWN);
2238+
}
22332239
break;
22342240
}
22352241
default: {
@@ -2270,4 +2276,4 @@ static bool getRowFields(GSRow* row, int columnCount, GSType* typeList, bool tim
22702276
}
22712277
$1 = ((tmpBool == true) ? GS_TRUE : GS_FALSE);
22722278

2273-
}
2279+
}

0 commit comments

Comments
 (0)