Write binary data as a file

Alexander Zhirov azhirov1991 at gmail.com
Tue Aug 2 11:10:27 UTC 2022


I'm trying to write a mechanism for writing and reading from 
Postgres.
Using the Adama D. Ruppe library. I write data to Postgres in the 
form of this code:
```d
ubyte[] bytes = cast(ubyte[])read("myFile");
PostgresResult resultQuery = cast(PostgresResult) 
db.query("insert into amts.t_client_xrdp_settings (pid_client, 
settings_file) values (?, ?)", id, bytes);
assert(resultQuery !is null);
```
Data appears in the database. Now I'm trying to do the reverse 
process. Get data from Postgres and create a file:
```d
auto result = db.query("select tcxs.settings_file as dbfile from 
amts.t_client_xrdp_settings tcxs where tcxs.pid_client = ?", id);
ubyte[] bytes = cast(ubyte[])result.front()["dbfile"];
write("newFile", bytes);
```
As a result, I get only a set of text data.
I am sure that my mechanism lacks refinement. It remains only to 
find out which one.


More information about the Digitalmars-d-learn mailing list