Veil
|
Functions to simplify SPI-based queries. These are way more sophisticated than veil really needs but are nice and generic. More...
#include <stdio.h>
#include "postgres.h"
#include "catalog/pg_type.h"
#include "executor/spi.h"
#include "veil_version.h"
#include "access/xact.h"
#include "veil_funcs.h"
Go to the source code of this file.
Macros | |
#define | FETCH_SIZE 20 |
The number of records to fetch in one go from the query executor. | |
Typedefs | |
typedef bool() | Fetch_fn(HeapTuple, TupleDesc, void *) |
A Fetch_fn is a function that processes records, one at a time, returned from a query. | |
Functions | |
int | vl_spi_connect (bool *p_pushed) |
If already connected in this session, push the current connection, and get a new one. More... | |
int | vl_spi_finish (bool pushed) |
Reciprocal function for vl_spi_connect() | |
static void | prepare_query (const char *qry, int nargs, Oid *argtypes, Datum *args, bool read_only, void **saved_plan) |
Prepare a query for query(). More... | |
static int | query (const char *qry, int nargs, Oid *argtypes, Datum *args, bool read_only, void **saved_plan, Fetch_fn process_row, void *fn_param) |
Prepare and execute a query. More... | |
static bool | fetch_one_bool (HeapTuple tuple, TupleDesc tupdesc, void *p_result) |
Fetch_fn function for processing a single row of a single integer for query. More... | |
static bool | fetch_one_str (HeapTuple tuple, TupleDesc tupdesc, void *p_result) |
Fetch_fn function for processing a single row of a single integer for query. More... | |
bool | vl_bool_from_query (const char *qry, bool *result) |
Executes a query that returns a single bool value. More... | |
static bool | str_from_oid_query (const char *qry, const Oid param, char *result) |
Executes a query by oid, that returns a single string value. More... | |
bool | vl_db_exists (Oid db_id) |
Determine whether the given oid represents an existing database or not. More... | |
static bool | exec_init_fn (HeapTuple tuple, TupleDesc tupdesc, void *p_param) |
Fetch_fn function for executing registered veil_init() functions for query. More... | |
int | vl_call_init_fns (bool param) |
Identify any registered init_functions and execute them. More... | |
Functions to simplify SPI-based queries. These are way more sophisticated than veil really needs but are nice and generic.
Definition in file veil_query.c.
int vl_spi_connect | ( | bool * | p_pushed | ) |
If already connected in this session, push the current connection, and get a new one.
We are already connected, if:
Definition at line 46 of file veil_query.c.
Referenced by ensure_init(), exec_init_fn(), veil_perform_reset(), and vl_call_init_fns().
|
static |
Prepare a query for query().
This creates and executes a plan. The caller must have established SPI_connect. It is assumed that no parameters to the query will be null.
qry | The text of the SQL query to be performed. |
nargs | The number of input parameters ($1, $2, etc) to the query |
argtypes | Pointer to an array containing the OIDs of the data |
args | Actual parameters types of the parameters |
read_only | Whether the query should be read-only or not |
saved_plan | Adress of void pointer into which the query plan will be saved. Passing the same void pointer on a subsequent call will cause the saved query plan to be re-used. |
Definition at line 86 of file veil_query.c.
Referenced by query().
|
static |
Prepare and execute a query.
Query execution consists of a call to process_row for each returned record. Process_row can return a single value to the caller of this function through the fn_param parameter. It is the caller's responsibility to establish an SPI connection with SPI_connect. It is assumed that no parameters to the query, and no results will be null.
qry | The text of the SQL query to be performed. |
nargs | The number of input parameters ($1, $2, etc) to the query |
argtypes | Pointer to an array containing the OIDs of the data |
args | Actual parameters types of the parameters |
read_only | Whether the query should be read-only or not |
saved_plan | Adress of void pointer into which the query plan will be saved. Passing the same void pointer on a subsequent call will cause the saved query plan to be re-used. |
process_row | The Fetch_fn function to be called for each fetched row to process it. If this is null, we simply count the row, doing no processing on the tuples returned. |
fn_param | An optional parameter to the process_row function. This may be used to return a value to the caller. |
Definition at line 151 of file veil_query.c.
References prepare_query().
Referenced by str_from_oid_query(), vl_bool_from_query(), and vl_call_init_fns().
|
static |
Fetch_fn function for processing a single row of a single integer for query.
tuple | The row to be processed |
tupdesc | Descriptor for the types of the fields in the tuple. |
p_result | Pointer to an int4 variable into which the value returned from the query will be placed. |
Definition at line 194 of file veil_query.c.
Referenced by vl_bool_from_query().
|
static |
Fetch_fn function for processing a single row of a single integer for query.
tuple | The row to be processed |
tupdesc | Descriptor for the types of the fields in the tuple. |
p_result | Pointer to an int4 variable into which the value returned from the query will be placed. |
Definition at line 214 of file veil_query.c.
Referenced by str_from_oid_query().
bool vl_bool_from_query | ( | const char * | qry, |
bool * | result | ||
) |
Executes a query that returns a single bool value.
qry | The text of the query to be performed. |
result | Variable into which the result of the query will be placed. |
Definition at line 232 of file veil_query.c.
References fetch_one_bool(), and query().
Referenced by ensure_init(), exec_init_fn(), and veil_perform_reset().
|
static |
Executes a query by oid, that returns a single string value.
qry | The text of the query to be performed. |
param | The oid of the row to be fetched. |
result | Variable into which the result of the query will be placed. |
Definition at line 253 of file veil_query.c.
References fetch_one_str(), and query().
Referenced by vl_db_exists().
bool vl_db_exists | ( | Oid | db_id | ) |
Determine whether the given oid represents an existing database or not.
db_id | Oid of the database in which we are interested. |
Definition at line 275 of file veil_query.c.
References str_from_oid_query().
Referenced by get_shmem_context().
|
static |
Fetch_fn function for executing registered veil_init() functions for query.
tuple | The row to be processed |
tupdesc | Descriptor for the types of the fields in the tuple. |
p_param | Pointer to a boolean value which is the value of the argument to the init function being called. |
Definition at line 294 of file veil_query.c.
References vl_bool_from_query(), vl_spi_connect(), and vl_spi_finish().
Referenced by vl_call_init_fns().
int vl_call_init_fns | ( | bool | param | ) |
Identify any registered init_functions and execute them.
param | The boolean parameter to be passed to each init_function. |
Definition at line 336 of file veil_query.c.
References exec_init_fn(), query(), vl_spi_connect(), and vl_spi_finish().
Referenced by veil_init().