October 05, 2020
On Monday, 5 October 2020 at 09:24:33 UTC, Mike Parker wrote:
> On Monday, 5 October 2020 at 09:05:16 UTC, Alaindevos wrote:
>
>> [...]
>
> You don't need to install dpq2 if you are using dub to build your project. Add it as a dependency to your dub.json (or dub.sdl if you prefer that format). When you build your project, dub will download the version you configured as your dependency and compile it along with your project.
>
> [...]

Thanks for this clear explanation. I'll try first using the dub tooling.
PS : Manual does not look easy with different versions in the /home/myhome/.dub/packages directory.
October 05, 2020
On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
> On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
>> On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
>>> [...]
>>
>> Take a look at:
>> https://code.dlang.org/packages/dpq2
>> https://code.dlang.org/packages/ddbc
>
> Say I want to use dpq2.
> Do I need to clone the git repository with "git clone ?"

No, you just dub add dpq2
October 05, 2020
On Monday, 5 October 2020 at 11:35:43 UTC, Imperatorn wrote:
> On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
>> On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
>>> On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
>>>> [...]
>>>
>>> Take a look at:
>>> https://code.dlang.org/packages/dpq2
>>> https://code.dlang.org/packages/ddbc
>>
>> Say I want to use dpq2.
>> Do I need to clone the git repository with "git clone ?"
>
> No, you just dub add dpq2

With dub.json:
"dependencies": {
		"dpq2": "~>1.0.17"
	},
It worked.
Something I ask myself is how do I pass a connection from one function to another.
...
string url=format("hostaddr='127.0.0.1' port='5432' dbname='%s' user='%s' password='%s'",db,user,pass);
 writeln(url);
Connection conn = new Connection(url);
auto answer = conn.exec("SELECT version()");
writeln(answer[0][0].as!PGtext);
...
myfunction(conn)

void myfunction( .... conn)
What is the type I should use for passing conn ?

October 05, 2020
On Monday, 5 October 2020 at 13:30:22 UTC, Alaindevos wrote:
> On Monday, 5 October 2020 at 11:35:43 UTC, Imperatorn wrote:
>> On Monday, 5 October 2020 at 08:47:45 UTC, Alaindevos wrote:
>>> On Monday, 5 October 2020 at 08:34:37 UTC, Imperatorn wrote:
>>>> On Monday, 5 October 2020 at 08:24:26 UTC, Alaindevos wrote:
>>>>> [...]
>>>>
>>>> Take a look at:
>>>> https://code.dlang.org/packages/dpq2
>>>> https://code.dlang.org/packages/ddbc
>>>
>>> Say I want to use dpq2.
>>> Do I need to clone the git repository with "git clone ?"
>>
>> No, you just dub add dpq2
>
> With dub.json:
> "dependencies": {
> 		"dpq2": "~>1.0.17"
> 	},
> It worked.
> Something I ask myself is how do I pass a connection from one function to another.
> ...
> string url=format("hostaddr='127.0.0.1' port='5432' dbname='%s' user='%s' password='%s'",db,user,pass);
>  writeln(url);
> Connection conn = new Connection(url);
> auto answer = conn.exec("SELECT version()");
> writeln(answer[0][0].as!PGtext);
> ...
> myfunction(conn)
>
> void myfunction( .... conn)
> What is the type I should use for passing conn ?

Maybe just Connection ?
October 05, 2020
Just Connection worked.
But how do I loop over results of a select statement.
string sql=format(" SELECT * from %s ;",tablepredata);
auto answer = conn.exec(sql);
foreach(arow; answer){
	writeln(arow);
}
Fails with,
dub ~master: building configuration "application"...
source/app.d(36,3): Error: invalid foreach aggregate answer, define opApply(), range primitives, or use .tupleof
/usr/local/bin/ldc2 failed with exit code 1.


October 05, 2020
answer[0][0].as!PGtext contains good data
October 05, 2020
On Monday, 5 October 2020 at 14:57:53 UTC, Alaindevos wrote:
> answer[0][0].as!PGtext contains good data
I found an answer.
>
foreach(rownumber; answer.length.iota){
auto arow=answer[rownumber];
writeln(arow);
}
>
Yet it would be nice to know why i can't iterate directly over answer using foreach.
October 05, 2020
On Monday, 5 October 2020 at 15:08:54 UTC, Alaindevos wrote:

>>
> Yet it would be nice to know why i can't iterate directly over answer using foreach.

Looking at the implementation of the `Answer` type [1], I see no way to create a range or a slice, and no `opApply`. So you'll have to ask the maintainer about that.

[1] https://github.com/denizzzka/dpq2/blob/master/src/dpq2/result.d#L107
October 05, 2020
On Monday, 5 October 2020 at 15:08:54 UTC, Alaindevos wrote:
> On Monday, 5 October 2020 at 14:57:53 UTC, Alaindevos wrote:
>> answer[0][0].as!PGtext contains good data
> I found an answer.
>>
> foreach(rownumber; answer.length.iota){
> auto arow=answer[rownumber];
> writeln(arow);
> }
>>
> Yet it would be nice to know why i can't iterate directly over answer using foreach.

Use "rangify" template to get forward range from answer
October 05, 2020
> Use "rangify" template to get forward range from answer
Thanks, this answers the question on programmatic level.
Yet I guess something is special with the answer datatype which makes foreach to fail.