summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas2015-01-29 12:29:40 +0000
committerHeikki Linnakangas2015-01-29 12:30:20 +0000
commit4c90ca65403da625f191a84258221a461bd29718 (patch)
tree98434407d544d975e3df79836b4c6e8e26fb0778
parente5e048509bada06c61f05901904ddbdda070bd10 (diff)
Fix crash when a query is described, without binding params.
Add test case for the same.
-rw-r--r--statement.c15
-rw-r--r--test/expected/premature.out3
-rw-r--r--test/src/premature-test.c5
3 files changed, 18 insertions, 5 deletions
diff --git a/statement.c b/statement.c
index f53fcfb..20c9c06 100644
--- a/statement.c
+++ b/statement.c
@@ -2675,13 +2675,18 @@ mylog("sta_pidx=%d end_pidx=%d num_p=%d\n", sta_pidx, end_pidx, num_params);
j = 0;
for (i = sta_pidx; i <= end_pidx; i++)
{
- if (i < ipdopts->allocated &&
- SQL_PARAM_OUTPUT == ipdopts->parameters[i].paramType)
- paramTypes[j++] = PG_TYPE_VOID;
+ if (i < ipdopts->allocated)
+ {
+ if (SQL_PARAM_OUTPUT == ipdopts->parameters[i].paramType)
+ paramTypes[j++] = PG_TYPE_VOID;
+ else
+ paramTypes[j++] = sqltype_to_bind_pgtype(conn,
+ ipdopts->parameters[i].SQLType);
+ }
else
{
- paramTypes[j++] = sqltype_to_bind_pgtype(conn,
- ipdopts->parameters[i].SQLType);
+ /* Unknown type of parameter. Let the server decide */
+ paramTypes[j++] = 0;
}
}
}
diff --git a/test/expected/premature.out b/test/expected/premature.out
index 1a7cfdb..9d682d6 100644
--- a/test/expected/premature.out
+++ b/test/expected/premature.out
@@ -3,12 +3,15 @@ connected
Preparing an INSERT statement
# of result cols: 1
+# of result cols: 1
Preparing an insert using a function
# of result cols: 1
+# of result cols: 1
Preparing a multi-statement
# of result cols: 3
+# of result cols: 3
Prepare with function, but execute with different param
# of result cols: 1
diff --git a/test/src/premature-test.c b/test/src/premature-test.c
index 8bbb73d..9ef9ea1 100644
--- a/test/src/premature-test.c
+++ b/test/src/premature-test.c
@@ -112,16 +112,21 @@ int main(int argc, char **argv)
*/
printf("\nPreparing an INSERT statement\n");
runtest("INSERT INTO premature_test VALUES (?) RETURNING 'plain insert'::text", "plain insert", NULL, 0);
+ /* same with no parameter bound */
+ runtest("INSERT INTO premature_test VALUES (?) RETURNING 'plain insert'::text", NULL, NULL, 0);
/*** Now, do the same with the function ***/
printf("\nPreparing an insert using a function\n");
runtest("SELECT insertfunc(?)", "function insert", NULL, 0);
+ runtest("SELECT insertfunc(?)", NULL, NULL, 0);
/*** Same with the function, used in a multi-statement ***/
printf("\nPreparing a multi-statement\n");
runtest("SELECT 'foo', 2, 3; SELECT insertfunc(?), 2; SELECT 'bar'",
"function insert in multi-statement", NULL, 0);
+ runtest("SELECT 'foo', 2, 3; SELECT insertfunc(?), 2; SELECT 'bar'",
+ NULL, NULL, 0);
/*** Again with the function, but this time execute it too. With a
* twist: we rebind a different parameter after the SQLNumResultCols