Tue Apr 4 11:28:58 PDT 2006
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Log Message:
-----------
Don't skip NULL columns on insert. If the table definition on a
subscriber has a default value, an explicit given NULL by the
application will be overwritten by the subscriber with the default.
Jan
Modified Files:
--------------
slony1-engine/src/backend:
slony1_funcs.c (r1.40 -> r1.41)
-------------- next part --------------
Index: slony1_funcs.c
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/src/backend/slony1_funcs.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -Lsrc/backend/slony1_funcs.c -Lsrc/backend/slony1_funcs.c -u -w -r1.40 -r1.41
--- src/backend/slony1_funcs.c
+++ src/backend/slony1_funcs.c
@@ -491,7 +491,7 @@
HeapTuple new_row = tg->tg_trigtuple;
TupleDesc tupdesc = tg->tg_relation->rd_att;
char *col_ident;
- char **col_value;
+ char *col_value;
int len_ident;
int len_value;
int i;
@@ -501,38 +501,23 @@
/*
* INSERT
*
- * cmdtype = 'I' cmddata = ("non-NULL-col" [, ...]) values ('value' [,
- * ...])
+ * cmdtype = 'I' cmddata = ("col" [, ...]) values ('value' [, ...])
*/
cmdtype = cs->cmdtype_I;
/*
- * Allocate an array of char pointers to hold the values. We need to
- * go over the tuple descriptor 2 times, first to add the column names
- * of non-null columns, second to add the values. But we can identify
- * what's NULL only by getting the value via SPI_getvalue() in the
- * first pass.
- */
- col_value = (char **)palloc(sizeof(char *) *
- tg->tg_relation->rd_att->natts);
-
- /*
* Specify all the columns
*/
*cp++ = '(';
for (i = 0; i < tg->tg_relation->rd_att->natts; i++)
{
/*
- * Skip dropped columns and NULL values
+ * Skip dropped columns
*/
if (tupdesc->attrs[i]->attisdropped)
continue;
- if ((col_value[i] = SPI_getvalue(new_row, tupdesc, i + 1)) == NULL)
- continue;
col_ident = (char *)slon_quote_identifier(SPI_fname(tupdesc, i + 1));
- col_value[i] = slon_quote_literal(col_value[i]);
-
cmddata_need = (cp - (char *)(cs->cmddata_buf)) + 16 +
(len_ident = strlen(col_ident));
if (cs->cmddata_size < cmddata_need)
@@ -575,15 +560,21 @@
for (i = 0; i < tg->tg_relation->rd_att->natts; i++)
{
/*
- * Skip dropped columns and NULL values
+ * Skip dropped columns
*/
if (tupdesc->attrs[i]->attisdropped)
continue;
- if (col_value[i] == NULL)
- continue;
+ if ((col_value = SPI_getvalue(new_row, tupdesc, i + 1)) == NULL)
+ {
+ col_value = "NULL";
+ }
+ else
+ {
+ col_value = slon_quote_literal(col_value);
+ }
cmddata_need = (cp - (char *)(cs->cmddata_buf)) + 16 +
- (len_value = strlen(col_value[i]));
+ (len_value = strlen(col_value));
if (cs->cmddata_size < cmddata_need)
{
int have = (cp - (char *)(cs->cmddata_buf));
@@ -599,7 +590,7 @@
else
need_comma = true;
- memcpy(cp, col_value[i], len_value);
+ memcpy(cp, col_value, len_value);
cp += len_value;
}
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Slony1-commit mailing list