Re: Using Postgres connection functions

2018-01-20 Thread Joe via Digitalmars-d-learn
On Saturday, 20 January 2018 at 04:54:47 UTC, Adam D. Ruppe wrote: Same as above. The general pattern is: C_Type[] name = new C_Type[](requested_size); // pass as `name.ptr`. This becomes a C_Type* Thanks, Adam. Perhaps something like this ought to make its way into the "D for C Programmers"

Re: Using Postgres connection functions

2018-01-19 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 20 January 2018 at 04:09:01 UTC, Joe wrote: extern(C) char * [2] pvs; foreach (i, val; paramValues) pvs[i] = cast(char *)toStringz(val); And then use "cast(const char **)pvs" for the paramValues argument. A slight improvement here that removes the need for any casts

Re: Using Postgres connection functions

2018-01-19 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 05:28:17 UTC, Joe wrote: Going beyond the connection, there are various other libpq functions that use a similar pattern of values passed using multiple parallel C arrays, e.g., PGresult *PQexecParams(PGconn *conn, const char *command,

Re: Using Postgres connection functions

2018-01-16 Thread Boris-Barboris via Digitalmars-d-learn
On Saturday, 13 January 2018 at 17:58:14 UTC, Joe wrote: ...ddb. The latter perhaps has the distinction that it doesn't use libpq, but rather implements the Postgres FE/BE protocol. That's a bit *too* native for my taste. It means the library maintainer has to keep up with changes to the

Re: Using Postgres connection functions

2018-01-15 Thread Joe via Digitalmars-d-learn
On Monday, 15 January 2018 at 02:28:29 UTC, Matthias Klumpp wrote: In any case, please don't start another Postgres library and consider contributing to one of the existing ones, so that we maybe have one really awesome, 100% complete library at some point. If, on the other hand, your goal

Re: Using Postgres connection functions

2018-01-14 Thread Matthias Klumpp via Digitalmars-d-learn
On Saturday, 13 January 2018 at 17:58:14 UTC, Joe wrote: On Saturday, 13 January 2018 at 10:10:41 UTC, Jacob Carlborg wrote: There's a native D library, ddb [1], for connecting to Postgres. Then you don't have to worry about null-terminated strings. There are several D libraries that I would

Re: Using Postgres connection functions

2018-01-13 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 10:10:41 UTC, Jacob Carlborg wrote: There's a native D library, ddb [1], for connecting to Postgres. Then you don't have to worry about null-terminated strings. There are several D libraries that I would consider "native": derelict-pq, dpq, dpq2 and ddb. The

Re: Using Postgres connection functions

2018-01-13 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-01-13 05:17, Joe wrote: I'm trying to learn how to use D to connect (and send queries) to Postgres, i.e., libpq in C. So my question is: is there an easier or better way of passing two arrays of C null-terminated strings to an extern(C) function? There's a native D library, ddb [1],

Re: Using Postgres connection functions

2018-01-12 Thread Joe via Digitalmars-d-learn
Going beyond the connection, there are various other libpq functions that use a similar pattern of values passed using multiple parallel C arrays, e.g., PGresult *PQexecParams(PGconn *conn, const char *command, int nParams,

Re: Using Postgres connection functions

2018-01-12 Thread Joe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 04:26:06 UTC, Adam D. Ruppe wrote: If and only if the values are known at compile time, you can do: const char** keywords = ["hostaddr".ptr, "port".ptr, "dbname".ptr, null].ptr; or even do it inline: PQconnectdbParams(["hostaddr".ptr, "port".ptr,

Re: Using Postgres connection functions

2018-01-12 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 13 January 2018 at 04:17:02 UTC, Joe wrote: It only compiled after I removed the second 'const' in the first and second arguments. Yeah, D's const applies down the chain automatically, so you don't write it twice there. string[] keywords = ["hostaddr", "port", "dbname"];