这篇教程C++ CharGetDatum函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CharGetDatum函数的典型用法代码示例。如果您正苦于以下问题:C++ CharGetDatum函数的具体用法?C++ CharGetDatum怎么用?C++ CharGetDatum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CharGetDatum函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: gp_add_master_standby/* * Add a master standby. * * gp_add_master_standby(hostname, address) * * Args: * hostname - as above * address - as above * * Returns: * dbid of the new standby */Datumgp_add_master_standby(PG_FUNCTION_ARGS){ CdbComponentDatabaseInfo *master = NULL; Relation gprel; Datum values[Natts_gp_segment_configuration]; bool nulls[Natts_gp_segment_configuration]; HeapTuple tuple; cqContext cqc; cqContext *pcqCtx = NULL; if (PG_ARGISNULL(0)) elog(ERROR, "host name cannot be NULL"); if (PG_ARGISNULL(1)) elog(ERROR, "address cannot be NULL"); mirroring_sanity_check(MASTER_ONLY | UTILITY_MODE, "gp_add_master_standby"); if (standby_exists()) elog(ERROR, "only a single master standby may be defined"); /* master */ master = registration_order_get_dbinfo(MASTER_ORDER_ID); /* Lock exclusively to avoid concurrent changes */ gprel = heap_open(GpSegmentConfigRelationId, AccessExclusiveLock); pcqCtx = caql_beginscan( caql_addrel(cqclr(&cqc), gprel), cql("INSERT INTO gp_segment_configuration ", NULL)); MemSet(nulls, false, sizeof(nulls)); values[Anum_gp_segment_configuration_registration_order - 1] = Int32GetDatum(STANDBY_ORDER_ID); values[Anum_gp_segment_configuration_role - 1] = CharGetDatum(SEGMENT_ROLE_STANDBY_CONFIG); values[Anum_gp_segment_configuration_status - 1] = CharGetDatum('u'); values[Anum_gp_segment_configuration_port - 1] = Int32GetDatum(master->port); values[Anum_gp_segment_configuration_hostname - 1] = PG_GETARG_DATUM(0); values[Anum_gp_segment_configuration_address - 1] = PG_GETARG_DATUM(1); nulls[Anum_gp_segment_configuration_description - 1] = true; tuple = caql_form_tuple(pcqCtx, values, nulls); /* insert a new tuple */ caql_insert(pcqCtx, tuple); /* implicit update of index as well */ caql_endscan(pcqCtx); if(master) pfree(master); heap_close(gprel, NoLock); PG_RETURN_INT16(1);}
开发者ID:laixiong,项目名称:incubator-hawq,代码行数:68,
示例2: contentid_get_dbid/* * Obtain the dbid of a of a segment at a given segment index (i.e., content id) * currently fulfilling the role specified. This means that the segment is * really performing the role of primary or mirror, irrespective of their * preferred role. */int16contentid_get_dbid(int16 contentid, char role, bool getPreferredRoleNotCurrentRole){ int16 dbid = 0; bool bOnly; HeapTuple tup; /* * Can only run on a master node, this restriction is due to the reliance * on the gp_segment_configuration table. This may be able to be relaxed * by switching to a different method of checking. */ if (GpIdentity.segindex != MASTER_CONTENT_ID) elog(ERROR, "contentid_get_dbid() executed on execution segment"); /* XXX XXX: CHECK THIS XXX jic 2011/12/09 */ if (getPreferredRoleNotCurrentRole) { tup = caql_getfirst_only( NULL, &bOnly, cql("SELECT * FROM gp_segment_configuration " " WHERE content = :1 " " AND preferred_role = :2 ", Int16GetDatum(contentid), CharGetDatum(role))); } else { tup = caql_getfirst_only( NULL, &bOnly, cql("SELECT * FROM gp_segment_configuration " " WHERE content = :1 " " AND role = :2 ", Int16GetDatum(contentid), CharGetDatum(role))); } if (HeapTupleIsValid(tup)) { dbid = ((Form_gp_segment_configuration) GETSTRUCT(tup))->dbid; /* We expect a single result, assert this */ Assert(bOnly); /* should be only 1 */ } /* no need to hold the lock, it's a catalog */ return dbid;}
开发者ID:AnLingm,项目名称:gpdb,代码行数:55,
示例3: addProcCallback/* --------------------- * addProcCallback() - Add a new callback to pg_proc_callback * * Parameters: * profnoid - oid of the function that has a callback * procallback - oid of the callback function * promethod - role the callback function plays * * Notes: * This function does not maintain dependencies in pg_depend, that behavior * is currently controlled in pg_proc.c * --------------------- */void addProcCallback(Oid profnoid, Oid procallback, char promethod){ Relation rel; bool nulls[Natts_pg_proc_callback]; Datum values[Natts_pg_proc_callback]; HeapTuple tup; Insist(OidIsValid(profnoid)); Insist(OidIsValid(procallback)); /* open pg_proc_callback */ rel = heap_open(ProcCallbackRelationId, RowExclusiveLock); /* Build the tuple and insert it */ nulls[Anum_pg_proc_callback_profnoid - 1] = false; nulls[Anum_pg_proc_callback_procallback - 1] = false; nulls[Anum_pg_proc_callback_promethod - 1] = false; values[Anum_pg_proc_callback_profnoid - 1] = ObjectIdGetDatum(profnoid); values[Anum_pg_proc_callback_procallback - 1] = ObjectIdGetDatum(procallback); values[Anum_pg_proc_callback_promethod - 1] = CharGetDatum(promethod); tup = heap_form_tuple(RelationGetDescr(rel), values, nulls); /* Insert tuple into the relation */ simple_heap_insert(rel, tup); CatalogUpdateIndexes(rel, tup); heap_close(rel, RowExclusiveLock);}
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:43,
示例4: my_mirror_dbid/* * Returns the dbid of the mirror. We can use the fact that * mirrors have the same contentid (stored in GpIdentity) and go from * there. */int16my_mirror_dbid(void){ int16 dbid = 0; int16 contentid = (int16)GpIdentity.segindex; bool bOnly; HeapTuple tup; /* * Can only run on a master node, this restriction is due to the reliance * on the gp_segment_configuration table. This may be able to be relaxed * by switching to a different method of checking. */ if (GpIdentity.segindex != MASTER_CONTENT_ID) elog(ERROR, "my_mirror_dbid() executed on execution segment"); tup = caql_getfirst_only( NULL, &bOnly, cql("SELECT dbid FROM gp_segment_configuration " " WHERE content = :1 " " AND role = :2 ", Int16GetDatum(contentid), CharGetDatum('m'))); if (HeapTupleIsValid(tup)) { dbid = ((Form_gp_segment_configuration) GETSTRUCT(tup))->dbid; /* We expect a single result, assert this */ Assert(bOnly); /* should be only 1 */ } /* no need to hold the lock, it's a catalog */ return dbid;}
开发者ID:AnLingm,项目名称:gpdb,代码行数:40,
示例5: GetAllTablesPublicationRelations/* * Gets list of all relation published by FOR ALL TABLES publication(s). */List *GetAllTablesPublicationRelations(void){ Relation classRel; ScanKeyData key[1]; HeapScanDesc scan; HeapTuple tuple; List *result = NIL; classRel = heap_open(RelationRelationId, AccessShareLock); ScanKeyInit(&key[0], Anum_pg_class_relkind, BTEqualStrategyNumber, F_CHAREQ, CharGetDatum(RELKIND_RELATION)); scan = heap_beginscan_catalog(classRel, 1, key); while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) { Form_pg_class relForm = (Form_pg_class) GETSTRUCT(tuple); Oid relid = relForm->oid; if (is_publishable_class(relid, relForm)) result = lappend_oid(result, relid); } heap_endscan(scan); heap_close(classRel, AccessShareLock); return result;}
开发者ID:adityavs,项目名称:postgres,代码行数:35,
示例6: gp_remove_master_standby/* * Remove the master standby. * * gp_remove_master_standby() * * Returns: * true upon success otherwise false */Datumgp_remove_master_standby(PG_FUNCTION_ARGS){ int numDel; cqContext cqc; mirroring_sanity_check(SUPERUSER | MASTER_ONLY | UTILITY_MODE, "gp_remove_master_standby"); if (!standby_exists()) elog(ERROR, "no master standby defined"); Relation rel = heap_open(GpSegmentConfigRelationId, AccessExclusiveLock); numDel= caql_getcount(caql_addrel(cqclr(&cqc), rel), cql("DELETE FROM gp_segment_configuration " " WHERE role = :1", CharGetDatum(SEGMENT_ROLE_STANDBY_CONFIG))); elog(LOG, "Remove standby, count : %d.", numDel); heap_close(rel, NoLock); update_gp_master_mirroring("Not Configured"); PG_RETURN_BOOL(true);}
开发者ID:PivotalBigData,项目名称:incubator-hawq,代码行数:34,
示例7: gp_activate_standby/* * Activate a standby. To do this, we need to change * * 1. Check that we're actually the standby * 2. Remove standby from gp_segment_configuration. * * gp_activate_standby() * * Returns: * true upon success, otherwise throws error. */Datumgp_activate_standby(PG_FUNCTION_ARGS){ cqContext cqc; int numDel; mirroring_sanity_check(SUPERUSER | UTILITY_MODE | STANDBY_ONLY, PG_FUNCNAME_MACRO); if (!AmIStandby()) elog(ERROR, "%s must be run on the standby master", PG_FUNCNAME_MACRO); /* remove standby from gp_segment_configuration */ Relation rel = heap_open(GpSegmentConfigRelationId, AccessExclusiveLock); numDel= caql_getcount(caql_addrel(cqclr(&cqc), rel), cql("DELETE FROM gp_segment_configuration " " WHERE role = :1", CharGetDatum(SEGMENT_ROLE_STANDBY_CONFIG))); elog(LOG, "Remove standby while activating it, count : %d.", numDel); heap_close(rel, NoLock); /* done */ PG_RETURN_BOOL(true);}
开发者ID:PivotalBigData,项目名称:incubator-hawq,代码行数:37,
示例8: master_standby_dbid/* * Determine the dbid for the master standby */int16master_standby_dbid(void){ int16 dbid = 0; int16 contentid = -1; bool bOnly; HeapTuple tup; /* * Can only run on a master node, this restriction is due to the reliance * on the gp_segment_configuration table. */ if (GpIdentity.segindex != MASTER_CONTENT_ID) elog(ERROR, "master_standby_dbid() executed on execution segment"); tup = caql_getfirst_only( NULL, &bOnly, cql("SELECT * FROM gp_segment_configuration " " WHERE content = :1 " " AND role = :2 ", Int16GetDatum(contentid), CharGetDatum('m'))); if (HeapTupleIsValid(tup)) { dbid = ((Form_gp_segment_configuration) GETSTRUCT(tup))->dbid; /* We expect a single result, assert this */ Assert(bOnly); } /* no need to hold the lock, it's a catalog */ return dbid;}
开发者ID:AnLingm,项目名称:gpdb,代码行数:37,
示例9: InsertAgLabelTuple/* * InsertAgLabelTuple - register the new label in ag_label * * See InsertPgClassTuple() */static voidInsertAgLabelTuple(Relation ag_label_desc, Oid laboid, RangeVar *label, Oid relid, char labkind){ Oid graphid = get_graphname_oid(label->schemaname); char *labname = label->relname; int32 labid; Datum values[Natts_ag_label]; bool nulls[Natts_ag_label]; HeapTuple tup; AssertArg(labkind == LABEL_KIND_VERTEX || labkind == LABEL_KIND_EDGE); labid = (int32) GetNewLabelId(label->schemaname, graphid); values[Anum_ag_label_labname - 1] = CStringGetDatum(labname); values[Anum_ag_label_graphid - 1] = CStringGetDatum(graphid); values[Anum_ag_label_labid - 1] = Int32GetDatum(labid); values[Anum_ag_label_relid - 1] = ObjectIdGetDatum(relid); values[Anum_ag_label_labkind - 1] = CharGetDatum(labkind); memset(nulls, false, sizeof(nulls)); tup = heap_form_tuple(RelationGetDescr(ag_label_desc), values, nulls); HeapTupleSetOid(tup, laboid); simple_heap_insert(ag_label_desc, tup); CatalogUpdateIndexes(ag_label_desc, tup); heap_freetuple(tup);}
开发者ID:kskim80,项目名称:agens-graph,代码行数:38,
示例10: PgxcClassCreate/* * PgxcClassCreate * Create a pgxc_class entry */voidPgxcClassCreate(Oid pcrelid, char pclocatortype, int pcattnum, int pchashalgorithm, int pchashbuckets, int numnodes, Oid *nodes){ Relation pgxcclassrel; HeapTuple htup; bool nulls[Natts_pgxc_class]; Datum values[Natts_pgxc_class]; int i; oidvector *nodes_array; /* Build array of Oids to be inserted */ nodes_array = buildoidvector(nodes, numnodes); /* Iterate through attributes initializing nulls and values */ for (i = 0; i < Natts_pgxc_class; i++) { nulls[i] = false; values[i] = (Datum) 0; } /* should not happen */ if (pcrelid == InvalidOid) { elog(ERROR,"pgxc class relid invalid."); return; } values[Anum_pgxc_class_pcrelid - 1] = ObjectIdGetDatum(pcrelid); values[Anum_pgxc_class_pclocatortype - 1] = CharGetDatum(pclocatortype); if (pclocatortype == LOCATOR_TYPE_HASH || pclocatortype == LOCATOR_TYPE_MODULO) { values[Anum_pgxc_class_pcattnum - 1] = UInt16GetDatum(pcattnum); values[Anum_pgxc_class_pchashalgorithm - 1] = UInt16GetDatum(pchashalgorithm); values[Anum_pgxc_class_pchashbuckets - 1] = UInt16GetDatum(pchashbuckets); } /* Node information */ values[Anum_pgxc_class_nodes - 1] = PointerGetDatum(nodes_array); /* Open the relation for insertion */ pgxcclassrel = heap_open(PgxcClassRelationId, RowExclusiveLock); htup = heap_form_tuple(pgxcclassrel->rd_att, values, nulls); (void) simple_heap_insert(pgxcclassrel, htup); CatalogUpdateIndexes(pgxcclassrel, htup); heap_close(pgxcclassrel, RowExclusiveLock);}
开发者ID:TesterRandolph,项目名称:postgres-x2,代码行数:61,
示例11: standby_exists/* * Tell the caller whether a standby master is defined in the system. */static boolstandby_exists(){ return caql_getcount( NULL, cql("SELECT COUNT(*) FROM gp_segment_configuration " " WHERE role = :1 ", CharGetDatum(SEGMENT_ROLE_STANDBY_CONFIG))) > 0;}
开发者ID:PivotalBigData,项目名称:incubator-hawq,代码行数:12,
示例12: ConstraintIsAForeignKeyToReferenceTable/* * ConstraintIsAForeignKeyToReferenceTable function scans the pgConstraint to * fetch all of the constraints on the given relationId and see if at least one * of them is a foreign key referencing to a reference table. */boolConstraintIsAForeignKeyToReferenceTable(char *constraintName, Oid relationId){ Relation pgConstraint = NULL; SysScanDesc scanDescriptor = NULL; ScanKeyData scanKey[1]; int scanKeyCount = 1; HeapTuple heapTuple = NULL; bool foreignKeyToReferenceTable = false; pgConstraint = heap_open(ConstraintRelationId, AccessShareLock); ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber, F_CHAREQ, CharGetDatum(CONSTRAINT_FOREIGN)); scanDescriptor = systable_beginscan(pgConstraint, InvalidOid, false, NULL, scanKeyCount, scanKey); heapTuple = systable_getnext(scanDescriptor); while (HeapTupleIsValid(heapTuple)) { Oid referencedTableId = InvalidOid; Form_pg_constraint constraintForm = (Form_pg_constraint) GETSTRUCT(heapTuple); char *constraintName = (constraintForm->conname).data; if (strncmp(constraintName, constraintName, NAMEDATALEN) != 0 || constraintForm->conrelid != relationId) { heapTuple = systable_getnext(scanDescriptor); continue; } referencedTableId = constraintForm->confrelid; Assert(IsDistributedTable(referencedTableId)); if (PartitionMethod(referencedTableId) == DISTRIBUTE_BY_NONE) { foreignKeyToReferenceTable = true; break; } heapTuple = systable_getnext(scanDescriptor); } /* clean up scan and close system catalog */ systable_endscan(scanDescriptor); heap_close(pgConstraint, AccessShareLock); return foreignKeyToReferenceTable;}
开发者ID:marcocitus,项目名称:citus,代码行数:56,
示例13: GetSubscriptionNotReadyRelations/* * Get all relations for subscription that are not in a ready state. * * Returned list is palloc'ed in current memory context. */List *GetSubscriptionNotReadyRelations(Oid subid){ List *res = NIL; Relation rel; HeapTuple tup; int nkeys = 0; ScanKeyData skey[2]; SysScanDesc scan; rel = table_open(SubscriptionRelRelationId, AccessShareLock); ScanKeyInit(&skey[nkeys++], Anum_pg_subscription_rel_srsubid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(subid)); ScanKeyInit(&skey[nkeys++], Anum_pg_subscription_rel_srsubstate, BTEqualStrategyNumber, F_CHARNE, CharGetDatum(SUBREL_STATE_READY)); scan = systable_beginscan(rel, InvalidOid, false, NULL, nkeys, skey); while (HeapTupleIsValid(tup = systable_getnext(scan))) { Form_pg_subscription_rel subrel; SubscriptionRelState *relstate; subrel = (Form_pg_subscription_rel) GETSTRUCT(tup); relstate = (SubscriptionRelState *) palloc(sizeof(SubscriptionRelState)); relstate->relid = subrel->srrelid; relstate->state = subrel->srsubstate; relstate->lsn = subrel->srsublsn; res = lappend(res, relstate); } /* Cleanup */ systable_endscan(scan); table_close(rel, AccessShareLock); return res;}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:51,
示例14: lookupProcCallback/* --------------------- * lookupProcCallback() - Find a specified callback for a specified function * * Parameters: * profnoid - oid of the function that has a callback * promethod - which callback to find * --------------------- */Oid lookupProcCallback(Oid profnoid, char promethod){ Relation rel; ScanKeyData skey[2]; SysScanDesc scan; HeapTuple tup; Oid result; Insist(OidIsValid(profnoid)); /* open pg_proc_callback */ rel = heap_open(ProcCallbackRelationId, AccessShareLock); /* Lookup (profnoid, promethod) from index */ /* (profnoid, promethod) is guaranteed unique by the index */ ScanKeyInit(&skey[0], Anum_pg_proc_callback_profnoid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(profnoid)); ScanKeyInit(&skey[1], Anum_pg_proc_callback_promethod, BTEqualStrategyNumber, F_CHAREQ, CharGetDatum(promethod)); scan = systable_beginscan(rel, ProcCallbackProfnoidPromethodIndexId, true, SnapshotNow, 2, skey); tup = systable_getnext(scan); if (HeapTupleIsValid(tup)) { Datum d; bool isnull; d = heap_getattr(tup, Anum_pg_proc_callback_procallback, RelationGetDescr(rel), &isnull); Assert(!isnull); result = DatumGetObjectId(d); } else result = InvalidOid; systable_endscan(scan); heap_close(rel, AccessShareLock); return result;}
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:54,
示例15: UpdateSubscriptionRelState/* * Update the state of a subscription table. */voidUpdateSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn){ Relation rel; HeapTuple tup; bool nulls[Natts_pg_subscription_rel]; Datum values[Natts_pg_subscription_rel]; bool replaces[Natts_pg_subscription_rel]; LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock); rel = table_open(SubscriptionRelRelationId, RowExclusiveLock); /* Try finding existing mapping. */ tup = SearchSysCacheCopy2(SUBSCRIPTIONRELMAP, ObjectIdGetDatum(relid), ObjectIdGetDatum(subid)); if (!HeapTupleIsValid(tup)) elog(ERROR, "subscription table %u in subscription %u does not exist", relid, subid); /* Update the tuple. */ memset(values, 0, sizeof(values)); memset(nulls, false, sizeof(nulls)); memset(replaces, false, sizeof(replaces)); replaces[Anum_pg_subscription_rel_srsubstate - 1] = true; values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state); replaces[Anum_pg_subscription_rel_srsublsn - 1] = true; if (sublsn != InvalidXLogRecPtr) values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn); else nulls[Anum_pg_subscription_rel_srsublsn - 1] = true; tup = heap_modify_tuple(tup, RelationGetDescr(rel), values, nulls, replaces); /* Update the catalog. */ CatalogTupleUpdate(rel, &tup->t_self, tup); /* Cleanup. */ table_close(rel, NoLock);}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:48,
示例16: AddSubscriptionRelState/* * Add new state record for a subscription table. */voidAddSubscriptionRelState(Oid subid, Oid relid, char state, XLogRecPtr sublsn){ Relation rel; HeapTuple tup; bool nulls[Natts_pg_subscription_rel]; Datum values[Natts_pg_subscription_rel]; LockSharedObject(SubscriptionRelationId, subid, 0, AccessShareLock); rel = table_open(SubscriptionRelRelationId, RowExclusiveLock); /* Try finding existing mapping. */ tup = SearchSysCacheCopy2(SUBSCRIPTIONRELMAP, ObjectIdGetDatum(relid), ObjectIdGetDatum(subid)); if (HeapTupleIsValid(tup)) elog(ERROR, "subscription table %u in subscription %u already exists", relid, subid); /* Form the tuple. */ memset(values, 0, sizeof(values)); memset(nulls, false, sizeof(nulls)); values[Anum_pg_subscription_rel_srsubid - 1] = ObjectIdGetDatum(subid); values[Anum_pg_subscription_rel_srrelid - 1] = ObjectIdGetDatum(relid); values[Anum_pg_subscription_rel_srsubstate - 1] = CharGetDatum(state); if (sublsn != InvalidXLogRecPtr) values[Anum_pg_subscription_rel_srsublsn - 1] = LSNGetDatum(sublsn); else nulls[Anum_pg_subscription_rel_srsublsn - 1] = true; tup = heap_form_tuple(RelationGetDescr(rel), values, nulls); /* Insert tuple into catalog. */ CatalogTupleInsert(rel, tup); heap_freetuple(tup); /* Cleanup. */ table_close(rel, NoLock);}
开发者ID:MasahikoSawada,项目名称:postgresql,代码行数:45,
示例17: ConstraintIsAForeignKey/* * ConstraintIsAForeignKey returns true if the given constraint name * is a foreign key to defined on the relation. */boolConstraintIsAForeignKey(char *constraintNameInput, Oid relationId){ Relation pgConstraint = NULL; SysScanDesc scanDescriptor = NULL; ScanKeyData scanKey[1]; int scanKeyCount = 1; HeapTuple heapTuple = NULL; pgConstraint = heap_open(ConstraintRelationId, AccessShareLock); ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber, F_CHAREQ, CharGetDatum(CONSTRAINT_FOREIGN)); scanDescriptor = systable_beginscan(pgConstraint, InvalidOid, false, NULL, scanKeyCount, scanKey); heapTuple = systable_getnext(scanDescriptor); while (HeapTupleIsValid(heapTuple)) { Form_pg_constraint constraintForm = (Form_pg_constraint) GETSTRUCT(heapTuple); char *constraintName = (constraintForm->conname).data; if (strncmp(constraintName, constraintNameInput, NAMEDATALEN) == 0 && constraintForm->conrelid == relationId) { systable_endscan(scanDescriptor); heap_close(pgConstraint, AccessShareLock); return true; } heapTuple = systable_getnext(scanDescriptor); } /* clean up scan and close system catalog */ systable_endscan(scanDescriptor); heap_close(pgConstraint, AccessShareLock); return false;}
开发者ID:marcocitus,项目名称:citus,代码行数:44,
示例18: GetHiddenPgProcTuples/* * Returns pre-defined hidden tuples for pg_proc. */HeapTuple *GetHiddenPgProcTuples(Relation pg_proc, int *len){ HeapTuple *tuples; Datum values[Natts_pg_proc]; bool nulls[Natts_pg_proc]; MemoryContext oldcontext; static HeapTuple *StaticPgProcTuples = NULL; static int StaticPgProcTupleLen = 0; if (StaticPgProcTuples != NULL) { *len = StaticPgProcTupleLen; return StaticPgProcTuples; }#define N_PGPROC_TUPLES 2 oldcontext = MemoryContextSwitchTo(CacheMemoryContext); tuples = palloc(sizeof(HeapTuple) * N_PGPROC_TUPLES); /* * gp_read_error_log * * CREATE FUNCTION pg_catalog.gp_read_error_log( * text, * cmdtime OUT timestamptz, * relname OUT text, * filename OUT text, * linenum OUT int4, * bytenum OUT int4, * errmsg OUT text, * rawdata OUT text, * rawbytes OUT bytea * ) RETURNS SETOF record AS 'gp_read_error_log' * LANGUAGE internal VOLATILE STRICT <RUN ON SEGMENT>; */ { NameData procname = {"gp_read_error_log"}; Oid proargtypes[] = {TEXTOID}; ArrayType *array; Datum allargtypes[9]; Datum proargmodes[9]; Datum proargnames[9]; MemSet(nulls, false, sizeof(bool) * Natts_pg_proc); values[Anum_pg_proc_proname - 1] = NameGetDatum(&procname); values[Anum_pg_proc_pronamespace - 1] = ObjectIdGetDatum(PG_CATALOG_NAMESPACE); values[Anum_pg_proc_proowner - 1] = ObjectIdGetDatum(BOOTSTRAP_SUPERUSERID); values[Anum_pg_proc_prolang - 1] = ObjectIdGetDatum(INTERNALlanguageId); values[Anum_pg_proc_proisagg - 1] = BoolGetDatum(false); values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(false); values[Anum_pg_proc_proisstrict - 1] = BoolGetDatum(true); values[Anum_pg_proc_proretset - 1] = BoolGetDatum(true); values[Anum_pg_proc_provolatile - 1] = CharGetDatum('v'); values[Anum_pg_proc_pronargs - 1] = Int16GetDatum(1); values[Anum_pg_proc_prorettype - 1] = ObjectIdGetDatum(RECORDOID); values[Anum_pg_proc_proiswin - 1] = BoolGetDatum(false); values[Anum_pg_proc_proargtypes - 1] = PointerGetDatum(buildoidvector(proargtypes, 1)); allargtypes[0] = TEXTOID; allargtypes[1] = TIMESTAMPTZOID; allargtypes[2] = TEXTOID; allargtypes[3] = TEXTOID; allargtypes[4] = INT4OID; allargtypes[5] = INT4OID; allargtypes[6] = TEXTOID; allargtypes[7] = TEXTOID; allargtypes[8] = BYTEAOID; array = construct_array(allargtypes, 9, OIDOID, 4, true, 'i'); values[Anum_pg_proc_proallargtypes - 1] = PointerGetDatum(array); proargmodes[0] = CharGetDatum('i'); proargmodes[1] = CharGetDatum('o'); proargmodes[2] = CharGetDatum('o'); proargmodes[3] = CharGetDatum('o'); proargmodes[4] = CharGetDatum('o'); proargmodes[5] = CharGetDatum('o'); proargmodes[6] = CharGetDatum('o'); proargmodes[7] = CharGetDatum('o'); proargmodes[8] = CharGetDatum('o'); array = construct_array(proargmodes, 9, CHAROID, 1, true, 'c'); values[Anum_pg_proc_proargmodes - 1] = PointerGetDatum(array); proargnames[0] = CStringGetTextDatum(""); proargnames[1] = CStringGetTextDatum("cmdtime"); proargnames[2] = CStringGetTextDatum("relname"); proargnames[3] = CStringGetTextDatum("filename"); proargnames[4] = CStringGetTextDatum("linenum"); proargnames[5] = CStringGetTextDatum("bytenum"); proargnames[6] = CStringGetTextDatum("errmsg"); proargnames[7] = CStringGetTextDatum("rawdata"); proargnames[8] = CStringGetTextDatum("rawbytes"); array = construct_array(proargnames, 9, TEXTOID, -1, false, 'i'); values[Anum_pg_proc_proargnames - 1] = PointerGetDatum(array); values[Anum_pg_proc_prosrc - 1] = CStringGetTextDatum("gp_read_error_log"); values[Anum_pg_proc_probin - 1] = (Datum) 0; nulls[Anum_pg_proc_probin - 1] = true;//.........这里部分代码省略.........
开发者ID:ricky-wu,项目名称:gpdb,代码行数:101,
示例19: AggregateCreate//.........这里部分代码省略......... "aggregate_dummy", /* placeholder proc */ NULL, /* probin */ true, /* isAgg */ false, /* isWindowFunc */ false, /* security invoker (currently not * definable for agg) */ false, /* isLeakProof */ false, /* isStrict (not needed for agg) */ PROVOLATILE_IMMUTABLE, /* volatility (not * needed for agg) */ proparallel, parameterTypes, /* paramTypes */ allParameterTypes, /* allParamTypes */ parameterModes, /* parameterModes */ parameterNames, /* parameterNames */ parameterDefaults, /* parameterDefaults */ PointerGetDatum(NULL), /* trftypes */ PointerGetDatum(NULL), /* proconfig */ 1, /* procost */ 0); /* prorows */ procOid = myself.objectId; /* * Okay to create the pg_aggregate entry. */ /* initialize nulls and values */ for (i = 0; i < Natts_pg_aggregate; i++) { nulls[i] = false; values[i] = (Datum) NULL; } values[Anum_pg_aggregate_aggfnoid - 1] = ObjectIdGetDatum(procOid); values[Anum_pg_aggregate_aggkind - 1] = CharGetDatum(aggKind); values[Anum_pg_aggregate_aggnumdirectargs - 1] = Int16GetDatum(numDirectArgs); values[Anum_pg_aggregate_aggtransfn - 1] = ObjectIdGetDatum(transfn); values[Anum_pg_aggregate_aggfinalfn - 1] = ObjectIdGetDatum(finalfn); values[Anum_pg_aggregate_aggcombinefn - 1] = ObjectIdGetDatum(combinefn); values[Anum_pg_aggregate_aggserialfn - 1] = ObjectIdGetDatum(serialfn); values[Anum_pg_aggregate_aggdeserialfn - 1] = ObjectIdGetDatum(deserialfn); values[Anum_pg_aggregate_aggmtransfn - 1] = ObjectIdGetDatum(mtransfn); values[Anum_pg_aggregate_aggminvtransfn - 1] = ObjectIdGetDatum(minvtransfn); values[Anum_pg_aggregate_aggmfinalfn - 1] = ObjectIdGetDatum(mfinalfn); values[Anum_pg_aggregate_aggfinalextra - 1] = BoolGetDatum(finalfnExtraArgs); values[Anum_pg_aggregate_aggmfinalextra - 1] = BoolGetDatum(mfinalfnExtraArgs); values[Anum_pg_aggregate_aggsortop - 1] = ObjectIdGetDatum(sortop); values[Anum_pg_aggregate_aggtranstype - 1] = ObjectIdGetDatum(aggTransType); values[Anum_pg_aggregate_aggserialtype - 1] = ObjectIdGetDatum(aggSerialType); values[Anum_pg_aggregate_aggtransspace - 1] = Int32GetDatum(aggTransSpace); values[Anum_pg_aggregate_aggmtranstype - 1] = ObjectIdGetDatum(aggmTransType); values[Anum_pg_aggregate_aggmtransspace - 1] = Int32GetDatum(aggmTransSpace); if (agginitval) values[Anum_pg_aggregate_agginitval - 1] = CStringGetTextDatum(agginitval); else nulls[Anum_pg_aggregate_agginitval - 1] = true; if (aggminitval) values[Anum_pg_aggregate_aggminitval - 1] = CStringGetTextDatum(aggminitval); else nulls[Anum_pg_aggregate_aggminitval - 1] = true; aggdesc = heap_open(AggregateRelationId, RowExclusiveLock); tupDesc = aggdesc->rd_att; tup = heap_form_tuple(tupDesc, values, nulls); simple_heap_insert(aggdesc, tup);
开发者ID:GeorgeAyvazian,项目名称:postgres,代码行数:66,
示例20: InsertRule/* * InsertRule - * takes the arguments and inserts them as a row into the system * relation "pg_rewrite" */static OidInsertRule(char *rulname, int evtype, Oid eventrel_oid, AttrNumber evslot_index, bool evinstead, Node *event_qual, List *action, bool replace){ char *evqual = nodeToString(event_qual); char *actiontree = nodeToString((Node *) action); int i; Datum values[Natts_pg_rewrite]; bool nulls[Natts_pg_rewrite]; bool replaces[Natts_pg_rewrite]; NameData rname; Relation pg_rewrite_desc; HeapTuple tup, oldtup; Oid rewriteObjectId; ObjectAddress myself, referenced; bool is_update = false; /* * Set up *nulls and *values arrays */ MemSet(nulls, false, sizeof(nulls)); i = 0; namestrcpy(&rname, rulname); values[i++] = NameGetDatum(&rname); /* rulename */ values[i++] = ObjectIdGetDatum(eventrel_oid); /* ev_class */ values[i++] = Int16GetDatum(evslot_index); /* ev_attr */ values[i++] = CharGetDatum(evtype + '0'); /* ev_type */ values[i++] = CharGetDatum(RULE_FIRES_ON_ORIGIN); /* ev_enabled */ values[i++] = BoolGetDatum(evinstead); /* is_instead */ values[i++] = CStringGetTextDatum(evqual); /* ev_qual */ values[i++] = CStringGetTextDatum(actiontree); /* ev_action */ /* * Ready to store new pg_rewrite tuple */ pg_rewrite_desc = heap_open(RewriteRelationId, RowExclusiveLock); /* * Check to see if we are replacing an existing tuple */ oldtup = SearchSysCache2(RULERELNAME, ObjectIdGetDatum(eventrel_oid), PointerGetDatum(rulname)); if (HeapTupleIsValid(oldtup)) { if (!replace) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("rule /"%s/" for relation /"%s/" already exists", rulname, get_rel_name(eventrel_oid)))); /* * When replacing, we don't need to replace every attribute */ MemSet(replaces, false, sizeof(replaces)); replaces[Anum_pg_rewrite_ev_attr - 1] = true; replaces[Anum_pg_rewrite_ev_type - 1] = true; replaces[Anum_pg_rewrite_is_instead - 1] = true; replaces[Anum_pg_rewrite_ev_qual - 1] = true; replaces[Anum_pg_rewrite_ev_action - 1] = true; tup = heap_modify_tuple(oldtup, RelationGetDescr(pg_rewrite_desc), values, nulls, replaces); simple_heap_update(pg_rewrite_desc, &tup->t_self, tup); ReleaseSysCache(oldtup); rewriteObjectId = HeapTupleGetOid(tup); is_update = true; } else { tup = heap_form_tuple(pg_rewrite_desc->rd_att, values, nulls); rewriteObjectId = simple_heap_insert(pg_rewrite_desc, tup); } /* Need to update indexes in either case */ CatalogUpdateIndexes(pg_rewrite_desc, tup); heap_freetuple(tup); /* If replacing, get rid of old dependencies and make new ones */ if (is_update)//.........这里部分代码省略.........
开发者ID:GisKook,项目名称:Gis,代码行数:101,
示例21: CollationCreate//.........这里部分代码省略......... ? errmsg("collation /"%s/" already exists", collname) : errmsg("collation /"%s/" for encoding /"%s/" already exists", collname, pg_encoding_to_char(collencoding)))); } /* open pg_collation; see below about the lock level */ rel = heap_open(CollationRelationId, ShareRowExclusiveLock); /* * Also forbid a specific-encoding collation shadowing an any-encoding * collation, or an any-encoding collation being shadowed (see * get_collation_name()). This test is not backed up by the unique index, * so we take a ShareRowExclusiveLock earlier, to protect against * concurrent changes fooling this check. */ if ((collencoding == -1 && SearchSysCacheExists3(COLLNAMEENCNSP, PointerGetDatum(collname), Int32GetDatum(GetDatabaseEncoding()), ObjectIdGetDatum(collnamespace))) || (collencoding != -1 && SearchSysCacheExists3(COLLNAMEENCNSP, PointerGetDatum(collname), Int32GetDatum(-1), ObjectIdGetDatum(collnamespace)))) { if (quiet) { heap_close(rel, NoLock); return InvalidOid; } else if (if_not_exists) { heap_close(rel, NoLock); ereport(NOTICE, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("collation /"%s/" already exists, skipping", collname))); return InvalidOid; } else ereport(ERROR, (errcode(ERRCODE_DUPLICATE_OBJECT), errmsg("collation /"%s/" already exists", collname))); } tupDesc = RelationGetDescr(rel); /* form a tuple */ memset(nulls, 0, sizeof(nulls)); namestrcpy(&name_name, collname); values[Anum_pg_collation_collname - 1] = NameGetDatum(&name_name); values[Anum_pg_collation_collnamespace - 1] = ObjectIdGetDatum(collnamespace); values[Anum_pg_collation_collowner - 1] = ObjectIdGetDatum(collowner); values[Anum_pg_collation_collprovider - 1] = CharGetDatum(collprovider); values[Anum_pg_collation_collencoding - 1] = Int32GetDatum(collencoding); namestrcpy(&name_collate, collcollate); values[Anum_pg_collation_collcollate - 1] = NameGetDatum(&name_collate); namestrcpy(&name_ctype, collctype); values[Anum_pg_collation_collctype - 1] = NameGetDatum(&name_ctype); if (collversion) values[Anum_pg_collation_collversion - 1] = CStringGetTextDatum(collversion); else nulls[Anum_pg_collation_collversion - 1] = true; tup = heap_form_tuple(tupDesc, values, nulls); /* insert a new tuple */ oid = CatalogTupleInsert(rel, tup); Assert(OidIsValid(oid)); /* set up dependencies for the new collation */ myself.classId = CollationRelationId; myself.objectId = oid; myself.objectSubId = 0; /* create dependency on namespace */ referenced.classId = NamespaceRelationId; referenced.objectId = collnamespace; referenced.objectSubId = 0; recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL); /* create dependency on owner */ recordDependencyOnOwner(CollationRelationId, HeapTupleGetOid(tup), collowner); /* dependency on extension */ recordDependencyOnCurrentExtension(&myself, false); /* Post creation hook for new collation */ InvokeObjectPostCreateHook(CollationRelationId, oid, 0); heap_freetuple(tup); heap_close(rel, NoLock); return oid;}
开发者ID:AmiGanguli,项目名称:postgres,代码行数:101,
示例22: shdepChangeDep//.........这里部分代码省略.........shdepChangeDep(Relation sdepRel, Oid classid, Oid objid, int32 objsubid, Oid refclassid, Oid refobjid, SharedDependencyType deptype){ Oid dbid = classIdGetDbId(classid); HeapTuple oldtup = NULL; HeapTuple scantup; ScanKeyData key[4]; SysScanDesc scan; /* * Make sure the new referenced object doesn't go away while we record the * dependency. */ shdepLockAndCheckObject(refclassid, refobjid); /* * Look for a previous entry */ ScanKeyInit(&key[0], Anum_pg_shdepend_dbid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(dbid)); ScanKeyInit(&key[1], Anum_pg_shdepend_classid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(classid)); ScanKeyInit(&key[2], Anum_pg_shdepend_objid, BTEqualStrategyNumber, F_OIDEQ, ObjectIdGetDatum(objid)); ScanKeyInit(&key[3], Anum_pg_shdepend_objsubid, BTEqualStrategyNumber, F_INT4EQ, Int32GetDatum(objsubid)); scan = systable_beginscan(sdepRel, SharedDependDependerIndexId, true, NULL, 4, key); while ((scantup = systable_getnext(scan)) != NULL) { /* Ignore if not of the target dependency type */ if (((Form_pg_shdepend) GETSTRUCT(scantup))->deptype != deptype) continue; /* Caller screwed up if multiple matches */ if (oldtup) elog(ERROR, "multiple pg_shdepend entries for object %u/%u/%d deptype %c", classid, objid, objsubid, deptype); oldtup = heap_copytuple(scantup); } systable_endscan(scan); if (isSharedObjectPinned(refclassid, refobjid, sdepRel)) { /* No new entry needed, so just delete existing entry if any */ if (oldtup) CatalogTupleDelete(sdepRel, &oldtup->t_self); } else if (oldtup) { /* Need to update existing entry */ Form_pg_shdepend shForm = (Form_pg_shdepend) GETSTRUCT(oldtup); /* Since oldtup is a copy, we can just modify it in-memory */ shForm->refclassid = refclassid; shForm->refobjid = refobjid; CatalogTupleUpdate(sdepRel, &oldtup->t_self, oldtup); } else { /* Need to insert new entry */ Datum values[Natts_pg_shdepend]; bool nulls[Natts_pg_shdepend]; memset(nulls, false, sizeof(nulls)); values[Anum_pg_shdepend_dbid - 1] = ObjectIdGetDatum(dbid); values[Anum_pg_shdepend_classid - 1] = ObjectIdGetDatum(classid); values[Anum_pg_shdepend_objid - 1] = ObjectIdGetDatum(objid); values[Anum_pg_shdepend_objsubid - 1] = Int32GetDatum(objsubid); values[Anum_pg_shdepend_refclassid - 1] = ObjectIdGetDatum(refclassid); values[Anum_pg_shdepend_refobjid - 1] = ObjectIdGetDatum(refobjid); values[Anum_pg_shdepend_deptype - 1] = CharGetDatum(deptype); /* * we are reusing oldtup just to avoid declaring a new variable, but * it's certainly a new tuple */ oldtup = heap_form_tuple(RelationGetDescr(sdepRel), values, nulls); CatalogTupleInsert(sdepRel, oldtup); } if (oldtup) heap_freetuple(oldtup);}
开发者ID:hasegeli,项目名称:postgres,代码行数:101,
示例23: OperatorCreate//.........这里部分代码省略......... if (negatorName) { /* negator has same arg types */ negatorId = get_other_operator(negatorName, leftTypeId, rightTypeId, operatorName, operatorNamespace, leftTypeId, rightTypeId, false); /* Permission check: must own other operator */ if (OidIsValid(negatorId) && !pg_oper_ownercheck(negatorId, GetUserId())) aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPER, NameListToString(negatorName)); } else negatorId = InvalidOid; /* * set up values in the operator tuple */ for (i = 0; i < Natts_pg_operator; ++i) { values[i] = (Datum) NULL; replaces[i] = true; nulls[i] = false; } namestrcpy(&oname, operatorName); values[Anum_pg_operator_oprname - 1] = NameGetDatum(&oname); values[Anum_pg_operator_oprnamespace - 1] = ObjectIdGetDatum(operatorNamespace); values[Anum_pg_operator_oprowner - 1] = ObjectIdGetDatum(GetUserId()); values[Anum_pg_operator_oprkind - 1] = CharGetDatum(leftTypeId ? (rightTypeId ? 'b' : 'r') : 'l'); values[Anum_pg_operator_oprcanmerge - 1] = BoolGetDatum(canMerge); values[Anum_pg_operator_oprcanhash - 1] = BoolGetDatum(canHash); values[Anum_pg_operator_oprleft - 1] = ObjectIdGetDatum(leftTypeId); values[Anum_pg_operator_oprright - 1] = ObjectIdGetDatum(rightTypeId); values[Anum_pg_operator_oprresult - 1] = ObjectIdGetDatum(operResultType); values[Anum_pg_operator_oprcom - 1] = ObjectIdGetDatum(commutatorId); values[Anum_pg_operator_oprnegate - 1] = ObjectIdGetDatum(negatorId); values[Anum_pg_operator_oprcode - 1] = ObjectIdGetDatum(procedureId); values[Anum_pg_operator_oprrest - 1] = ObjectIdGetDatum(restrictionId); values[Anum_pg_operator_oprjoin - 1] = ObjectIdGetDatum(joinId); pg_operator_desc = heap_open(OperatorRelationId, RowExclusiveLock); /* * If we are replacing an operator shell, update; else insert */ if (operatorObjectId) { isUpdate = true; tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(operatorObjectId)); if (!HeapTupleIsValid(tup)) elog(ERROR, "cache lookup failed for operator %u", operatorObjectId); tup = heap_modify_tuple(tup, RelationGetDescr(pg_operator_desc), values, nulls, replaces);
开发者ID:dreamsxin,项目名称:postgresql-1,代码行数:66,
示例24: ColumnAppearsInForeignKeyToReferenceTable/* * ColumnAppearsInForeignKeyToReferenceTable checks if there is foreign constraint * from/to a reference table on the given column. We iterate pgConstraint to fetch * the constraint on the given relationId and find if any of the constraints * includes the given column. */boolColumnAppearsInForeignKeyToReferenceTable(char *columnName, Oid relationId){ Relation pgConstraint = NULL; SysScanDesc scanDescriptor = NULL; ScanKeyData scanKey[1]; int scanKeyCount = 1; HeapTuple heapTuple = NULL; bool foreignKeyToReferenceTableIncludesGivenColumn = false; pgConstraint = heap_open(ConstraintRelationId, AccessShareLock); ScanKeyInit(&scanKey[0], Anum_pg_constraint_contype, BTEqualStrategyNumber, F_CHAREQ, CharGetDatum(CONSTRAINT_FOREIGN)); scanDescriptor = systable_beginscan(pgConstraint, InvalidOid, false, NULL, scanKeyCount, scanKey); heapTuple = systable_getnext(scanDescriptor); while (HeapTupleIsValid(heapTuple)) { Oid referencedTableId = InvalidOid; Oid referencingTableId = InvalidOid; int pgConstraintKey = 0; Form_pg_constraint constraintForm = (Form_pg_constraint) GETSTRUCT(heapTuple); referencedTableId = constraintForm->confrelid; referencingTableId = constraintForm->conrelid; if (referencedTableId == relationId) { pgConstraintKey = Anum_pg_constraint_confkey; } else if (referencingTableId == relationId) { pgConstraintKey = Anum_pg_constraint_conkey; } else { /* * If the constraint is not from/to the given relation, we should simply * skip. */ heapTuple = systable_getnext(scanDescriptor); continue; } /* * We check if the referenced table is a reference table. There cannot be * any foreign constraint from a distributed table to a local table. */ Assert(IsDistributedTable(referencedTableId)); if (PartitionMethod(referencedTableId) != DISTRIBUTE_BY_NONE) { heapTuple = systable_getnext(scanDescriptor); continue; } if (HeapTupleOfForeignConstraintIncludesColumn(heapTuple, relationId, pgConstraintKey, columnName)) { foreignKeyToReferenceTableIncludesGivenColumn = true; break; } heapTuple = systable_getnext(scanDescriptor); } /* clean up scan and close system catalog */ systable_endscan(scanDescriptor); heap_close(pgConstraint, AccessShareLock); return foreignKeyToReferenceTableIncludesGivenColumn;}
开发者ID:marcocitus,项目名称:citus,代码行数:79,
示例25: role_get_dbinfo/* * get dbinfo by role * There should be only one master in gp_segment_configuration table, one standby at most. */CdbComponentDatabaseInfo *role_get_dbinfo(char role){ HeapTuple tuple; Relation rel; cqContext cqc; bool bOnly; CdbComponentDatabaseInfo *i = NULL; Assert(role == SEGMENT_ROLE_PRIMARY || role == SEGMENT_ROLE_MASTER_CONFIG || role == SEGMENT_ROLE_STANDBY_CONFIG); /* * Can only run on a master node, this restriction is due to the reliance * on the gp_segment_configuration table. This may be able to be relaxed * by switching to a different method of checking. */ if (!AmActiveMaster() && !AmStandbyMaster()) elog(ERROR, "role_get_dbinfo() executed on execution segment"); rel = heap_open(GpSegmentConfigRelationId, AccessShareLock); tuple = caql_getfirst_only( caql_addrel(cqclr(&cqc), rel), &bOnly, cql("SELECT * FROM gp_segment_configuration " " WHERE role = :1 ", CharGetDatum(role))); if (HeapTupleIsValid(tuple)) { Datum attr; bool isNull; i = palloc(sizeof(CdbComponentDatabaseInfo)); /* * role */ attr = heap_getattr(tuple, Anum_gp_segment_configuration_role, RelationGetDescr(rel), &isNull); Assert(!isNull); i->role = DatumGetChar(attr); /* * status */ attr = heap_getattr(tuple, Anum_gp_segment_configuration_status, RelationGetDescr(rel), &isNull); Assert(!isNull); i->status = DatumGetChar(attr); /* * hostname */ attr = heap_getattr(tuple, Anum_gp_segment_configuration_hostname, RelationGetDescr(rel), &isNull); Assert(!isNull); i->hostname = TextDatumGetCString(attr); /* * address */ attr = heap_getattr(tuple, Anum_gp_segment_configuration_address, RelationGetDescr(rel), &isNull); Assert(!isNull); i->address = TextDatumGetCString(attr); /* * port */ attr = heap_getattr(tuple, Anum_gp_segment_configuration_port, RelationGetDescr(rel), &isNull); Assert(!isNull); i->port = DatumGetInt32(attr); } else { elog(ERROR, "could not find configuration entry for role %c", role); } heap_close(rel, NoLock); return i;}
开发者ID:BALDELab,项目名称:incubator-hawq,代码行数:90,
示例26: ProcedureCreate//.........这里部分代码省略......... variadicType = get_element_type(allParams[i]); if (!OidIsValid(variadicType)) elog(ERROR, "variadic parameter is not an array"); break; } break; default: elog(ERROR, "invalid parameter mode '%c'", paramModes[i]); break; } } } /* * All seems OK; prepare the data to be inserted into pg_proc. */ for (i = 0; i < Natts_pg_proc; ++i) { nulls[i] = false; values[i] = (Datum) 0; replaces[i] = true; } namestrcpy(&procname, procedureName); values[Anum_pg_proc_proname - 1] = NameGetDatum(&procname); values[Anum_pg_proc_pronamespace - 1] = ObjectIdGetDatum(procNamespace); values[Anum_pg_proc_proowner - 1] = ObjectIdGetDatum(proowner); values[Anum_pg_proc_prolang - 1] = ObjectIdGetDatum(languageObjectId); values[Anum_pg_proc_procost - 1] = Float4GetDatum(procost); values[Anum_pg_proc_prorows - 1] = Float4GetDatum(prorows); values[Anum_pg_proc_provariadic - 1] = ObjectIdGetDatum(variadicType); values[Anum_pg_proc_protransform - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_proc_prokind - 1] = CharGetDatum(prokind); values[Anum_pg_proc_prosecdef - 1] = BoolGetDatum(security_definer); values[Anum_pg_proc_proleakproof - 1] = BoolGetDatum(isLeakProof); values[Anum_pg_proc_proisstrict - 1] = BoolGetDatum(isStrict); values[Anum_pg_proc_proretset - 1] = BoolGetDatum(returnsSet); values[Anum_pg_proc_provolatile - 1] = CharGetDatum(volatility); values[Anum_pg_proc_proparallel - 1] = CharGetDatum(parallel); values[Anum_pg_proc_pronargs - 1] = UInt16GetDatum(parameterCount); values[Anum_pg_proc_pronargdefaults - 1] = UInt16GetDatum(list_length(parameterDefaults)); values[Anum_pg_proc_prorettype - 1] = ObjectIdGetDatum(returnType); values[Anum_pg_proc_proargtypes - 1] = PointerGetDatum(parameterTypes); if (allParameterTypes != PointerGetDatum(NULL)) values[Anum_pg_proc_proallargtypes - 1] = allParameterTypes; else nulls[Anum_pg_proc_proallargtypes - 1] = true; if (parameterModes != PointerGetDatum(NULL)) values[Anum_pg_proc_proargmodes - 1] = parameterModes; else nulls[Anum_pg_proc_proargmodes - 1] = true; if (parameterNames != PointerGetDatum(NULL)) values[Anum_pg_proc_proargnames - 1] = parameterNames; else nulls[Anum_pg_proc_proargnames - 1] = true; if (parameterDefaults != NIL) values[Anum_pg_proc_proargdefaults - 1] = CStringGetTextDatum(nodeToString(parameterDefaults)); else nulls[Anum_pg_proc_proargdefaults - 1] = true; if (trftypes != PointerGetDatum(NULL)) values[Anum_pg_proc_protrftypes - 1] = trftypes; else nulls[Anum_pg_proc_protrftypes - 1] = true; values[Anum_pg_proc_prosrc - 1] = CStringGetTextDatum(prosrc); if (probin)
开发者ID:eubide,项目名称:postgres,代码行数:67,
示例27: TypeCreate//.........这里部分代码省略......... /* cstring must have char alignment */ if (internalSize == -2 && !(alignment == 'c')) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("alignment /"%c/" is invalid for variable-length type", alignment))); } /* Only varlena types can be toasted */ if (storage != 'p' && internalSize != -1) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), errmsg("fixed-size types must have storage PLAIN"))); /* * initialize arrays needed for heap_form_tuple or heap_modify_tuple */ for (i = 0; i < Natts_pg_type; ++i) { nulls[i] = false; replaces[i] = true; values[i] = (Datum) 0; } /* * insert data values */ namestrcpy(&name, typeName); values[Anum_pg_type_typname - 1] = NameGetDatum(&name); values[Anum_pg_type_typnamespace - 1] = ObjectIdGetDatum(typeNamespace); values[Anum_pg_type_typowner - 1] = ObjectIdGetDatum(ownerId); values[Anum_pg_type_typlen - 1] = Int16GetDatum(internalSize); values[Anum_pg_type_typbyval - 1] = BoolGetDatum(passedByValue); values[Anum_pg_type_typtype - 1] = CharGetDatum(typeType); values[Anum_pg_type_typcategory - 1] = CharGetDatum(typeCategory); values[Anum_pg_type_typispreferred - 1] = BoolGetDatum(typePreferred); values[Anum_pg_type_typisdefined - 1] = BoolGetDatum(true); values[Anum_pg_type_typdelim - 1] = CharGetDatum(typDelim); values[Anum_pg_type_typrelid - 1] = ObjectIdGetDatum(relationOid); values[Anum_pg_type_typelem - 1] = ObjectIdGetDatum(elementType); values[Anum_pg_type_typarray - 1] = ObjectIdGetDatum(arrayType); values[Anum_pg_type_typinput - 1] = ObjectIdGetDatum(inputProcedure); values[Anum_pg_type_typoutput - 1] = ObjectIdGetDatum(outputProcedure); values[Anum_pg_type_typreceive - 1] = ObjectIdGetDatum(receiveProcedure); values[Anum_pg_type_typsend - 1] = ObjectIdGetDatum(sendProcedure); values[Anum_pg_type_typmodin - 1] = ObjectIdGetDatum(typmodinProcedure); values[Anum_pg_type_typmodout - 1] = ObjectIdGetDatum(typmodoutProcedure); values[Anum_pg_type_typanalyze - 1] = ObjectIdGetDatum(analyzeProcedure); values[Anum_pg_type_typalign - 1] = CharGetDatum(alignment); values[Anum_pg_type_typstorage - 1] = CharGetDatum(storage); values[Anum_pg_type_typnotnull - 1] = BoolGetDatum(typeNotNull); values[Anum_pg_type_typbasetype - 1] = ObjectIdGetDatum(baseType); values[Anum_pg_type_typtypmod - 1] = Int32GetDatum(typeMod); values[Anum_pg_type_typndims - 1] = Int32GetDatum(typNDims); values[Anum_pg_type_typcollation - 1] = ObjectIdGetDatum(typeCollation); /* * initialize the default binary value for this type. Check for nulls of * course. */ if (defaultTypeBin) values[Anum_pg_type_typdefaultbin - 1] = CStringGetTextDatum(defaultTypeBin); else nulls[Anum_pg_type_typdefaultbin - 1] = true; /*
开发者ID:adunstan,项目名称:postgresql-dev,代码行数:67,
示例28: TypeShellMake/* ---------------------------------------------------------------- * TypeShellMake * * This procedure inserts a "shell" tuple into the pg_type relation. * The type tuple inserted has valid but dummy values, and its * "typisdefined" field is false indicating it's not really defined. * * This is used so that a tuple exists in the catalogs. The I/O * functions for the type will link to this tuple. When the full * CREATE TYPE command is issued, the bogus values will be replaced * with correct ones, and "typisdefined" will be set to true. * ---------------------------------------------------------------- */OidTypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId){ Relation pg_type_desc; TupleDesc tupDesc; int i; HeapTuple tup; Datum values[Natts_pg_type]; bool nulls[Natts_pg_type]; Oid typoid; NameData name; Assert(PointerIsValid(typeName)); /* * open pg_type */ pg_type_desc = heap_open(TypeRelationId, RowExclusiveLock); tupDesc = pg_type_desc->rd_att; /* * initialize our *nulls and *values arrays */ for (i = 0; i < Natts_pg_type; ++i) { nulls[i] = false; values[i] = (Datum) NULL; /* redundant, but safe */ } /* * initialize *values with the type name and dummy values * * The representational details are the same as int4 ... it doesn't really * matter what they are so long as they are consistent. Also note that we * give it typtype = TYPTYPE_PSEUDO as extra insurance that it won't be * mistaken for a usable type. */ namestrcpy(&name, typeName); values[Anum_pg_type_typname - 1] = NameGetDatum(&name); values[Anum_pg_type_typnamespace - 1] = ObjectIdGetDatum(typeNamespace); values[Anum_pg_type_typowner - 1] = ObjectIdGetDatum(ownerId); values[Anum_pg_type_typlen - 1] = Int16GetDatum(sizeof(int32)); values[Anum_pg_type_typbyval - 1] = BoolGetDatum(true); values[Anum_pg_type_typtype - 1] = CharGetDatum(TYPTYPE_PSEUDO); values[Anum_pg_type_typcategory - 1] = CharGetDatum(TYPCATEGORY_PSEUDOTYPE); values[Anum_pg_type_typispreferred - 1] = BoolGetDatum(false); values[Anum_pg_type_typisdefined - 1] = BoolGetDatum(false); values[Anum_pg_type_typdelim - 1] = CharGetDatum(DEFAULT_TYPDELIM); values[Anum_pg_type_typrelid - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typelem - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typarray - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typinput - 1] = ObjectIdGetDatum(F_SHELL_IN); values[Anum_pg_type_typoutput - 1] = ObjectIdGetDatum(F_SHELL_OUT); values[Anum_pg_type_typreceive - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typsend - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typmodin - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typmodout - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typanalyze - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typalign - 1] = CharGetDatum('i'); values[Anum_pg_type_typstorage - 1] = CharGetDatum('p'); values[Anum_pg_type_typnotnull - 1] = BoolGetDatum(false); values[Anum_pg_type_typbasetype - 1] = ObjectIdGetDatum(InvalidOid); values[Anum_pg_type_typtypmod - 1] = Int32GetDatum(-1); values[Anum_pg_type_typndims - 1] = Int32GetDatum(0); values[Anum_pg_type_typcollation - 1] = ObjectIdGetDatum(InvalidOid); nulls[Anum_pg_type_typdefaultbin - 1] = true; nulls[Anum_pg_type_typdefault - 1] = true; nulls[Anum_pg_type_typacl - 1] = true; /* * create a new type tuple */ tup = heap_form_tuple(tupDesc, values, nulls); /* Use binary-upgrade override for pg_type.oid, if supplied. */ if (IsBinaryUpgrade && OidIsValid(binary_upgrade_next_pg_type_oid)) { HeapTupleSetOid(tup, binary_upgrade_next_pg_type_oid); binary_upgrade_next_pg_type_oid = InvalidOid; } /* * insert the tuple in the relation and get the tuple's oid. */ typoid = simple_heap_insert(pg_type_desc, tup); CatalogUpdateIndexes(pg_type_desc, tup);//.........这里部分代码省略.........
开发者ID:adunstan,项目名称:postgresql-dev,代码行数:101,
示例29: DeserializeTuple/* * Deserialize a HeapTuple's data from a byte-array. * * This code is based on the binary input handling functions in copy.c. */HeapTupleDeserializeTuple(SerTupInfo * pSerInfo, StringInfo serialTup){ MemoryContext oldCtxt; TupleDesc tupdesc; HeapTuple htup; int natts; SerAttrInfo *attrInfo; uint32 attr_size; int i; StringInfoData attr_data; bool fHandled; AssertArg(pSerInfo != NULL); AssertArg(serialTup != NULL); tupdesc = pSerInfo->tupdesc; natts = tupdesc->natts; /* * Flip to our tuple-serialization memory-context, to speed up memory * reclamation operations. */ AssertState(s_tupSerMemCtxt != NULL); oldCtxt = MemoryContextSwitchTo(s_tupSerMemCtxt); /* Receive nulls character-array. */ pq_copymsgbytes(serialTup, pSerInfo->nulls, natts); skipPadding(serialTup); /* Deserialize the non-NULL attributes of this tuple */ initStringInfo(&attr_data); for (i = 0; i < natts; ++i) { attrInfo = pSerInfo->myinfo + i; if (pSerInfo->nulls[i]) /* NULL field. */ { pSerInfo->values[i] = (Datum) 0; continue; } /* * Assume that the data's output will be handled by the special IO * code, and if not then we can handle it the slow way. */ fHandled = true; switch (attrInfo->atttypid) { case INT4OID: pSerInfo->values[i] = Int32GetDatum(stringInfoGetInt32(serialTup)); break; case CHAROID: pSerInfo->values[i] = CharGetDatum(pq_getmsgbyte(serialTup)); skipPadding(serialTup); break; case BPCHAROID: case VARCHAROID: case INT2VECTOROID: /* postgres serialization logic broken, use our own */ case OIDVECTOROID: /* postgres serialization logic broken, use our own */ case ANYARRAYOID: { text *pText; int textSize; textSize = stringInfoGetInt32(serialTup);#ifdef TUPSER_SCRATCH_SPACE if (textSize + VARHDRSZ <= attrInfo->varlen_scratch_size) pText = (text *) attrInfo->pv_varlen_scratch; else pText = (text *) palloc(textSize + VARHDRSZ);#else pText = (text *) palloc(textSize + VARHDRSZ);#endif SET_VARSIZE(pText, textSize + VARHDRSZ); pq_copymsgbytes(serialTup, VARDATA(pText), textSize); skipPadding(serialTup); pSerInfo->values[i] = PointerGetDatum(pText); break; } case DATEOID: { /* * TODO: I would LIKE to do something more efficient, but * DateADT is not strictly limited to 4 bytes by its * definition. */ DateADT date;//.........这里部分代码省略.........
开发者ID:50wu,项目名称:gpdb,代码行数:101,
示例30: CreateConstraintEntry//.........这里部分代码省略......... conffeqopArray = construct_array(fkdatums, foreignNKeys, OIDOID, sizeof(Oid), true, 'i'); } else { confkeyArray = NULL; conpfeqopArray = NULL; conppeqopArray = NULL; conffeqopArray = NULL; } if (exclOp != NULL) { Datum *opdatums; opdatums = (Datum *) palloc(constraintNKeys * sizeof(Datum)); for (i = 0; i < constraintNKeys; i++) opdatums[i] = ObjectIdGetDatum(exclOp[i]); conexclopArray = construct_array(opdatums, constraintNKeys, OIDOID, sizeof(Oid), true, 'i'); } else conexclopArray = NULL; /* initialize nulls and values */ for (i = 0; i < Natts_pg_constraint; i++) { nulls[i] = false; values[i] = (Datum) NULL; } values[Anum_pg_constraint_conname - 1] = NameGetDatum(&cname); values[Anum_pg_constraint_connamespace - 1] = ObjectIdGetDatum(constraintNamespace); values[Anum_pg_constraint_contype - 1] = CharGetDatum(constraintType); values[Anum_pg_constraint_condeferrable - 1] = BoolGetDatum(isDeferrable); values[Anum_pg_constraint_condeferred - 1] = BoolGetDatum(isDeferred); values[Anum_pg_constraint_convalidated - 1] = BoolGetDatum(isValidated); values[Anum_pg_constraint_conrelid - 1] = ObjectIdGetDatum(relId); values[Anum_pg_constraint_contypid - 1] = ObjectIdGetDatum(domainId); values[Anum_pg_constraint_conindid - 1] = ObjectIdGetDatum(indexRelId); values[Anum_pg_constraint_confrelid - 1] = ObjectIdGetDatum(foreignRelId); values[Anum_pg_constraint_confupdtype - 1] = CharGetDatum(foreignUpdateType); values[Anum_pg_constraint_confdeltype - 1] = CharGetDatum(foreignDeleteType); values[Anum_pg_constraint_confmatchtype - 1] = CharGetDatum(foreignMatchType); values[Anum_pg_constraint_conislocal - 1] = BoolGetDatum(conIsLocal); values[Anum_pg_constraint_coninhcount - 1] = Int32GetDatum(conInhCount); values[Anum_pg_constraint_connoinherit - 1] = BoolGetDatum(conNoInherit); if (conkeyArray) values[Anum_pg_constraint_conkey - 1] = PointerGetDatum(conkeyArray); else nulls[Anum_pg_constraint_conkey - 1] = true; if (confkeyArray) values[Anum_pg_constraint_confkey - 1] = PointerGetDatum(confkeyArray); else nulls[Anum_pg_constraint_confkey - 1] = true; if (conpfeqopArray) values[Anum_pg_constraint_conpfeqop - 1] = PointerGetDatum(conpfeqopArray); else nulls[Anum_pg_constraint_conpfeqop - 1] = true; if (conppeqopArray) values[Anum_pg_constraint_conppeqop - 1] = PointerGetDatum(conppeqopArray); else
开发者ID:PJMODOS,项目名称:postgres,代码行数:67,
注:本文中的CharGetDatum函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CharNext函数代码示例 C++ Channel函数代码示例 |