summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Kreen2009-04-02 11:30:47 +0000
committerMarko Kreen2009-04-02 14:00:13 +0000
commitcd9decda2095fe422b4fba2dc89a12edab39d2ae (patch)
treef029bc77abb0554bb6f91c6e3c1ce83dbdb33b8a
parent6630b5f26c9656cdceb3730621a26489761a2666 (diff)
sql/pgq: reindent C code
Several places had whitespace bugs, probably due to copy-paste. As there is no point keeping historical PG style around here, reindent with proper -kr -i8.
-rwxr-xr-xmisc/Cindent15
-rw-r--r--sql/pgq/lowlevel/insert_event.c64
-rw-r--r--sql/pgq/triggers/common.c84
-rw-r--r--sql/pgq/triggers/common.h4
-rw-r--r--sql/pgq/triggers/logtriga.c8
-rw-r--r--sql/pgq/triggers/logutriga.c21
-rw-r--r--sql/pgq/triggers/makesql.c133
-rw-r--r--sql/pgq/triggers/sqltriga.c8
-rw-r--r--sql/pgq/triggers/stringutil.c48
-rw-r--r--sql/pgq/triggers/stringutil.h5
10 files changed, 170 insertions, 220 deletions
diff --git a/misc/Cindent b/misc/Cindent
new file mode 100755
index 00000000..d6349c90
--- /dev/null
+++ b/misc/Cindent
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+PARAM="-npro -kr -i8 -ts8 -sob -l120 -ss -ncs -cp1"
+PARAM="-npro -kr -i8 -ts8 -nsob -l80 -ss -ncs -cp1 -il0"
+PARAM="-npro -kr -i8 -ts8 -nsob -hnl -l110 -ss -ncs -cp1 -il0"
+
+for t in Datum PgqTriggerEvent TriggerData uint8 uint32 uint64 \
+ StringInfo Oid TransactionId
+do
+ PARAM="$PARAM -T $t"
+done
+
+echo indent $PARAM "$@"
+indent $PARAM "$@"
+
diff --git a/sql/pgq/lowlevel/insert_event.c b/sql/pgq/lowlevel/insert_event.c
index 5431c0cc..87f5ad1b 100644
--- a/sql/pgq/lowlevel/insert_event.c
+++ b/sql/pgq/lowlevel/insert_event.c
@@ -50,8 +50,8 @@ PG_FUNCTION_INFO_V1(pgq_insert_event_raw);
" queue_disable_insert::bool" \
" from pgq.queue where queue_name = $1"
#define COL_QUEUE_ID 1
-#define COL_PREFIX 2
-#define COL_TBLNO 3
+#define COL_PREFIX 2
+#define COL_TBLNO 3
#define COL_EVENT_ID 4
#define COL_DISABLED 5
@@ -59,7 +59,7 @@ PG_FUNCTION_INFO_V1(pgq_insert_event_raw);
* Plan cache entry in HTAB.
*/
struct InsertCacheEntry {
- Oid queue_id; /* actually int32, but we want to use oid_hash */
+ Oid queue_id; /* actually int32, but we want to use oid_hash */
int cur_table;
void *plan;
};
@@ -84,14 +84,13 @@ static HTAB *insert_cache;
/*
* Prepare utility plans and plan cache.
*/
-static void
-init_cache(void)
+static void init_cache(void)
{
static int init_done = 0;
Oid types[1] = { TEXTOID };
- HASHCTL ctl;
- int flags;
- int max_queues = 128;
+ HASHCTL ctl;
+ int flags;
+ int max_queues = 128;
if (init_done)
return;
@@ -133,9 +132,9 @@ static void *make_plan(struct QueueState *state)
*/
sql = makeStringInfo();
appendStringInfo(sql, "insert into %s_%d (ev_id, ev_time, ev_owner, ev_retry,"
- " ev_type, ev_data, ev_extra1, ev_extra2, ev_extra3, ev_extra4)"
- " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
- state->table_prefix, state->cur_table);
+ " ev_type, ev_data, ev_extra1, ev_extra2, ev_extra3, ev_extra4)"
+ " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)",
+ state->table_prefix, state->cur_table);
/*
* create plan
*/
@@ -148,20 +147,19 @@ static void *make_plan(struct QueueState *state)
*/
static void *load_insert_plan(struct QueueState *state)
{
- struct InsertCacheEntry *entry;
- Oid queue_id = state->queue_id;
- bool did_exist = false;
-
- entry = hash_search(insert_cache, &queue_id, HASH_ENTER, &did_exist);
- if (did_exist)
- {
- if (state->cur_table == entry->cur_table)
- return entry->plan;
- SPI_freeplan(entry->plan);
- }
- entry->cur_table = state->cur_table;
- entry->plan = make_plan(state);
- return entry->plan;
+ struct InsertCacheEntry *entry;
+ Oid queue_id = state->queue_id;
+ bool did_exist = false;
+
+ entry = hash_search(insert_cache, &queue_id, HASH_ENTER, &did_exist);
+ if (did_exist) {
+ if (state->cur_table == entry->cur_table)
+ return entry->plan;
+ SPI_freeplan(entry->plan);
+ }
+ entry->cur_table = state->cur_table;
+ entry->plan = make_plan(state);
+ return entry->plan;
}
/*
@@ -171,8 +169,8 @@ static void load_queue_info(Datum queue_name, struct QueueState *state)
{
Datum values[1];
int res;
- TupleDesc desc;
- HeapTuple row;
+ TupleDesc desc;
+ HeapTuple row;
bool isnull;
values[0] = queue_name;
@@ -203,9 +201,9 @@ static void load_queue_info(Datum queue_name, struct QueueState *state)
/*
* Arguments:
- * 0: queue_name text NOT NULL
- * 1: ev_id int8 if NULL take from SEQ
- * 2: ev_time timestamptz if NULL use now()
+ * 0: queue_name text NOT NULL
+ * 1: ev_id int8 if NULL take from SEQ
+ * 2: ev_time timestamptz if NULL use now()
* 3: ev_owner int4
* 4: ev_retry int4
* 5: ev_type text
@@ -215,8 +213,7 @@ static void load_queue_info(Datum queue_name, struct QueueState *state)
* 9: ev_extra3 text
* 10:ev_extra4 text
*/
-Datum
-pgq_insert_event_raw(PG_FUNCTION_ARGS)
+Datum pgq_insert_event_raw(PG_FUNCTION_ARGS)
{
Datum values[11];
char nulls[11];
@@ -233,7 +230,7 @@ pgq_insert_event_raw(PG_FUNCTION_ARGS)
if (SPI_connect() < 0)
elog(ERROR, "SPI_connect() failed");
-
+
init_cache();
load_queue_info(PG_GETARG_DATUM(0), &state);
@@ -287,4 +284,3 @@ pgq_insert_event_raw(PG_FUNCTION_ARGS)
PG_RETURN_INT64(ret_id);
}
-
diff --git a/sql/pgq/triggers/common.c b/sql/pgq/triggers/common.c
index 7783d73c..883bbfa5 100644
--- a/sql/pgq/triggers/common.c
+++ b/sql/pgq/triggers/common.c
@@ -44,11 +44,10 @@ PG_MODULE_MAGIC;
static MemoryContext tbl_cache_ctx;
static HTAB *tbl_cache_map;
-static const char pkey_sql [] =
- "SELECT k.attnum, k.attname FROM pg_index i, pg_attribute k"
- " WHERE i.indrelid = $1 AND k.attrelid = i.indexrelid"
- " AND i.indisprimary AND k.attnum > 0 AND NOT k.attisdropped"
- " ORDER BY k.attnum";
+static const char pkey_sql[] =
+ "SELECT k.attnum, k.attname FROM pg_index i, pg_attribute k"
+ " WHERE i.indrelid = $1 AND k.attrelid = i.indexrelid"
+ " AND i.indisprimary AND k.attnum > 0 AND NOT k.attisdropped" " ORDER BY k.attnum";
static void *pkey_plan;
static void relcache_reset_cb(Datum arg, Oid relid);
@@ -67,7 +66,7 @@ void pgq_simple_insert(const char *queue_name, Datum ev_type, Datum ev_data, Dat
if (!plan) {
const char *sql;
- Oid types[5] = { TEXTOID, TEXTOID, TEXTOID, TEXTOID, TEXTOID };
+ Oid types[5] = { TEXTOID, TEXTOID, TEXTOID, TEXTOID, TEXTOID };
sql = "select pgq.insert_event($1, $2, $3, $4, $5, null, null)";
plan = SPI_saveplan(SPI_prepare(sql, 5, types));
@@ -92,26 +91,23 @@ void pgq_simple_insert(const char *queue_name, Datum ev_type, Datum ev_data, Dat
void pgq_insert_tg_event(PgqTriggerEvent *ev)
{
pgq_simple_insert(ev->queue_name,
- pgq_finish_varbuf(ev->ev_type),
- pgq_finish_varbuf(ev->ev_data),
- pgq_finish_varbuf(ev->ev_extra1),
- ev->ev_extra2
- ? pgq_finish_varbuf(ev->ev_extra2)
- : (Datum)0);
+ pgq_finish_varbuf(ev->ev_type),
+ pgq_finish_varbuf(ev->ev_data),
+ pgq_finish_varbuf(ev->ev_extra1),
+ ev->ev_extra2 ? pgq_finish_varbuf(ev->ev_extra2) : (Datum)0);
}
char *pgq_find_table_name(Relation rel)
{
- NameData tname = rel->rd_rel->relname;
- Oid nsoid = rel->rd_rel->relnamespace;
- char namebuf[NAMEDATALEN * 2 + 3];
- HeapTuple ns_tup;
+ NameData tname = rel->rd_rel->relname;
+ Oid nsoid = rel->rd_rel->relnamespace;
+ char namebuf[NAMEDATALEN * 2 + 3];
+ HeapTuple ns_tup;
Form_pg_namespace ns_struct;
- NameData nspname;
+ NameData nspname;
/* find namespace info */
- ns_tup = SearchSysCache(NAMESPACEOID,
- ObjectIdGetDatum(nsoid), 0, 0, 0);
+ ns_tup = SearchSysCache(NAMESPACEOID, ObjectIdGetDatum(nsoid), 0, 0, 0);
if (!HeapTupleIsValid(ns_tup))
elog(ERROR, "Cannot find namespace %u", nsoid);
ns_struct = (Form_pg_namespace) GETSTRUCT(ns_tup);
@@ -124,8 +120,7 @@ char *pgq_find_table_name(Relation rel)
return pstrdup(namebuf);
}
-static void
-init_pkey_plan(void)
+static void init_pkey_plan(void)
{
Oid types[1] = { OIDOID };
pkey_plan = SPI_saveplan(SPI_prepare(pkey_sql, 1, types));
@@ -133,12 +128,11 @@ init_pkey_plan(void)
elog(ERROR, "pgq_triggers: SPI_prepare() failed");
}
-static void
-init_cache(void)
+static void init_cache(void)
{
- HASHCTL ctl;
- int flags;
- int max_tables = 128;
+ HASHCTL ctl;
+ int flags;
+ int max_tables = 128;
/*
* create own context
@@ -148,6 +142,7 @@ init_cache(void)
ALLOCSET_SMALL_MINSIZE,
ALLOCSET_SMALL_INITSIZE,
ALLOCSET_SMALL_MAXSIZE);
+
/*
* init pkey cache.
*/
@@ -162,8 +157,7 @@ init_cache(void)
/*
* Prepare utility plans and plan cache.
*/
-static void
-init_module(void)
+static void init_module(void)
{
static int callback_init = 0;
@@ -185,8 +179,7 @@ init_module(void)
}
}
-static void
-full_reset(void)
+static void full_reset(void)
{
if (tbl_cache_ctx) {
/* needed only if backend has HASH_STATISTICS set */
@@ -200,8 +193,7 @@ full_reset(void)
/*
* Fill table information in hash table.
*/
-static struct PgqTableInfo *
-fill_tbl_info(Relation rel)
+static struct PgqTableInfo *fill_tbl_info(Relation rel)
{
struct PgqTableInfo *info;
StringInfo pkeys;
@@ -250,8 +242,7 @@ fill_tbl_info(Relation rel)
return info;
}
-static void
-free_info(struct PgqTableInfo *info)
+static void free_info(struct PgqTableInfo *info)
{
pfree(info->table_name);
pfree(info->pkey_attno);
@@ -263,11 +254,11 @@ static void relcache_reset_cb(Datum arg, Oid relid)
if (relid == InvalidOid) {
full_reset();
} else if (tbl_cache_map) {
- struct PgqTableInfo *entry;
- entry = hash_search(tbl_cache_map, &relid, HASH_FIND, NULL);
+ struct PgqTableInfo *entry;
+ entry = hash_search(tbl_cache_map, &relid, HASH_FIND, NULL);
if (entry) {
free_info(entry);
- hash_search(tbl_cache_map, &relid, HASH_REMOVE, NULL);
+ hash_search(tbl_cache_map, &relid, HASH_REMOVE, NULL);
}
}
}
@@ -275,8 +266,7 @@ static void relcache_reset_cb(Datum arg, Oid relid)
/*
* fetch insert plan from cache.
*/
-struct PgqTableInfo *
-pgq_find_table_info(Relation rel)
+struct PgqTableInfo *pgq_find_table_info(Relation rel)
{
struct PgqTableInfo *entry;
@@ -289,8 +279,7 @@ pgq_find_table_info(Relation rel)
return entry;
}
-static void
-parse_newstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
+static void parse_newstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
{
int i;
/*
@@ -313,8 +302,7 @@ parse_newstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
}
}
-static void
-parse_oldstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
+static void parse_oldstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
{
const char *kpos;
int attcnt, i;
@@ -327,15 +315,14 @@ parse_oldstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
ev->attkind = tg->tg_trigger->tgargs[1];
ev->attkind_len = strlen(ev->attkind);
if (tg->tg_trigger->tgnargs > 2)
- ev->table_name = tg->tg_trigger->tgargs[2];
+ ev->table_name = tg->tg_trigger->tgargs[2];
/*
* Count number of active columns
*/
tupdesc = tg->tg_relation->rd_att;
- for (i = 0, attcnt = 0; i < tupdesc->natts; i++)
- {
+ for (i = 0, attcnt = 0; i < tupdesc->natts; i++) {
if (!tupdesc->attrs[i]->attisdropped)
attcnt++;
}
@@ -361,7 +348,7 @@ void pgq_prepare_event(struct PgqTriggerEvent *ev, TriggerData *tg, bool newstyl
* Check trigger calling conventions
*/
if (!TRIGGER_FIRED_AFTER(tg->tg_event))
- /* dont care */;
+ /* dont care */ ;
if (!TRIGGER_FIRED_FOR_ROW(tg->tg_event))
elog(ERROR, "pgq trigger must be fired FOR EACH ROW");
if (tg->tg_trigger->tgnargs < 1)
@@ -400,7 +387,7 @@ void pgq_prepare_event(struct PgqTriggerEvent *ev, TriggerData *tg, bool newstyl
ev->ev_type = pgq_init_varbuf();
ev->ev_data = pgq_init_varbuf();
ev->ev_extra1 = pgq_init_varbuf();
-
+
/*
* Do the backup, if requested.
*/
@@ -467,4 +454,3 @@ bool pgq_is_logging_disabled(void)
#endif
return false;
}
-
diff --git a/sql/pgq/triggers/common.h b/sql/pgq/triggers/common.h
index 5be441b1..957a02df 100644
--- a/sql/pgq/triggers/common.h
+++ b/sql/pgq/triggers/common.h
@@ -42,7 +42,8 @@ struct PgqTableInfo {
struct PgqTableInfo *pgq_find_table_info(Relation rel);
void pgq_prepare_event(struct PgqTriggerEvent *ev, TriggerData *tg, bool newstyle);
char *pgq_find_table_name(Relation rel);
-void pgq_simple_insert(const char *queue_name, Datum ev_type, Datum ev_data, Datum ev_extra1, Datum ev_extra2);
+void pgq_simple_insert(const char *queue_name, Datum ev_type, Datum ev_data, Datum ev_extra1,
+ Datum ev_extra2);
bool pgqtriga_skip_col(PgqTriggerEvent *ev, TriggerData *tg, int i, int attkind_idx);
bool pgqtriga_is_pkey(PgqTriggerEvent *ev, TriggerData *tg, int i, int attkind_idx);
void pgq_insert_tg_event(PgqTriggerEvent *ev);
@@ -54,4 +55,3 @@ int pgqtriga_make_sql(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql);
/* logutriga.c */
void pgq_urlenc_row(PgqTriggerEvent *ev, TriggerData *tg, HeapTuple row, StringInfo buf);
-
diff --git a/sql/pgq/triggers/logtriga.c b/sql/pgq/triggers/logtriga.c
index b724dd60..0b2e544b 100644
--- a/sql/pgq/triggers/logtriga.c
+++ b/sql/pgq/triggers/logtriga.c
@@ -39,11 +39,10 @@ Datum pgq_logtriga(PG_FUNCTION_ARGS);
* ev_extra1 - table name
*/
-Datum
-pgq_logtriga(PG_FUNCTION_ARGS)
+Datum pgq_logtriga(PG_FUNCTION_ARGS)
{
TriggerData *tg;
- PgqTriggerEvent ev;
+ PgqTriggerEvent ev;
/*
* Get the trigger call context
@@ -51,7 +50,7 @@ pgq_logtriga(PG_FUNCTION_ARGS)
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "pgq.logutriga not called as trigger");
- tg = (TriggerData *) (fcinfo->context);
+ tg = (TriggerData *)(fcinfo->context);
if (!TRIGGER_FIRED_AFTER(tg->tg_event))
elog(ERROR, "pgq.logtriga must be fired AFTER");
@@ -82,4 +81,3 @@ pgq_logtriga(PG_FUNCTION_ARGS)
skip_it:
return PointerGetDatum(NULL);
}
-
diff --git a/sql/pgq/triggers/logutriga.c b/sql/pgq/triggers/logutriga.c
index 1dac75a5..37506aa7 100644
--- a/sql/pgq/triggers/logutriga.c
+++ b/sql/pgq/triggers/logutriga.c
@@ -27,17 +27,15 @@
PG_FUNCTION_INFO_V1(pgq_logutriga);
Datum pgq_logutriga(PG_FUNCTION_ARGS);
-void
-pgq_urlenc_row(PgqTriggerEvent *ev, TriggerData *tg, HeapTuple row, StringInfo buf)
+void pgq_urlenc_row(PgqTriggerEvent *ev, TriggerData *tg, HeapTuple row, StringInfo buf)
{
- TupleDesc tupdesc = tg->tg_relation->rd_att;
+ TupleDesc tupdesc = tg->tg_relation->rd_att;
bool first = true;
int i;
const char *col_ident, *col_value;
int attkind_idx = -1;
- for (i = 0; i < tg->tg_relation->rd_att->natts; i++)
- {
+ for (i = 0; i < tg->tg_relation->rd_att->natts; i++) {
/* Skip dropped columns */
if (tupdesc->attrs[i]->attisdropped)
continue;
@@ -58,8 +56,7 @@ pgq_urlenc_row(PgqTriggerEvent *ev, TriggerData *tg, HeapTuple row, StringInfo b
/* quote column value */
col_value = SPI_getvalue(row, tupdesc, i + 1);
- if (col_value != NULL)
- {
+ if (col_value != NULL) {
appendStringInfoChar(buf, '=');
pgq_encode_cstring(buf, col_value, TBUF_QUOTE_URLENC);
}
@@ -76,12 +73,11 @@ pgq_urlenc_row(PgqTriggerEvent *ev, TriggerData *tg, HeapTuple row, StringInfo b
* ev_extra1 - table name
* ev_extra2 - optional urlencoded backup
*/
-Datum
-pgq_logutriga(PG_FUNCTION_ARGS)
+Datum pgq_logutriga(PG_FUNCTION_ARGS)
{
TriggerData *tg;
- struct PgqTriggerEvent ev;
- HeapTuple row;
+ struct PgqTriggerEvent ev;
+ HeapTuple row;
/*
* Get the trigger call context
@@ -89,7 +85,7 @@ pgq_logutriga(PG_FUNCTION_ARGS)
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "pgq.logutriga not called as trigger");
- tg = (TriggerData *) (fcinfo->context);
+ tg = (TriggerData *)(fcinfo->context);
if (TRIGGER_FIRED_BY_UPDATE(tg->tg_event))
row = tg->tg_newtuple;
else
@@ -134,4 +130,3 @@ skip_it:
else
return PointerGetDatum(row);
}
-
diff --git a/sql/pgq/triggers/makesql.c b/sql/pgq/triggers/makesql.c
index 067b27e7..e9b1ca85 100644
--- a/sql/pgq/triggers/makesql.c
+++ b/sql/pgq/triggers/makesql.c
@@ -32,8 +32,7 @@
#include "stringutil.h"
-static void
-append_key_eq(StringInfo buf, const char *col_ident, const char *col_value)
+static void append_key_eq(StringInfo buf, const char *col_ident, const char *col_value)
{
if (col_value == NULL)
elog(ERROR, "logtriga: Unexpected NULL key value");
@@ -43,8 +42,7 @@ append_key_eq(StringInfo buf, const char *col_ident, const char *col_value)
pgq_encode_cstring(buf, col_value, TBUF_QUOTE_LITERAL);
}
-static void
-append_normal_eq(StringInfo buf, const char *col_ident, const char *col_value)
+static void append_normal_eq(StringInfo buf, const char *col_ident, const char *col_value)
{
pgq_encode_cstring(buf, col_ident, TBUF_QUOTE_IDENT);
appendStringInfoChar(buf, '=');
@@ -54,22 +52,20 @@ append_normal_eq(StringInfo buf, const char *col_ident, const char *col_value)
appendStringInfoString(buf, "NULL");
}
-static void
-process_insert(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
+static void process_insert(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
{
- HeapTuple new_row = tg->tg_trigtuple;
- TupleDesc tupdesc = tg->tg_relation->rd_att;
- int i;
- int need_comma = false;
- int attkind_idx;
+ HeapTuple new_row = tg->tg_trigtuple;
+ TupleDesc tupdesc = tg->tg_relation->rd_att;
+ int i;
+ int need_comma = false;
+ int attkind_idx;
/*
* Specify all the columns
*/
appendStringInfoChar(sql, '(');
attkind_idx = -1;
- for (i = 0; i < tupdesc->natts; i++)
- {
+ for (i = 0; i < tupdesc->natts; i++) {
char *col_ident;
/* Skip dropped columns */
@@ -101,8 +97,7 @@ process_insert(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
*/
need_comma = false;
attkind_idx = -1;
- for (i = 0; i < tupdesc->natts; i++)
- {
+ for (i = 0; i < tupdesc->natts; i++) {
char *col_value;
/* Skip dropped columns */
@@ -133,28 +128,26 @@ process_insert(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
appendStringInfoChar(sql, ')');
}
-static int
-process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
+static int process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
{
- HeapTuple old_row = tg->tg_trigtuple;
- HeapTuple new_row = tg->tg_newtuple;
- TupleDesc tupdesc = tg->tg_relation->rd_att;
- Datum old_value;
- Datum new_value;
- bool old_isnull;
- bool new_isnull;
-
- char *col_ident;
- char *col_value;
- int i;
- int need_comma = false;
- int need_and = false;
- int attkind_idx;
- int ignore_count = 0;
+ HeapTuple old_row = tg->tg_trigtuple;
+ HeapTuple new_row = tg->tg_newtuple;
+ TupleDesc tupdesc = tg->tg_relation->rd_att;
+ Datum old_value;
+ Datum new_value;
+ bool old_isnull;
+ bool new_isnull;
+
+ char *col_ident;
+ char *col_value;
+ int i;
+ int need_comma = false;
+ int need_and = false;
+ int attkind_idx;
+ int ignore_count = 0;
attkind_idx = -1;
- for (i = 0; i < tupdesc->natts; i++)
- {
+ for (i = 0; i < tupdesc->natts; i++) {
/*
* Ignore dropped columns
*/
@@ -176,10 +169,9 @@ process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
* If both are NOT NULL, we need to compare the values and skip
* setting the column if equal
*/
- if (!old_isnull && !new_isnull)
- {
- Oid opr_oid;
- FmgrInfo *opr_finfo_p;
+ if (!old_isnull && !new_isnull) {
+ Oid opr_oid;
+ FmgrInfo *opr_finfo_p;
/*
* Lookup the equal operators function call info using the
@@ -188,7 +180,7 @@ process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
TypeCacheEntry *type_cache;
type_cache = lookup_type_cache(SPI_gettypeid(tupdesc, i + 1),
- TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO);
+ TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO);
opr_oid = type_cache->eq_opr;
if (opr_oid == ARRAY_EQ_OP)
opr_oid = InvalidOid;
@@ -200,24 +192,19 @@ process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
* comparision. Else get the string representation of both
* attributes and do string comparision.
*/
- if (OidIsValid(opr_oid))
- {
- if (DatumGetBool(FunctionCall2(opr_finfo_p,
- old_value, new_value)))
+ if (OidIsValid(opr_oid)) {
+ if (DatumGetBool(FunctionCall2(opr_finfo_p, old_value, new_value)))
continue;
- }
- else
- {
- char *old_strval = SPI_getvalue(old_row, tupdesc, i + 1);
- char *new_strval = SPI_getvalue(new_row, tupdesc, i + 1);
+ } else {
+ char *old_strval = SPI_getvalue(old_row, tupdesc, i + 1);
+ char *new_strval = SPI_getvalue(new_row, tupdesc, i + 1);
if (strcmp(old_strval, new_strval) == 0)
continue;
}
}
- if (pgqtriga_skip_col(ev, tg, i, attkind_idx))
- {
+ if (pgqtriga_skip_col(ev, tg, i, attkind_idx)) {
/* this change should be ignored */
ignore_count++;
continue;
@@ -241,14 +228,12 @@ process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
* with it's old value to simulate the same for the replication
* engine.
*/
- if (!need_comma)
- {
+ if (!need_comma) {
/* there was change in ignored columns, skip whole event */
if (ignore_count > 0)
return 0;
- for (i = 0, attkind_idx = -1; i < tupdesc->natts; i++)
- {
+ for (i = 0, attkind_idx = -1; i < tupdesc->natts; i++) {
if (tupdesc->attrs[i]->attisdropped)
continue;
@@ -264,8 +249,7 @@ process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
appendStringInfoString(sql, " where ");
- for (i = 0, attkind_idx = -1; i < tupdesc->natts; i++)
- {
+ for (i = 0, attkind_idx = -1; i < tupdesc->natts; i++) {
/*
* Ignore dropped columns
*/
@@ -289,19 +273,17 @@ process_update(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
return 1;
}
-static void
-process_delete(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
+static void process_delete(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
{
- HeapTuple old_row = tg->tg_trigtuple;
- TupleDesc tupdesc = tg->tg_relation->rd_att;
- char *col_ident;
- char *col_value;
- int i;
- int need_and = false;
- int attkind_idx;
-
- for (i = 0, attkind_idx = -1; i < tupdesc->natts; i++)
- {
+ HeapTuple old_row = tg->tg_trigtuple;
+ TupleDesc tupdesc = tg->tg_relation->rd_att;
+ char *col_ident;
+ char *col_value;
+ int i;
+ int need_and = false;
+ int attkind_idx;
+
+ for (i = 0, attkind_idx = -1; i < tupdesc->natts; i++) {
if (tupdesc->attrs[i]->attisdropped)
continue;
@@ -320,21 +302,19 @@ process_delete(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
}
}
-int
-pgqtriga_make_sql(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
+int pgqtriga_make_sql(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
{
- TupleDesc tupdesc;
- int i;
- int attcnt;
- int need_event = 1;
+ TupleDesc tupdesc;
+ int i;
+ int attcnt;
+ int need_event = 1;
tupdesc = tg->tg_relation->rd_att;
/*
* Count number of active columns
*/
- for (i = 0, attcnt = 0; i < tupdesc->natts; i++)
- {
+ for (i = 0, attcnt = 0; i < tupdesc->natts; i++) {
if (tupdesc->attrs[i]->attisdropped)
continue;
attcnt++;
@@ -357,4 +337,3 @@ pgqtriga_make_sql(PgqTriggerEvent *ev, TriggerData *tg, StringInfo sql)
return need_event;
}
-
diff --git a/sql/pgq/triggers/sqltriga.c b/sql/pgq/triggers/sqltriga.c
index 6dbb1cd1..3ccfb50a 100644
--- a/sql/pgq/triggers/sqltriga.c
+++ b/sql/pgq/triggers/sqltriga.c
@@ -37,11 +37,10 @@ Datum pgq_sqltriga(PG_FUNCTION_ARGS);
* ev_extra1 - table name
* ev_extra2 - optional urlencoded backup
*/
-Datum
-pgq_sqltriga(PG_FUNCTION_ARGS)
+Datum pgq_sqltriga(PG_FUNCTION_ARGS)
{
TriggerData *tg;
- PgqTriggerEvent ev;
+ PgqTriggerEvent ev;
/*
* Get the trigger call context
@@ -49,7 +48,7 @@ pgq_sqltriga(PG_FUNCTION_ARGS)
if (!CALLED_AS_TRIGGER(fcinfo))
elog(ERROR, "pgq.logutriga not called as trigger");
- tg = (TriggerData *) (fcinfo->context);
+ tg = (TriggerData *)(fcinfo->context);
if (pgq_is_logging_disabled())
goto skip_it;
@@ -86,4 +85,3 @@ skip_it:
else
return PointerGetDatum(tg->tg_trigtuple);
}
-
diff --git a/sql/pgq/triggers/stringutil.c b/sql/pgq/triggers/stringutil.c
index c314b19e..ebd5b098 100644
--- a/sql/pgq/triggers/stringutil.c
+++ b/sql/pgq/triggers/stringutil.c
@@ -53,7 +53,7 @@ bool pgq_strlist_contains(const char *liststr, const char *str)
{
int c, len = strlen(str);
const char *p, *listpos = liststr;
-
+
loop:
/* find string fragment, later check if actual token */
p = strstr(listpos, str);
@@ -95,10 +95,9 @@ static int pgq_urlencode(char *dst, const uint8 *src, int srclen)
if (c == ' ') {
*p++ = '+';
} else if ((c >= '0' && c <= '9')
- || (c >= 'A' && c <= 'Z')
- || (c >= 'a' && c <= 'z')
- || c == '_' || c == '.')
- {
+ || (c >= 'A' && c <= 'Z')
+ || (c >= 'a' && c <= 'z')
+ || c == '_' || c == '.') {
*p++ = c;
} else {
*p++ = '%';
@@ -147,8 +146,7 @@ static int pgq_quote_literal(char *dst, const uint8 *src, int srclen)
/*
* slon_quote_identifier - Quote an identifier only if needed
*/
-static int
-pgq_quote_ident(char *dst, const uint8 *src, int srclen)
+static int pgq_quote_ident(char *dst, const uint8 *src, int srclen)
{
/*
* Can avoid quoting if ident starts with a lowercase letter or
@@ -156,10 +154,10 @@ pgq_quote_ident(char *dst, const uint8 *src, int srclen)
* underscores, *and* is not any SQL keyword. Otherwise, supply
* quotes.
*/
- int nquotes = 0;
- bool safe;
+ int nquotes = 0;
+ bool safe;
const char *ptr;
- char *optr;
+ char *optr;
char ident[NAMEDATALEN + 1];
/* expect idents be not bigger than NAMEDATALEN */
@@ -174,22 +172,18 @@ pgq_quote_ident(char *dst, const uint8 *src, int srclen)
*/
safe = ((ident[0] >= 'a' && ident[0] <= 'z') || ident[0] == '_');
- for (ptr = ident; *ptr; ptr++)
- {
- char ch = *ptr;
+ for (ptr = ident; *ptr; ptr++) {
+ char ch = *ptr;
- if ((ch >= 'a' && ch <= 'z') ||
- (ch >= '0' && ch <= '9') ||
- (ch == '_'))
- continue; /* okay */
+ if ((ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9') || (ch == '_'))
+ continue; /* okay */
safe = false;
if (ch == '"')
nquotes++;
}
- if (safe)
- {
+ if (safe) {
/*
* Check for keyword. This test is overly strong, since many of
* the "keywords" known to the parser are usable as column names,
@@ -207,9 +201,8 @@ pgq_quote_ident(char *dst, const uint8 *src, int srclen)
if (!safe)
*optr++ = '"';
- for (ptr = ident; *ptr; ptr++)
- {
- char ch = *ptr;
+ for (ptr = ident; *ptr; ptr++) {
+ char ch = *ptr;
if (ch == '"')
*optr++ = '"';
@@ -235,10 +228,7 @@ static void finish_append(StringInfo buf, int final_len)
}
-static void
-tbuf_encode_data(StringInfo buf,
- const uint8 *data, int len,
- enum PgqEncode encoding)
+static void tbuf_encode_data(StringInfo buf, const uint8 *data, int len, enum PgqEncode encoding)
{
int dlen = 0;
char *dst;
@@ -266,13 +256,9 @@ tbuf_encode_data(StringInfo buf,
finish_append(buf, dlen);
}
-void
-pgq_encode_cstring(StringInfo tbuf,
- const char *str,
- enum PgqEncode encoding)
+void pgq_encode_cstring(StringInfo tbuf, const char *str, enum PgqEncode encoding)
{
if (str == NULL)
elog(ERROR, "tbuf_encode_cstring: NULL");
tbuf_encode_data(tbuf, (const uint8 *)str, strlen(str), encoding);
}
-
diff --git a/sql/pgq/triggers/stringutil.h b/sql/pgq/triggers/stringutil.h
index 8a55c76c..c93c1f4f 100644
--- a/sql/pgq/triggers/stringutil.h
+++ b/sql/pgq/triggers/stringutil.h
@@ -8,7 +8,4 @@ enum PgqEncode {
StringInfo pgq_init_varbuf(void);
Datum pgq_finish_varbuf(StringInfo buf);
bool pgq_strlist_contains(const char *liststr, const char *str);
-void pgq_encode_cstring(StringInfo tbuf,
- const char *str,
- enum PgqEncode encoding);
-
+void pgq_encode_cstring(StringInfo tbuf, const char *str, enum PgqEncode encoding);