diff options
| author | Bruce Momjian <bruce@momjian.us> | 1999-05-25 16:15:34 +0000 |
|---|---|---|
| committer | Bruce Momjian <bruce@momjian.us> | 1999-05-25 16:15:34 +0000 |
| commit | 07842084fe3e11041f83563c851236395f481470 (patch) | |
| tree | ab9960e67325bec5a97b8b4dd4b2075ce60cc420 /contrib/lo | |
| parent | 4b04b01aaa460f1e52980f24173dc7a4535efd2d (diff) | |
| download | postgresql-07842084fe3e11041f83563c851236395f481470.tar.gz | |
pgindent run over code.
Diffstat (limited to 'contrib/lo')
| -rw-r--r-- | contrib/lo/lo.c | 245 |
1 files changed, 125 insertions, 120 deletions
diff --git a/contrib/lo/lo.c b/contrib/lo/lo.c index 96af1df3d9..3b0c1e2614 100644 --- a/contrib/lo/lo.c +++ b/contrib/lo/lo.c @@ -1,7 +1,7 @@ /* * PostgreSQL type definitions for managed LargeObjects. * - * $Id: lo.c,v 1.1 1998/06/16 07:07:11 momjian Exp $ + * $Id: lo.c,v 1.2 1999/05/25 16:05:45 momjian Exp $ * */ @@ -33,11 +33,11 @@ typedef Oid Blob; * Various forward declarations: */ -Blob *lo_in(char *str); /* Create from String */ -char *lo_out(Blob * addr); /* Output oid as String */ -Oid lo_oid(Blob * addr); /* Return oid as an oid */ -Blob *lo(Oid oid); /* Return Blob based on oid */ -HeapTuple lo_manage(void); /* Trigger handler */ +Blob *lo_in(char *str); /* Create from String */ +char *lo_out(Blob * addr);/* Output oid as String */ +Oid lo_oid(Blob * addr);/* Return oid as an oid */ +Blob *lo(Oid oid); /* Return Blob based on oid */ +HeapTuple lo_manage(void); /* Trigger handler */ /* * This creates a large object, and set's its OID to the value in the @@ -49,45 +49,46 @@ HeapTuple lo_manage(void); /* Trigger handler */ Blob * lo_in(char *str) { - Blob *result; - Oid oid; - int count; - - if (strlen(str) > 0) + Blob *result; + Oid oid; + int count; + + if (strlen(str) > 0) { - - count = sscanf(str, "%d", &oid); - - if (count < 1) + + count = sscanf(str, "%d", &oid); + + if (count < 1) { - elog(ERROR, "lo_in: error in parsing \"%s\"", str); - return (NULL); + elog(ERROR, "lo_in: error in parsing \"%s\"", str); + return (NULL); } - - if(oid < 0) + + if (oid < 0) { - elog(ERROR, "lo_in: illegal oid \"%s\"", str); - return (NULL); + elog(ERROR, "lo_in: illegal oid \"%s\"", str); + return (NULL); } } - else + else { - /* - * There is no Oid passed, so create a new one - */ - oid = lo_creat(INV_READ|INV_WRITE); - if(oid == InvalidOid) + + /* + * There is no Oid passed, so create a new one + */ + oid = lo_creat(INV_READ | INV_WRITE); + if (oid == InvalidOid) { - elog(ERROR,"lo_in: InvalidOid returned from lo_creat"); - return (NULL); + elog(ERROR, "lo_in: InvalidOid returned from lo_creat"); + return (NULL); } } - - result = (Blob *) palloc(sizeof(Blob)); - - *result = oid; - - return (result); + + result = (Blob *) palloc(sizeof(Blob)); + + *result = oid; + + return (result); } /* @@ -96,42 +97,43 @@ lo_in(char *str) char * lo_out(Blob * addr) { - char *result; - - if (addr == NULL) - return (NULL); - - result = (char *) palloc(32); - sprintf(result,"%d",*addr); - return (result); + char *result; + + if (addr == NULL) + return (NULL); + + result = (char *) palloc(32); + sprintf(result, "%d", *addr); + return (result); } /* * This function converts Blob to oid. * * eg: select lo_export(raster::oid,'/path/file') from table; - * + * */ Oid lo_oid(Blob * addr) { - if(addr == NULL) - return InvalidOid; - return (Oid)(*addr); + if (addr == NULL) + return InvalidOid; + return (Oid) (*addr); } /* * This function is used so we can convert oid's to lo's * - * ie: insert into table values(lo_import('/path/file')::lo); + * ie: insert into table values(lo_import('/path/file')::lo); * */ Blob * lo(Oid oid) { - Blob *result = (Blob *) palloc(sizeof(Blob)); - *result = oid; - return (result); + Blob *result = (Blob *) palloc(sizeof(Blob)); + + *result = oid; + return (result); } /* @@ -140,74 +142,77 @@ lo(Oid oid) HeapTuple lo_manage(void) { - int attnum; /* attribute number to monitor */ - char **args; /* Args containing attr name */ - TupleDesc tupdesc; /* Tuple Descriptor */ - HeapTuple rettuple; /* Tuple to be returned */ - bool isdelete; /* are we deleting? */ - HeapTuple newtuple=NULL; /* The new value for tuple */ - HeapTuple trigtuple; /* The original value of tuple */ - - if (!CurrentTriggerData) - elog(ERROR, "lo: triggers are not initialized"); - - /* - * Fetch some values from CurrentTriggerData - */ - newtuple = CurrentTriggerData->tg_newtuple; - trigtuple = CurrentTriggerData->tg_trigtuple; - tupdesc = CurrentTriggerData->tg_relation->rd_att; - args = CurrentTriggerData->tg_trigger->tgargs; - - /* tuple to return to Executor */ - if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event)) - rettuple = newtuple; - else - rettuple = trigtuple; - - /* Are we deleting the row? */ - isdelete = TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event); - - /* Were done with it */ - CurrentTriggerData = NULL; - - /* Get the column were interested in */ - attnum = SPI_fnumber(tupdesc,args[0]); - - /* - * Handle updates - * - * Here, if the value of the monitored attribute changes, then the - * large object associated with the original value is unlinked. - */ - if(newtuple!=NULL) { - char *orig = SPI_getvalue(trigtuple,tupdesc,attnum); - char *newv = SPI_getvalue(newtuple,tupdesc,attnum); - - if((orig != newv && (orig==NULL || newv==NULL)) || (orig!=NULL && newv!=NULL && strcmp(orig,newv))) - lo_unlink(atoi(orig)); - - if(newv) - pfree(newv); - if(orig) - pfree(orig); - } - - /* - * Handle deleting of rows - * - * Here, we unlink the large object associated with the managed attribute - * - */ - if(isdelete) { - char *orig = SPI_getvalue(trigtuple,tupdesc,attnum); - - if(orig != NULL) { - lo_unlink(atoi(orig)); - - pfree(orig); + int attnum; /* attribute number to monitor */ + char **args; /* Args containing attr name */ + TupleDesc tupdesc; /* Tuple Descriptor */ + HeapTuple rettuple; /* Tuple to be returned */ + bool isdelete; /* are we deleting? */ + HeapTuple newtuple = NULL;/* The new value for tuple */ + HeapTuple trigtuple; /* The original value of tuple */ + + if (!CurrentTriggerData) + elog(ERROR, "lo: triggers are not initialized"); + + /* + * Fetch some values from CurrentTriggerData + */ + newtuple = CurrentTriggerData->tg_newtuple; + trigtuple = CurrentTriggerData->tg_trigtuple; + tupdesc = CurrentTriggerData->tg_relation->rd_att; + args = CurrentTriggerData->tg_trigger->tgargs; + + /* tuple to return to Executor */ + if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event)) + rettuple = newtuple; + else + rettuple = trigtuple; + + /* Are we deleting the row? */ + isdelete = TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event); + + /* Were done with it */ + CurrentTriggerData = NULL; + + /* Get the column were interested in */ + attnum = SPI_fnumber(tupdesc, args[0]); + + /* + * Handle updates + * + * Here, if the value of the monitored attribute changes, then the large + * object associated with the original value is unlinked. + */ + if (newtuple != NULL) + { + char *orig = SPI_getvalue(trigtuple, tupdesc, attnum); + char *newv = SPI_getvalue(newtuple, tupdesc, attnum); + + if ((orig != newv && (orig == NULL || newv == NULL)) || (orig != NULL && newv != NULL && strcmp(orig, newv))) + lo_unlink(atoi(orig)); + + if (newv) + pfree(newv); + if (orig) + pfree(orig); } - } - - return (rettuple); + + /* + * Handle deleting of rows + * + * Here, we unlink the large object associated with the managed attribute + * + */ + if (isdelete) + { + char *orig = SPI_getvalue(trigtuple, tupdesc, attnum); + + if (orig != NULL) + { + lo_unlink(atoi(orig)); + + pfree(orig); + } + } + + return (rettuple); } |
