Search code examples
postgresqlodbcparameterized

PostgreSQL with ODBC: "there is no parameter $1"


I have a insert statement:

    INSERT INTO billData (
      tmStart, tsDuration, eCallDir, ...
    ) VALUES (
      $1,  -- tmStart
      $2,  -- tsDuration
      $3,  -- eCallDir
      ...
    );

I use SQLPrepare to compile it, bind parameters by SQLBindParameter, and execute it by SQLExecute.

After all of there steps, the error code 42P02 (there is no parameter $1) was returned.

BTW: I'm also using the almost same code for MS SQL Server and MySQL, and these two DB are working very well, so I believe my code is correct.

PS: the PostgreSQL is v9.1; the psqlODBC is v9.01.0100-1.

============================================================
UPDATE:

And the following error occured: 42601 (syntax error at or near ",") when I'm using '?' as the parameter placholder:

    INSERT INTO billData (
      tmStart, tsDuration, eCallDir, ...
    ) VALUES (
      ?,  -- tmStart
      ?,  -- tsDuration
      ?,  -- eCallDir
      ...
    );

============================================================
UPDATE:

According to the suggestion from j.w.r, It works after adding UseServerSidePrepare=1 option to the ODBC connection string.

A lot of thanks :-)


Solution

  • ============================================================ UPDATE:

    According to the suggestion from j.w.r, It works after adding UseServerSidePrepare=1 option to the ODBC connection string.

    A lot of thanks :-)

    Note: the ByteaAsLongVarBinary=1 option should also be added if you want to parameterize a bytea field with SQLBindParameter.