/* Connects to a data source. This driver provides two ways to connect to a data source: (1) giving the connection parameters as a set of pairs separated by whitespaces in a string (first method parameter) (2) giving one string for each connection parameter, said datasource, username, password, host and port.  */
static int env_connect(lua_State *L)
/* Connects to a data source. This driver provides two ways to connect to a data source: (1) giving the connection parameters as a set of pairs separated by whitespaces in a string (first method parameter) (2) giving one string for each connection parameter, said datasource, username, password, host and port.  */
static int env_connect(lua_State *L)
{
		const char *username = luaL_optstring(L, 3, NULL);
		const char *password = luaL_optstring(L, 4, NULL);
		const char *pghost = luaL_optstring(L, 5, NULL);
		const char *pgport = luaL_optstring(L, 6, NULL);
		conn = PQsetdbLogin(pghost, pgport, NULL, NULL,
			sourcename, username, password);
	}
	if (PQstatus(conn) == CONNECTION_BAD)
		return luasql_faildirect(L, LUASQL_PREFIX"Error connecting to database.");
	PQsetNoticeProcessor(conn, notice_processor, NULL);
	return create_connection(L, 1, conn);
}