Handle output parameters properly in build_libpq_bind_params.
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Sat, 4 Mar 2017 12:33:57 +0000 (21:33 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Sat, 4 Mar 2017 12:50:01 +0000 (21:50 +0900)
Also handle return values properly.
Now passes odbc-escapes-test.

convert.c
statement.c
test/src/odbc-escapes-test.c

index 0e7bd3750a14eb235a0f6257aa1a3f1ac5b461b2..c2ff663b20a7ba878ae7a464a52b3ad330aed4f4 100644 (file)
--- a/convert.c
+++ b/convert.c
@@ -3710,26 +3710,22 @@ build_libpq_bind_params(StatementClass *stmt,
    num_p = num_params - qb.num_discard_params;
 inolog("num_p=%d\n", num_p);
    discard_output = (0 != (qb.flags & FLGB_DISCARD_OUTPUT));
+   *nParams = 0;
    if (num_p > 0)
    {
        ParameterImplClass  *parameters = ipdopts->parameters;
+       int pno;
+
+       BOOL    isnull;
+       BOOL    isbinary;
+       char    *val_copy;
+       OID pgType;
 
        /*
         * Now build the parameter values.
         */
-       *nParams = 0;
-       for (i = 0; i < stmt->num_params; i++)
+       for (i = 0, pno = 0; i < stmt->num_params; i++)
        {
-           BOOL        isnull;
-           BOOL        isbinary;
-           char       *val_copy;
-           OID         pgType;
-
-           inolog("%dth parameter type oid is %u\n", i, PIC_dsp_pgtype(conn, parameters[i]));
-
-           if (discard_output && SQL_PARAM_OUTPUT == parameters[i].paramType)
-               continue;
-
            qb.npos = 0;
            retval = ResolveOneParam(&qb, NULL, &isnull, &isbinary, &pgType);
            if (SQL_ERROR == retval)
@@ -3739,6 +3735,21 @@ inolog("num_p=%d\n", num_p);
                goto cleanup;
            }
 
+           inolog("%dth parameter type oid is %u\n", i, PIC_dsp_pgtype(conn, parameters[i]));
+
+           if (i < qb.proc_return)
+               continue;
+           if (SQL_PARAM_OUTPUT == parameters[i].paramType)
+           {
+               if (discard_output)
+                   continue;
+               (*paramTypes)[pno] = PG_TYPE_VOID;
+               (*paramValues)[pno] = NULL;
+               (*paramLengths)[pno] = 0;
+               (*paramFormats)[pno] = 0;
+               pno++;
+               continue;
+           }
            if (!isnull)
            {
                val_copy = malloc(qb.npos + 1);
@@ -3747,27 +3758,26 @@ inolog("num_p=%d\n", num_p);
                memcpy(val_copy, qb.query_statement, qb.npos);
                val_copy[qb.npos] = '\0';
 
-               (*paramTypes)[i] = pgType;
-               (*paramValues)[i] = val_copy;
+               (*paramTypes)[pno] = pgType;
+               (*paramValues)[pno] = val_copy;
                if (qb.npos > INT_MAX)
                    goto cleanup;
-               (*paramLengths)[i] = (int) qb.npos;
+               (*paramLengths)[pno] = (int) qb.npos;
            }
            else
            {
-               (*paramTypes)[i] = pgType;
-               (*paramValues)[i] = NULL;
-               (*paramLengths)[i] = 0;
+               (*paramTypes)[pno] = pgType;
+               (*paramValues)[pno] = NULL;
+               (*paramLengths)[pno] = 0;
            }
            if (isbinary)
-               mylog("%dth parameter is of binary format\n", *nParams);
-           (*paramFormats)[i] = isbinary ? 1 : 0;
+               mylog("%dth parameter is of binary format\n", pno);
+           (*paramFormats)[pno] = isbinary ? 1 : 0;
 
-           (*nParams)++;
+           pno++;
        }
+       *nParams = pno;
    }
-   else
-       *nParams = 0;
 
    /* result format is text */
    *resultFormat = 0;
index 6d66a7537fede39fd3281234b7c96257a6f458cb..cff7c02f975404a2fe2d7db0e61b8581db103013 100644 (file)
@@ -2614,7 +2614,11 @@ ParseWithLibpq(StatementClass *stmt, const char *plan_name,
            if (pidx > end_pidx)
                break;
            else if (pidx < end_pidx)
+           {
+               if (0 == num_params)
+                   sta_pidx = pidx;
                num_params++;
+           }
            else
            {
                num_params++;
index 4cd448ee7c3c9ef261ce478336c0461b77a1715f..cd572c2a9a3418540f0fdda9d6f7b4963b79e12e 100644 (file)
@@ -84,7 +84,7 @@ prepareQuery(HSTMT hstmt, char *str)
 static void    escape_test(HSTMT hstmt)
 {
    char    outbuf1[64], outbuf3[64], outbuf5[64];
-   BOOL    variadic_test_success = FALSE;
+   BOOL    variadic_test_success = TRUE;
 
    /**** Function escapes ****/