1

I am trying to connect to a Firebird database using firebirdsql in Go (v1.14).

db_path := "D:\\DBs\\test.fdb"
conn, err := sql.Open("firebirdsql", ("sysdba:master@127.0.0.1:3050/" + db_path) )
err = conn.Ping()
if err != nil {
    fmt.Println("db.Ping failed:", err)
}

The code above works just fine but as soon as I introduce hash symbol (#) in the path (ex: db_path := "D:\\#DBs\\test.fdb"), I could not connect and firebirdsql complains that path is not valid (it reads the path up to the hash sign):

db.Ping failed: I/O error during "CreateFile (open)" operation for file "D:\"
Error while trying to open file
The system cannot find the path specified.

Is it a bug in firebirdsql or I am doing something wrong here?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
wiki
  • 1,877
  • 2
  • 31
  • 47
  • 1
    try replacing hash symbol with `%23` - https://stackoverflow.com/questions/5007352 / you may also abstract away (conseal from users and retain flexibility) the specific path and pass an identifier instead, see `c:\Program Files (x86)\Firebird\Firebird_2_1\aliases.conf` – Arioch 'The May 10 '20 at 21:53
  • 1
    this conversion - if it will fix things for you - is called `PathEscape` in Go jargon, according to https://yourbasic.org/golang/multiline-string/ – Arioch 'The May 10 '20 at 22:01
  • Replacing hash symbol with `%23` did the job. Thanks. – wiki May 11 '20 at 05:07
  • @Arioch'The Consider posting it as an answer. – Mark Rotteveel May 11 '20 at 16:03
  • Will anyone contact firebirdsql maintainers? We still do not know fi the bug is in wiki's program or in the driver (which was part of the question, and should be part of responsible programming regardless). I am at phone now, maybe i'll try to tomorrow. Go package reposotory docs did not say a thing on that. For comparison @MarkRotteveel JayBird also takes connection string as URIs, that is JDBC concept of things if i am not mistaken. What would JayBird do about symbols like # or % ? – Arioch 'The May 11 '20 at 20:32
  • Frankly, without investigating the intention i am more convinced to flag Duplicate rather than compose a well though out answer – Arioch 'The May 11 '20 at 20:33
  • @wiki - in general see "Reserved Character" section of URI standard - https://tools.ietf.org/html/rfc3986#section-2.2 - perhaps you'd be safer is you always call `PathEscape` on the filename – Arioch 'The May 12 '20 at 09:27
  • Request sent - https://github.com/nakagami/firebirdsql/issues/107 – Arioch 'The May 12 '20 at 09:34
  • @Arioch'The JDBC URLs are not technically URIs (or at least, the JDBC specification doesn't specify anything beyond having to start with `jdbc::`, the rest is driver-specific. And comparisons between drivers for other platforms is not a good route to infer behaviour. In any case, Jaybird doesn't use URL encoding, so that is not a valid comparison (although since Jaybird 4, it does support URL escapes in the query parameters because that was necessary to surface a new feature) – Mark Rotteveel May 12 '20 at 12:52
  • @MarkRotteveel i do not want comparison, i want uniformity :-) Though go driver maintainer has the final say – Arioch 'The May 12 '20 at 14:05

1 Answers1

0

Based on the comment by Arioch 'The:

Replace the hash symbol with %23 - How to escape hash character in URL. You may also abstract away (conceal from users and retain flexibility) the specific path and pass an identifier instead, see aliases.conf (Firebird 2.5 and earlier) or databases.conf (Firebird 3.0 and higher).

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197