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.
--- /dev/null
+#!/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 "$@"
+
" 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
* 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;
};
/*
* 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;
*/
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
*/
*/
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;
}
/*
{
Datum values[1];
int res;
- TupleDesc desc;
- HeapTuple row;
+ TupleDesc desc;
+ HeapTuple row;
bool isnull;
values[0] = queue_name;
/*
* 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
* 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];
if (SPI_connect() < 0)
elog(ERROR, "SPI_connect() failed");
-
+
init_cache();
load_queue_info(PG_GETARG_DATUM(0), &state);
PG_RETURN_INT64(ret_id);
}
-
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);
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));
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);
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));
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
ALLOCSET_SMALL_MINSIZE,
ALLOCSET_SMALL_INITSIZE,
ALLOCSET_SMALL_MAXSIZE);
+
/*
* init pkey cache.
*/
/*
* Prepare utility plans and plan cache.
*/
-static void
-init_module(void)
+static void init_module(void)
{
static int callback_init = 0;
}
}
-static void
-full_reset(void)
+static void full_reset(void)
{
if (tbl_cache_ctx) {
/* needed only if backend has HASH_STATISTICS set */
/*
* 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;
return info;
}
-static void
-free_info(struct PgqTableInfo *info)
+static void free_info(struct PgqTableInfo *info)
{
pfree(info->table_name);
pfree(info->pkey_attno);
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);
}
}
}
/*
* fetch insert plan from cache.
*/
-struct PgqTableInfo *
-pgq_find_table_info(Relation rel)
+struct PgqTableInfo *pgq_find_table_info(Relation rel)
{
struct PgqTableInfo *entry;
return entry;
}
-static void
-parse_newstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
+static void parse_newstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
{
int i;
/*
}
}
-static void
-parse_oldstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
+static void parse_oldstyle_args(PgqTriggerEvent *ev, TriggerData *tg)
{
const char *kpos;
int attcnt, i;
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++;
}
* 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)
ev->ev_type = pgq_init_varbuf();
ev->ev_data = pgq_init_varbuf();
ev->ev_extra1 = pgq_init_varbuf();
-
+
/*
* Do the backup, if requested.
*/
#endif
return false;
}
-
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);
/* logutriga.c */
void pgq_urlenc_row(PgqTriggerEvent *ev, TriggerData *tg, HeapTuple row, StringInfo buf);
-
* 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
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");
skip_it:
return PointerGetDatum(NULL);
}
-
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;
/* 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);
}
* 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
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
else
return PointerGetDatum(row);
}
-
#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");
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, '=');
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 */
*/
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 */
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
*/
* 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
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;
* 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;
* 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;
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
*/
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;
}
}
-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++;
return need_event;
}
-
* 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
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;
else
return PointerGetDatum(tg->tg_trigtuple);
}
-
{
int c, len = strlen(str);
const char *p, *listpos = liststr;
-
+
loop:
/* find string fragment, later check if actual token */
p = strstr(listpos, str);
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++ = '%';
/*
* 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
* 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 */
*/
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,
if (!safe)
*optr++ = '"';
- for (ptr = ident; *ptr; ptr++)
- {
- char ch = *ptr;
+ for (ptr = ident; *ptr; ptr++) {
+ char ch = *ptr;
if (ch == '"')
*optr++ = '"';
}
-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;
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);
}
-
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);