Why that query fails?

From: Igor Korot <ikorot01(at)gmail(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Why that query fails?
Date: 2026-04-26 20:15:26
Message-ID: CA+FnnTy3D3Zo0XxNe37w5FnmGftvv_jWuLVMdS0Y3qPanx2seA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, ALL,
[quote]
Thread 1 "dbhandler" hit Breakpoint 1,
PostgresDatabase::CreateDatabase (this=0x616000180c80,
name=L"test", opts=std::shared_ptr<CreateDBOptions> (use count 1,
weak count 0) = {...},
errorMsg=std::vector of length 0, capacity 0) at
../../libpostgres/database_postgres.cpp:46
46 int result = 0;
(gdb) n
47 auto exists = false;
(gdb)
48 std::vector<std::wstring> dbList;
(gdb)
49 std::wstring qry0, qry1, qry2;
(gdb)
50 qry0 = L"SELECT 1 FROM pg_database WHERE datname = $1";
(gdb)
51 if( opts->m_exist )
(gdb)
54 values[0] = NULL;
(gdb)
55 values[0] = new char[name.length() * sizeof( wchar_t ) + 1];
(gdb)
56 memset( values[0], '\0', name.length() * sizeof( wchar_t ) + 1 );
(gdb)
57 strcpy( values[0], m_pimpl->m_myconv.to_bytes(
name.c_str() ).c_str() );
(gdb)
58 int len1 = (int) name.length() * sizeof( wchar_t );
(gdb)
59 int length[1] = { len1 };
(gdb)
60 int formats[1] = { 1 };
(gdb)
61 auto res = PQexecParams( m_db,
m_pimpl->m_myconv.to_bytes( qry0.c_str() ).c_str(), 1, NULL, values,
length, formats, 0 );
(gdb)
62 auto status = PQresultStatus( res );
(gdb)
63 if( status != PGRES_TUPLES_OK )
(gdb) p status
$1 = PGRES_FATAL_ERROR
(gdb) n
65 std::wstring err = m_pimpl->m_myconv.from_bytes(
PQerrorMessage( m_db ) );
(gdb)
66 errorMsg.push_back( L"Error executing query: " + err );
(gdb) p err
$2 = L"ERROR: invalid byte sequence for encoding \"UTF8\":
0x00\nCONTEXT: unnamed portal parameter $1\n"
(gdb)
[/quote]

What am I doing wrong?

Thank you.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2026-04-26 20:22:28 Re: Why that query fails?
Previous Message Radu Radutiu 2026-04-23 11:39:34 Re: Patroni basebackup server compression not working in 4.1.1