ibarwick / fbsql

fbsql is a simple command-line client for the Firebird database, inspired by PostgreSQL's psql
10 stars 0 forks source link

UTF-8 in name of db file #1

Open mkgrgis opened 4 years ago

mkgrgis commented 4 years ago

in isql-fb

Use CONNECT or CREATE DATABASE to specify a database
SQL>CREATE DATABASE '/var/firebird/Пример.fdb' USER 'SYSDBA' PASSWORD 'masterkey' DEFAULT CHARACTER SET UTF8;

then

SQL> CONNECT '/var/firebird/Пример.fdb' USER 'SYSDBA' PASSWORD 'masterkey';
Database: '/var/firebird/Пример.fdb', User: SYSDBA
SQL>

but in bash

fbsql -d '/var/firebird/Пример.fdb' -u 'SYSDBA' -p 'masterkey';
fbsql 0.2.0
Error connecting to '/var/firebird/Пример.fdb' as 'SYSDBA'

Is this error of libfq lib?

mkgrgis commented 3 years ago

No problems with firebird_fdw for '/var/firebird/Пример.fdb' or '/tmp/テスト.fdb'. This issue really belongs to fbsql.

ibarwick commented 3 years ago

I can reproduce the issue.

I've modified the connection code to actually output the error message returned by Firebird:

$ ./src/fbsql -d localhost:/tmp/テスト.fdb -u sysdba -p masterkey
fbsql 0.2.0
Error connecting to 'localhost:/tmp/テスト.fdb' as 'sysdba'
Invalid connection string
 - Cannot transliterate character between character sets
 - Invalid or incomplete multibyte or wide character

The connection code in both fbsql and firebird_fdw basically does the same thing, the main difference is that in firebird_fdw the connection string is coming from within PostgreSQL, with fbsql it's coming from the shell environment. I can't see what difference that makes though, but obviously there's an issue somewhere.

mkgrgis commented 3 years ago

The ISC_DATABASE='/tmp/テスト.fdb' fbsql -u sysdba -p 'masterkey'; shell command is similar to fbsql -d localhost:/tmp/テスト.fdb -u sysdba -p masterkey by behaviour. Either the problem is in both cases of passing arguments, or not in passing arguments.

mkgrgis commented 1 year ago

Look like this problem is inside isc_attach_database but there is no problem if passing db_path form firebird_fdw. localhost prefix isn't critical.

mkgrgis commented 1 year ago

@ibarwick, what is external form of the database file string from PostgreSQL FDW API? For example near server_options.database.opt.strptr = &svr_database

Debug output gdb look like a problem between UTF-8, 1byte and wide character.

Error connecting to 'localhost:/tmp/テスト.fdb' as 'sysdba' in fbsql, but psql

set client_min_messages='debug3';
...
デバッグ:  server option: "address"
デバッグ:  server option: "database"
デバッグ:  path: localhost:/tmp/テスト.fdb
デバッグ:  client_encoding: "UTF8"
デバッグ:  firebirdGetConnection(): DB connection OK
デバッグ:  firebirdInstantiateConnection(): new firebird_fdw connection 0x564c2512fa10 for server "fb テスト"