예제 #1
0
struct StatementList *AppendStatementLists(CONST struct StatementList *sl1,
                                           struct StatementList *sl2)
{
  register CONST struct gl_list_t *l1;
  register struct gl_list_t *list,*l2;
  register struct Statement *stat;
  register unsigned long c,len;
  assert(sl1 && sl2);
  l1 = GetList(sl1);
  l2 = GetList(sl2);
  len = gl_length(l1);
  list = gl_create(len+gl_length(l2));
  /* add elements from sl1 */
  for(c=1;c<=len;c++){
    stat = (struct Statement *)gl_fetch(l1,c);
    CopyStatement(stat);
    gl_append_ptr(list,(VOIDPTR)stat);
  }
  /* add elements from sl2 */
  len = gl_length(l2);
  for(c=1;c<=len;c++){
    stat = (struct Statement *)gl_fetch(l2,c);
    CopyStatement(stat);
    gl_append_ptr(list,(VOIDPTR)stat);
  }
  DestroyStatementList(sl2);
  return CreateStatementList(list);
}
예제 #2
0
/*
 * CopyTaskFilesFromDirectory finds all files in the given directory, except for
 * those having an attempt suffix. The function then copies these files into the
 * database table identified by the given schema and table name.
 */
static void
CopyTaskFilesFromDirectory(StringInfo schemaName, StringInfo relationName,
						   StringInfo sourceDirectoryName)
{
	const char *directoryName = sourceDirectoryName->data;
	struct dirent *directoryEntry = NULL;
	uint64 copiedRowTotal = 0;

	DIR *directory = AllocateDir(directoryName);
	if (directory == NULL)
	{
		ereport(ERROR, (errcode_for_file_access(),
						errmsg("could not open directory \"%s\": %m", directoryName)));
	}

	directoryEntry = ReadDir(directory, directoryName);
	for (; directoryEntry != NULL; directoryEntry = ReadDir(directory, directoryName))
	{
		const char *baseFilename = directoryEntry->d_name;
		const char *queryString = NULL;
		StringInfo fullFilename = NULL;
		RangeVar *relation = NULL;
		CopyStmt *copyStatement = NULL;
		uint64 copiedRowCount = 0;

		/* if system file or lingering task file, skip it */
		if (strncmp(baseFilename, ".", MAXPGPATH) == 0 ||
			strncmp(baseFilename, "..", MAXPGPATH) == 0 ||
			strstr(baseFilename, ATTEMPT_FILE_SUFFIX) != NULL)
		{
			continue;
		}

		fullFilename = makeStringInfo();
		appendStringInfo(fullFilename, "%s/%s", directoryName, baseFilename);

		/* build relation object and copy statement */
		relation = makeRangeVar(schemaName->data, relationName->data, -1);
		copyStatement = CopyStatement(relation, fullFilename->data);
		if (BinaryWorkerCopyFormat)
		{
			DefElem *copyOption = makeDefElem("format", (Node *) makeString("binary"));
			copyStatement->options = list_make1(copyOption);
		}

		DoCopy(copyStatement, queryString, &copiedRowCount);
		copiedRowTotal += copiedRowCount;
		CommandCounterIncrement();
	}

	ereport(DEBUG2, (errmsg("copied " UINT64_FORMAT " rows into table: \"%s.%s\"",
							copiedRowTotal, schemaName->data, relationName->data)));

	FreeDir(directory);
}
예제 #3
0
void AppendStatement(struct StatementList *sl1, struct Statement *s)
{
  register struct gl_list_t *l1;

  assert(s!=NULL);
  if (sl1 ==NULL) {
    sl1 = EmptyStatementList();
  }
  l1 = GetList(sl1);
  CopyStatement(s);
  gl_append_ptr(l1,(VOIDPTR)s);
}
예제 #4
0
		ProcessUtility(ddlCommandNode, ddlCommand->data, PROCESS_UTILITY_TOPLEVEL,
					   NULL, None_Receiver, NULL);
		CommandCounterIncrement();
	}

	SetUserIdAndSecContext(savedUserId, savedSecurityContext);

	/*
	 * Copy local file into the relation. We call ProcessUtility() instead of
	 * directly calling DoCopy() because some extensions (e.g. cstore_fdw) hook
	 * into process utility to provide their custom COPY behavior.
	 */
	tableNameList = stringToQualifiedNameList(tableName);
	localTable = makeRangeVarFromNameList(tableNameList);
	localCopyCommand = CopyStatement(localTable, localFilePath->data);

	queryString = makeStringInfo();
	appendStringInfo(queryString, COPY_IN_COMMAND, tableName, localFilePath->data);

	ProcessUtility((Node *) localCopyCommand, queryString->data,
				   PROCESS_UTILITY_TOPLEVEL, NULL, None_Receiver, NULL);

	/* finally delete the temporary file we created */
	DeleteFile(localFilePath->data);

	return true;
}


/*
예제 #5
0
파일: copy.c 프로젝트: tcsilver/ecere-sdk
struct Expression * CopyExpression(struct Expression * exp)
{
struct Expression * result = (((void *)0));

if(exp)
switch(exp->type)
{
case 16:
result = MkExpDummy();
break;
case 0:
result = MkExpIdentifier(CopyIdentifier(exp->identifier));
break;
case 1:
result = MkExpInstance(CopyInstantiation(exp->instance));
break;
case 2:
result = MkExpConstant(exp->string);
break;
case 3:
result = MkExpString(exp->string);
break;
case 4:
result = MkExpOp(CopyExpression(exp->op.exp1), exp->op.op, CopyExpression(exp->op.exp2));
break;
case 5:
{
struct __ecereNameSpace__ecere__sys__OldList * list = MkList();
struct Expression * e;

for(e = (*exp->list).first; e; e = e->next)
ListAdd(list, CopyExpression(e));
result = MkExpBrackets(list);
break;
}
case 6:
{
struct __ecereNameSpace__ecere__sys__OldList * list = MkList();
struct Expression * e;

for(e = (*exp->index.index).first; e; e = e->next)
ListAdd(list, CopyExpression(e));
result = MkExpIndex(CopyExpression(exp->index.exp), list);
break;
}
case 7:
{
struct __ecereNameSpace__ecere__sys__OldList * list = MkList();
struct Expression * arg;

if(exp->call.arguments)
{
for(arg = (*exp->call.arguments).first; arg; arg = arg->next)
ListAdd(list, CopyExpression(arg));
}
result = MkExpCall(CopyExpression(exp->call.exp), list);
break;
}
case 8:
result = MkExpMember(CopyExpression(exp->member.exp), CopyIdentifier(exp->member.member));
result->member.memberType = exp->member.memberType;
result->member.thisPtr = exp->member.thisPtr;
break;
case 9:
result = MkExpPointer(CopyExpression(exp->member.exp), CopyIdentifier(exp->member.member));
break;
case 10:
result = MkExpTypeSize(CopyTypeName(exp->typeName));
break;
case 38:
result = MkExpTypeAlign(CopyTypeName(exp->typeName));
break;
case 11:
result = MkExpCast(CopyTypeName(exp->cast.typeName), CopyExpression(exp->cast.exp));
break;
case 12:
{
struct __ecereNameSpace__ecere__sys__OldList * list = MkList();
struct Expression * e;

for(e = (*exp->cond.exp).first; e; e = e->next)
ListAdd(list, CopyExpression(e));
result = MkExpCondition(CopyExpression(exp->cond.cond), list, CopyExpression(exp->cond.elseExp));
break;
}
case 36:
result = MkExpVaArg(CopyExpression(exp->vaArg.exp), CopyTypeName(exp->vaArg.typeName));
break;
case 25:
result = MkExpExtensionCompound(CopyStatement(exp->compound));
break;
}
if(result)
{
result->expType = exp->expType;
if(exp->expType)
exp->expType->refCount++;
result->destType = exp->destType;
if(exp->destType)
exp->destType->refCount++;
result->loc = exp->loc;
result->isConstant = exp->isConstant;
result->byReference = exp->byReference;
}
return result;
}