Skip to content

Multi Connection Pool PgSQL C++ Wrapper for web_jsx (CGI Application)

License

MIT, CC-BY-4.0 licenses found

Licenses found

MIT
LICENSE
CC-BY-4.0
LICENSE-DOCS.md
Notifications You must be signed in to change notification settings

rktuxyn/npgsql_wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Multi Connection Pool PgSQL C++ Wrapper for web_jsx (FCGI/CGI Application)

#Include header file

#if !defined(_npgsql_h)
#include <npgsql.h>
#endif//!_npgsql_h
#if !defined(_npgsql_tools_h)
#include <npgsql_tools.h>
#endif//_npgsql_tools_h

#Initialize sow.npgsql.dll

npgsql* pgsql = new npgsql();
int rec = !pgsql->is_iniit ? -1 : 0;
if (rec < 0) {
	std::cout << "UNABLE TO LOAD PGSQL LIB==>" << pgsql->lib_absolute_path << "<br/>";
}

#Connect to PostgreSQL

const char* pg_conn = "Server=localhost; Port=5432; UserId=postgres;Password=*****;Database=sow; keepalive=10; CommandTimeout=100000;";
rec = pgsql->connect(pg_conn);
if (rec < 0) {
	std::cout << "Unable to connect db==>" << pgsql->lib_absolute_path << "<br/>";
	return __reslut;
};

#Call to Stored Procedure with param

std::list<npgsql_params*>* sql_param = new std::list<npgsql_params*>();
malloc(sizeof sql_param);
sql_param->push_back(new npgsql_params("login_id", npgsql_db_type::Varchar, parameter_direction::Input, "rajibs"));
sql_param->push_back(new npgsql_params("form_data", npgsql_db_type::Jsonb, parameter_direction::Input, "{}"));
sql_param->push_back(new npgsql_params("_ret_data_table", npgsql_db_type::Jsonb, parameter_direction::Output));
sql_param->push_back(new npgsql_params("_ret_val", npgsql_db_type::Bigint, parameter_direction::Output));
sql_param->push_back(new npgsql_params("_ret_msg", npgsql_db_type::Varchar, parameter_direction::Output));
std::map<std::string, char*>* result = new std::map<std::string, char*>();
malloc(sizeof result);
rec = pgsql->execute_scalar("auth.__check_npgsql", *sql_param, *result);
free(sql_param);
if (rec < 0) {
	std::cout << pgsql->get_last_error();
	pgsql->close();
	free(pgsql);
}else{
	pgsql->close();
	auto search = result->find("_ret_data_table");
	if (search != result->end()) {
		try {
			std::cout <<  search->second;
		} catch (std::exception&e) {
			std::cout << e.what() << '\n';
		}
	}
	else {
		std::cout << "Not found\n";
	}
	free(result);
}

#Call raw query

pgsql->execute_scalar("select * from information_schema.columns", [](int i, std::vector<char*>&row) {
	for (size_t i = 0; i < row.size(); ++i) {
		std::cout << row[i] << '\r\n';
	}
	return;
});

About

Multi Connection Pool PgSQL C++ Wrapper for web_jsx (CGI Application)

Resources

License

MIT, CC-BY-4.0 licenses found

Licenses found

MIT
LICENSE
CC-BY-4.0
LICENSE-DOCS.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published