public inbox for [email protected]
help / color / mirror / Atom feedWhy that query fails?
8+ messages / 5 participants
[nested] [flat]
* Why that query fails?
@ 2026-04-26 20:15 Igor Korot <[email protected]>
2026-04-26 20:22 ` Re: Why that query fails? Adrian Klaver <[email protected]>
2026-04-26 22:17 ` Re: Why that query fails? Greg Sabino Mullane <[email protected]>
0 siblings, 2 replies; 8+ messages in thread
From: Igor Korot @ 2026-04-26 20:15 UTC (permalink / raw)
To: pgsql-generallists.postgresql.org <[email protected]>
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.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
@ 2026-04-26 20:22 ` Adrian Klaver <[email protected]>
2026-04-26 20:34 ` Re: Why that query fails? Igor Korot <[email protected]>
1 sibling, 1 reply; 8+ messages in thread
From: Adrian Klaver @ 2026-04-26 20:22 UTC (permalink / raw)
To: Igor Korot <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>
On 4/26/26 1:15 PM, Igor Korot wrote:
> Hi, ALL,
> [quote]
> Thread 1 "dbhandler" hit Breakpoint 1,
> 66 errorMsg.push_back( L"Error executing query: " + err );
> (gdb) p err
> $2 = L"ERROR: invalid byte sequence for encoding \"UTF8\":
I would think the above is a clue.
Are you sure the value you are passing to the parameter is UTF8?
> 0x00\nCONTEXT: unnamed portal parameter $1\n"
> (gdb)
> [/quote]
>
> What am I doing wrong?
>
> Thank you.
>
>
--
Adrian Klaver
[email protected]
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:22 ` Re: Why that query fails? Adrian Klaver <[email protected]>
@ 2026-04-26 20:34 ` Igor Korot <[email protected]>
2026-04-26 20:38 ` Re: Why that query fails? Igor Korot <[email protected]>
0 siblings, 1 reply; 8+ messages in thread
From: Igor Korot @ 2026-04-26 20:34 UTC (permalink / raw)
To: Adrian Klaver <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>
Adrian,
On Sun, Apr 26, 2026 at 3:22 PM Adrian Klaver <[email protected]> wrote:
>
> On 4/26/26 1:15 PM, Igor Korot wrote:
> > Hi, ALL,
> > [quote]
> > Thread 1 "dbhandler" hit Breakpoint 1,
>
> > 66 errorMsg.push_back( L"Error executing query: " + err );
> > (gdb) p err
> > $2 = L"ERROR: invalid byte sequence for encoding \"UTF8\":
>
> I would think the above is a clue.
>
> Are you sure the value you are passing to the parameter is UTF8?
Positive.
This is what the following line should be doing:
[code]
57 strcpy( values[0], m_pimpl->m_myconv.to_bytes(
name.c_str() ).c_str() );
[/code]
Thank you.
>
> > 0x00\nCONTEXT: unnamed portal parameter $1\n"
> > (gdb)
> > [/quote]
> >
> > What am I doing wrong?
> >
> > Thank you.
> >
> >
>
>
> --
> Adrian Klaver
> [email protected]
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:22 ` Re: Why that query fails? Adrian Klaver <[email protected]>
2026-04-26 20:34 ` Re: Why that query fails? Igor Korot <[email protected]>
@ 2026-04-26 20:38 ` Igor Korot <[email protected]>
2026-04-26 22:06 ` Re: Why that query fails? Igor Korot <[email protected]>
0 siblings, 1 reply; 8+ messages in thread
From: Igor Korot @ 2026-04-26 20:38 UTC (permalink / raw)
To: Adrian Klaver <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>
Adrian,
On Sun, Apr 26, 2026 at 3:34 PM Igor Korot <[email protected]> wrote:
>
> Adrian,
>
> On Sun, Apr 26, 2026 at 3:22 PM Adrian Klaver <[email protected]> wrote:
> >
> > On 4/26/26 1:15 PM, Igor Korot wrote:
> > > Hi, ALL,
> > > [quote]
> > > Thread 1 "dbhandler" hit Breakpoint 1,
> >
> > > 66 errorMsg.push_back( L"Error executing query: " + err );
> > > (gdb) p err
> > > $2 = L"ERROR: invalid byte sequence for encoding \"UTF8\":
> >
> > I would think the above is a clue.
> >
> > Are you sure the value you are passing to the parameter is UTF8?
>
> Positive.
>
> This is what the following line should be doing:
>
> [code]
> 57 strcpy( values[0], m_pimpl->m_myconv.to_bytes(
> name.c_str() ).c_str() );
> [/code]
And the conversion is as follows:
[code]
std::wstring_convert<std::codecvt_utf8<wchar_t> > m_myconv;
[/code]
Thank you.
>
> Thank you.
>
> >
> > > 0x00\nCONTEXT: unnamed portal parameter $1\n"
> > > (gdb)
> > > [/quote]
> > >
> > > What am I doing wrong?
> > >
> > > Thank you.
> > >
> > >
> >
> >
> > --
> > Adrian Klaver
> > [email protected]
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:22 ` Re: Why that query fails? Adrian Klaver <[email protected]>
2026-04-26 20:34 ` Re: Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:38 ` Re: Why that query fails? Igor Korot <[email protected]>
@ 2026-04-26 22:06 ` Igor Korot <[email protected]>
2026-04-26 22:15 ` Re: Why that query fails? Ron Johnson <[email protected]>
0 siblings, 1 reply; 8+ messages in thread
From: Igor Korot @ 2026-04-26 22:06 UTC (permalink / raw)
To: Adrian Klaver <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>
Adrian,
On Sun, Apr 26, 2026 at 3:38 PM Igor Korot <[email protected]> wrote:
>
> Adrian,
>
> On Sun, Apr 26, 2026 at 3:34 PM Igor Korot <[email protected]> wrote:
> >
> > Adrian,
> >
> > On Sun, Apr 26, 2026 at 3:22 PM Adrian Klaver <[email protected]> wrote:
> > >
> > > On 4/26/26 1:15 PM, Igor Korot wrote:
> > > > Hi, ALL,
> > > > [quote]
> > > > Thread 1 "dbhandler" hit Breakpoint 1,
> > >
> > > > 66 errorMsg.push_back( L"Error executing query: " + err );
> > > > (gdb) p err
> > > > $2 = L"ERROR: invalid byte sequence for encoding \"UTF8\":
> > >
> > > I would think the above is a clue.
> > >
> > > Are you sure the value you are passing to the parameter is UTF8?
> >
> > Positive.
> >
> > This is what the following line should be doing:
> >
> > [code]
> > 57 strcpy( values[0], m_pimpl->m_myconv.to_bytes(
> > name.c_str() ).c_str() );
> > [/code]
>
> And the conversion is as follows:
>
> [code]
> std::wstring_convert<std::codecvt_utf8<wchar_t> > m_myconv;
> [/code]
>
> Thank you.
Those are the values from gdb:
[code]
(gdb) p values[0]
$1 = 0x603001613380 "test"
(gdb) p strlen(values[0])
$2 = 4
(gdb)
[/code]
Thank you.
>
> >
> > Thank you.
> >
> > >
> > > > 0x00\nCONTEXT: unnamed portal parameter $1\n"
> > > > (gdb)
> > > > [/quote]
> > > >
> > > > What am I doing wrong?
> > > >
> > > > Thank you.
> > > >
> > > >
> > >
> > >
> > > --
> > > Adrian Klaver
> > > [email protected]
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:22 ` Re: Why that query fails? Adrian Klaver <[email protected]>
2026-04-26 20:34 ` Re: Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:38 ` Re: Why that query fails? Igor Korot <[email protected]>
2026-04-26 22:06 ` Re: Why that query fails? Igor Korot <[email protected]>
@ 2026-04-26 22:15 ` Ron Johnson <[email protected]>
0 siblings, 0 replies; 8+ messages in thread
From: Ron Johnson @ 2026-04-26 22:15 UTC (permalink / raw)
To: Igor Korot <[email protected]>; +Cc: Adrian Klaver <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>
When in doubt, run the query interactively.
On Sun, Apr 26, 2026 at 6:06 PM Igor Korot <[email protected]> wrote:
> Adrian,
>
> On Sun, Apr 26, 2026 at 3:38 PM Igor Korot <[email protected]> wrote:
> >
> > Adrian,
> >
> > On Sun, Apr 26, 2026 at 3:34 PM Igor Korot <[email protected]> wrote:
> > >
> > > Adrian,
> > >
> > > On Sun, Apr 26, 2026 at 3:22 PM Adrian Klaver <
> [email protected]> wrote:
> > > >
> > > > On 4/26/26 1:15 PM, Igor Korot wrote:
> > > > > Hi, ALL,
> > > > > [quote]
> > > > > Thread 1 "dbhandler" hit Breakpoint 1,
> > > >
> > > > > 66 errorMsg.push_back( L"Error executing query: " +
> err );
> > > > > (gdb) p err
> > > > > $2 = L"ERROR: invalid byte sequence for encoding \"UTF8\":
> > > >
> > > > I would think the above is a clue.
> > > >
> > > > Are you sure the value you are passing to the parameter is UTF8?
> > >
> > > Positive.
> > >
> > > This is what the following line should be doing:
> > >
> > > [code]
> > > 57 strcpy( values[0], m_pimpl->m_myconv.to_bytes(
> > > name.c_str() ).c_str() );
> > > [/code]
> >
> > And the conversion is as follows:
> >
> > [code]
> > std::wstring_convert<std::codecvt_utf8<wchar_t> > m_myconv;
> > [/code]
> >
> > Thank you.
>
> Those are the values from gdb:
>
> [code]
> (gdb) p values[0]
> $1 = 0x603001613380 "test"
> (gdb) p strlen(values[0])
> $2 = 4
> (gdb)
> [/code]
>
> Thank you.
>
> >
> > >
> > > Thank you.
> > >
> > > >
> > > > > 0x00\nCONTEXT: unnamed portal parameter $1\n"
> > > > > (gdb)
> > > > > [/quote]
> > > > >
> > > > > What am I doing wrong?
> > > > >
> > > > > Thank you.
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Adrian Klaver
> > > > [email protected]
>
>
>
--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
@ 2026-04-26 22:17 ` Greg Sabino Mullane <[email protected]>
2026-04-26 22:59 ` Re: Why that query fails? Tom Lane <[email protected]>
1 sibling, 1 reply; 8+ messages in thread
From: Greg Sabino Mullane @ 2026-04-26 22:17 UTC (permalink / raw)
To: Igor Korot <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>
You are using binary format, but your length calculation is wrong:
int len1 = (int) name.length() * sizeof( wchar_t );
Just use text format for a query like this.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Why that query fails?
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
2026-04-26 22:17 ` Re: Why that query fails? Greg Sabino Mullane <[email protected]>
@ 2026-04-26 22:59 ` Tom Lane <[email protected]>
0 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2026-04-26 22:59 UTC (permalink / raw)
To: Greg Sabino Mullane <[email protected]>; +Cc: Igor Korot <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>
Greg Sabino Mullane <[email protected]> writes:
> You are using binary format, but your length calculation is wrong:
> int len1 = (int) name.length() * sizeof( wchar_t );
I think the actual problem is that he's trying to send an array
of wchar_t to the server. That is not bit-compatible with UTF-8,
even though they are both representations of Unicode. The query
string itself has the same problem I think (I believe the L"..."
syntax in C produces an array of wchar_t).
regards, tom lane
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2026-04-26 22:59 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-04-26 20:15 Why that query fails? Igor Korot <[email protected]>
2026-04-26 20:22 ` Adrian Klaver <[email protected]>
2026-04-26 20:34 ` Igor Korot <[email protected]>
2026-04-26 20:38 ` Igor Korot <[email protected]>
2026-04-26 22:06 ` Igor Korot <[email protected]>
2026-04-26 22:15 ` Ron Johnson <[email protected]>
2026-04-26 22:17 ` Greg Sabino Mullane <[email protected]>
2026-04-26 22:59 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox