Skip to content

Params question #1062

@pkfox

Description

@pkfox

Just to be clear this question relates to a hobby project

Is it common practice to create a new Params object when calling a function in a loop, I ask because I notice there is no clear() on Params and if they do have values you can't change them. I'm probably not doing this the optimal way but, I have a large json file and I want to put its objects in a postgresql table ( 1 object = 1 row ) I have code that reads the json file and returns a serialized object using one of my classes, and when I come to push to pg i use the code below , I commit at the end of processing , am I doing this properly ?

size_t PGConnect::WriteToPG(const Bigfoot bf)
{
try
	{
	pqxx::params Params;
	std::size_t RetVal = 0;
	Params.append(bf.name);
	Params.append(bf.value);
	Params.append(bf.isActive);
	Params.append(bf.timestamp);
	Params.append(bf.tags);
	Params.append(bf.description);
	Params.append(bf.pad);


	
		this->PGResult = this->PGTransaction.exec("select createbigfoot($1,$2,$3,$4,$5,$6,$7)", Params);
		RetVal = PGResult[0][0].as<size_t>();
	}
	catch (const std::exception& e)
	{
		std::cerr << "Error writing to database: " << e.what() << std::endl;
		return 0;
	}
	return RetVal;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions