1 Oct 2010 04:21
Re: libpq (C++) - Insert binary data
Christian Ullrich <chris <at> chrullrich.net>
2010-10-01 02:21:33 GMT
2010-10-01 02:21:33 GMT
* GOO Creations wrote:
> This is what I have until now to insert data
>
> char *query = "insert into table1 (bytes) values ($1)";
> QByteArray chip = <assignment of bytes>;
> const char *data = chip->data();
> const char* params[]={data};
> const int params_length[]={chip->length()};
> const int params_format[]={1};
> result = PQexecParams(mDatabase, query, 1, in_oid, params,
> params_length, params_format, 0);
>
> The first problem I have is that I'm not sure if const int
> params_length[]={chip->length()}; is the correct way to provide the
> length. Second of all, is this actually the correct way of doing it,
> isn't there a beter way?
It is certainly the simplest way of doing it in plain libpq, as long as
you're using the binary format (which you are doing here). According to
the documentation, QByteArray::length() returns the number of bytes in
the array, so it is the correct size.
I'm not sure if the (internal) binary format of bytea is guaranteed not
to change in future versions of PostgreSQL. Currently, as you obviously
found out yourself, it's pretty simple -- no transformation at all, the
binary format is just the data.
To make sure that your application supports any changes in future
versions, you should consider using the "hex" text format instead. See
(Continue reading)
> OTOH, if there's some remote possibility of some workaround solution for Windows to get PGXS and/or the
temporal extension installed, I'd be grateful if someone could help me along with it (further to your
below suggestions, since I'm floundering around in unfamiliar territory here).
I wonder how hard it would be to make MSVC build files for the
temporal extensions. IIRC it's a very simple project. Jeff - have you
looked at this?
--
Magnus Hagander
Me:
RSS Feed