Skip to content

Commit

Permalink
Getting closer to a query running to end
Browse files Browse the repository at this point in the history
  • Loading branch information
heimir-sverrisson committed Apr 19, 2015
1 parent 35e52e2 commit de9c001
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 111 deletions.
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -34,10 +34,10 @@ PG_CPPFLAGS=-D'PKG_LIB_DIR=$(pkglibdir)' -I$(libpq_srcdir)

JFLAGS = -d $(pkglibdir)

# all:$(TRGTS)
all:$(TRGTS)

#JAVAFILES:
# javac $(JFLAGS) $(JAVA_SOURCES)
JAVAFILES:
javac $(JFLAGS) $(JAVA_SOURCES)

# the db name is hard-coded in the tests
override USE_MODULE_DB =
Expand Down
52 changes: 3 additions & 49 deletions connection.c
Expand Up @@ -19,6 +19,7 @@
#include "miscadmin.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "utils/elog.h"


/*
Expand Down Expand Up @@ -66,7 +67,6 @@ static bool xact_got_connection = false;
/* prototypes of private functions */
static Jconn *connect_jdbc_server(ForeignServer *server, UserMapping *user);
static void check_conn_params(const char **keywords, const char **values);
static void configure_remote_session(Jconn *conn);
static void do_sql_command(Jconn *conn, const char *sql);
static void begin_remote_xact(ConnCacheEntry *entry);
static void pgfdw_xact_callback(XactEvent event, void *arg);
Expand Down Expand Up @@ -194,7 +194,6 @@ connect_jdbc_server(ForeignServer *server, UserMapping *user)
const char **values;
int n;

ereport(DEBUG3, (errmsg("Entering connect_jdbc_server:")));
/*
* Construct connection params from generic options of ForeignServer
* and UserMapping. (Some of them might not be libpq options, in
Expand Down Expand Up @@ -256,9 +255,6 @@ connect_jdbc_server(ForeignServer *server, UserMapping *user)
errdetail("Non-superuser cannot connect if the server does not request a password."),
errhint("Target server's authentication method must be changed.")));

/* Prepare new session for use */
configure_remote_session(conn);

pfree(keywords);
pfree(values);
}
Expand Down Expand Up @@ -303,49 +299,6 @@ check_conn_params(const char **keywords, const char **values)
errdetail("Non-superusers must provide a password in the user mapping.")));
}

/*
* Issue SET commands to make sure remote session is configured properly.
*
* We do this just once at connection, assuming nothing will change the
* values later. Since we'll never send volatile function calls to the
* remote, there shouldn't be any way to break this assumption from our end.
* It's possible to think of ways to break it at the remote end, eg making
* a foreign table point to a view that includes a set_config call ---
* but once you admit the possibility of a malicious view definition,
* there are any number of ways to break things.
*/
static void
configure_remote_session(Jconn *conn)
{
int remoteversion = JQserverVersion(conn);

/* Force the search path to contain only pg_catalog (see deparse.c) */
do_sql_command(conn, "SET search_path = pg_catalog");

/*
* Set remote timezone; this is basically just cosmetic, since all
* transmitted and returned timestamptzs should specify a zone explicitly
* anyway. However it makes the regression test outputs more predictable.
*
* We don't risk setting remote zone equal to ours, since the remote
* server might use a different timezone database. Instead, use UTC
* (quoted, because very old servers are picky about case).
*/
do_sql_command(conn, "SET timezone = 'UTC'");

/*
* Set values needed to ensure unambiguous data output from remote. (This
* logic should match what pg_dump does. See also set_transmission_modes
* in jdbc2_fdw.c.)
*/
do_sql_command(conn, "SET datestyle = ISO");
if (remoteversion >= 80400)
do_sql_command(conn, "SET intervalstyle = postgres");
if (remoteversion >= 90000)
do_sql_command(conn, "SET extra_float_digits = 3");
else
do_sql_command(conn, "SET extra_float_digits = 2");
}

/*
* Convenience subroutine to issue a non-data-returning SQL command to remote
Expand All @@ -354,7 +307,6 @@ static void
do_sql_command(Jconn *conn, const char *sql)
{
Jresult *res;

res = JQexec(conn, sql);
if (JQresultStatus(res) != PGRES_COMMAND_OK)
pgfdw_report_error(ERROR, res, conn, true, sql);
Expand All @@ -376,6 +328,8 @@ begin_remote_xact(ConnCacheEntry *entry)
{
int curlevel = GetCurrentTransactionNestLevel();

//TODO: Replace this code with JDBC Connection call
return;
/* Start main transaction if we haven't yet */
if (entry->xact_depth <= 0)
{
Expand Down
10 changes: 9 additions & 1 deletion jdbc2_fdw.c
Expand Up @@ -36,6 +36,8 @@
#include "utils/guc.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/elog.h"


#include "storage/ipc.h"
#include "catalog/pg_foreign_server.h"
Expand Down Expand Up @@ -774,7 +776,7 @@ jdbcBeginForeignScan(ForeignScanState *node, int eflags)
/* Get private info created by planner functions. */
fsstate->query = strVal(list_nth(fsplan->fdw_private,
FdwScanPrivateSelectSql));
ereport(ERROR, (errmsg("\"local query = %s\"\n",fsstate->query)));
ereport(DEBUG3, (errmsg("local query = \"%s\"",fsstate->query)));
fsstate->retrieved_attrs = (List *) list_nth(fsplan->fdw_private,
FdwScanPrivateRetrievedAttrs);

Expand Down Expand Up @@ -1858,6 +1860,9 @@ fetch_more_data(ForeignScanState *node)
Jresult *volatile res = NULL;
MemoryContext oldcontext;

//TODO: Figure out what this is used for
return;

/*
* We'll store the tuples in the batch_cxt. First, flush the previous
* batch.
Expand Down Expand Up @@ -1982,6 +1987,9 @@ close_cursor(Jconn *conn, unsigned int cursor_number)
char sql[64];
Jresult *res;

//TODO: Make sure I don't need this at all
return;

snprintf(sql, sizeof(sql), "CLOSE c%u", cursor_number);

/*
Expand Down

0 comments on commit de9c001

Please sign in to comment.