-3

I have to use libpq library NOT libpqxx and I couldn't find out how to bind NULL value for numeric type at a prepared statement. I tried NULL or null or even with "" but it didn't work.

...
std::string statements = "insert into ipls_troubleticketerrorreport2 (CUSTOMER, NETWORK,SELECTABLEMONTH, ERRORCODE,ERRORMESSAGE, TTID ) " \
                             "values ($1, $2, to_date($3,'DD.MM.YYYY'), $4, $5, $6);";
for (int i=0; i< sqlParametersWithValue.size();i++)
    {
        char NULLstr[] = "NULL";
        if ((sqlParametersWithValue[i].second) == "")
        {
            paramValues[i] = NULLstr;
        }
        else
        {       
            paramValues[i] = &(*(sqlParametersWithValue[i].second).c_str());
        }
    }




pgres =  PQexecParams(pgconn,statements.c_str(), sqlParametersWithValue.size() , NULL, paramValues, NULL, NULL, 0);
Tomtom
  • 45
  • 7

1 Answers1

2

You are passing it a string containing "NULL" rather than an actual null pointer.

paramValues[i] = NULL;
paramValues[i] = nullptr; // If using C++

https://www.postgresql.org/docs/9.1/libpq-exec.html

paramValues[]
Specifies the actual values of the parameters. A null pointer in this array means the corresponding parameter is null; otherwise the pointer points to a zero-terminated text string (for text format) or binary data in the format expected by the server (for binary format).

Fire Lancer
  • 29,364
  • 31
  • 116
  • 182