RejectedSoftware Forums

Sign up

Pages: 1 2

Re: PostgreSQL with Vibe.d?

On Tue, 17 Dec 2013 20:43:02 GMT, Luís Marques wrote:

I have ddb working, but I don't know how to pass parameters to queries (without concatenating strings, which is unsafe and awkward). That is, I'm looking for something like this:

PGCommand(conn, "SELECT * FROM foo WHERE bar = ?", barValue);

I had missed the right part of the source (I couldn't get dmd -D to work for postgres.d) where it says:

Examples:
---
// without spaces between $ and number
auto cmd = new PGCommand(conn, "INSERT INTO users (name, surname) VALUES ($ 1, $ 2)");
cmd.parameters.add(1, PGType.TEXT).value = "John";
cmd.parameters.add(2, PGType.TEXT).value = "Doe";

I had expected that one could pass the params directly in the ctor, like in my example.

Re: PostgreSQL with Vibe.d?

On Tue, 17 Dec 2013 20:43:02 GMT, Luís Marques wrote:

I have ddb working, but I don't know how to pass parameters to queries (without concatenating strings, which is unsafe and awkward). That is, I'm looking for something like this:

PGCommand(conn, "SELECT * FROM foo WHERE bar = ?", barValue);

Suggestions?

I can't get ddb working. I get this error

object.Exception@../../../home/visus/.dub/packages/vibe-d-master/source/vibe/core/drivers/libevent2_tcp.d(348): Connection error while reading from TCPConnection.
Error: Program exited with code 1

here is my code

import postgres.db;

this()
{
	auto pdb = new PostgresDB([
		"host" : "localhost",
		"database" : "mydb",
		"user" : "postgres",
		"password" : "postgres"
	]);
	auto conn = pdb.lockConnection();
	
	auto cmd = new PGCommand(conn, "SELECT typname, typlen FROM pg_type");
	auto result = cmd.executeQuery;
	
	try
	{
		foreach (row; result)
		{
			writeln(row["typname"], ", ", row[1]);
		}
	}
	finally
	{
		result.close;
	}
}

Re: PostgreSQL with Vibe.d?

On Wed, 18 Dec 2013 16:01:51 GMT, zhaopuming wrote:

I can't get ddb working. I get this error

object.Exception@../../../home/visus/.dub/packages/vibe-d-master/source/vibe/core/drivers/libevent2_tcp.d(348): Connection error while reading from TCPConnection.
Error: Program exited with code 1

Have you tried "shared this() { ... } " instead of "this() { ... }" ?

If that doesn't help, I got ddb's author (Piotr Szturmaj) email address, so maybe you can ask him: pszturmaj@tlen.pl

Re: PostgreSQL with Vibe.d?

On Wed, 18 Dec 2013 15:54:38 GMT, Luís Marques wrote:

On Tue, 17 Dec 2013 20:43:02 GMT, Luís Marques wrote:

I have ddb working, but I don't know how to pass parameters to queries (without concatenating strings, which is unsafe and awkward). That is, I'm looking for something like this:

PGCommand(conn, "SELECT * FROM foo WHERE bar = ?", barValue);

I had missed the right part of the source (I couldn't get dmd -D to work for postgres.d) where it says:

Examples:
---
// without spaces between $ and number
auto cmd = new PGCommand(conn, "INSERT INTO users (name, surname) VALUES ($ 1, $ 2)");
cmd.parameters.add(1, PGType.TEXT).value = "John";
cmd.parameters.add(2, PGType.TEXT).value = "Doe";

I had expected that one could pass the params directly in the ctor, like in my example.

I'd also open up an issue on github, Piotr may not be active enough here in the forum to see it.

But I agree with that sentiment, at least in a D API I'd expect that, too. Maybe even statically checked for validity with something like

auto cmd = makePGCommand!"INSERT INTO users (name, surname) VALUES ($1, $2)"("John", "Doe");

Re: PostgreSQL with Vibe.d?

On Thu, 19 Dec 2013 10:49:52 GMT, Sönke Ludwig wrote:

I'd also open up an issue on github, Piotr may not be active enough here in the forum to see it.

But I agree with that sentiment, at least in a D API I'd expect that, too. Maybe even statically checked for validity with something like

auto cmd = makePGCommand!"INSERT INTO users (name, surname) VALUES ($1, $2)"("John", "Doe");

I contacted Piotr. It seems that text parameters were not even implemented (but that wasn't caught because there was a bug with an 'assert("Not implemented")'). Adam Ruppe fixed the bugs, so that's working (although it seems that now you have to use Variant("John"), because of new @property behavior/possible bug). Piotr wants to redesign the whole parameter thing, so I don't know how that's going to proceed. I'll just say one thing: please support ranges in parameters. That way I can stream vibe's HTTP post directly into a param, instead of building a temporary buffer.

Pages: 1 2