Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# npgsql_wrapper (C++)
PgSQL C++ Wrapper for web_jsx (FCGI/CGI Application)<br/>
# Multi Connection Pool PgSQL C++ Wrapper for web_jsx (FCGI/CGI Application)<br/>
#Include header file
```c++
#if !defined(_npgsql_h)
Expand Down
11 changes: 5 additions & 6 deletions src/connection_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
#if defined(_MSC_VER)
#pragma once
#if !defined(_npgsql_global_h)
#include "npgsql_global.h"
#endif//!_global_h
#endif//!_MSC_VER
#if !defined(_connection_state_h)
#define _connection_state_h
#pragma warning (disable : 4231)
# define _connection_state_h
//#pragma warning (disable : 4231)
typedef enum {
OPEN = 1,
CLOSED = 0
} connection_state;
#endif//!_parameter_direction_h
#endif//!_connection_state_h
Binary file modified src/npgsql.cpp
Binary file not shown.
96 changes: 46 additions & 50 deletions src/npgsql.h
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
////8:44 AM 11/19/2018 Start
#if defined(_MSC_VER)
#pragma once
#endif//!_MSC_VER
#if !defined(_npgsql_h)
#pragma warning (disable : 4231)
#define _npgsql_h
#if !defined(_npgsql_global_h)
#include "npgsql_global.h"
#endif//!_global_h
//5:27 PM 11/19/2018
#if !defined(_pg_sql_h)
#include "pg_sql.h"
#endif//!_global_h
#if !defined(_npgsql_db_type_h)
#include "npgsql_db_type.h"
#endif//!_npgsql_db_type_h
#if !defined(_parameter_direction_h)
#include "npgsql_params.h"
#endif//!_parameter_direction_h
#if !defined(_npgsql_param_type_h)
#include "npgsql_param_type.h"
#endif//!_npgsql_param_type_h
#if !defined(_npgsql_result_h)
#include "npgsql_result.h"
#endif//!_npgsql_result_h
#if !defined(_connection_state_h)
#include "connection_state.h"
#endif//!_connection_state_h
#ifndef _REGEX_
#include <regex>
#endif// !_REGEX_
# define _npgsql_h
# include "npgsql_global.h"
# include "pg_sql.h"
# include "npgsql_db_type.h"
# include "npgsql_params.h"
# include "npgsql_param_type.h"
# include "npgsql_result.h"
# include "connection_state.h"
# include <regex>

#if !defined(_free_obj)
# define _free_obj(obj)\
while(obj){\
obj->clear();delete obj;obj = NULL;\
}
#endif//!_free_obj
class NPGSQL_API npgsql {
public:
connection_state conn_state;
private:
//pg_connection_pool _active_conn; //!TODO
pg_sql* _pgsql;
const char* _conn;
std::string* _conn;
char* _internal_error;
void panic(const char* error);
int check_con_status();
protected:
int _is_disposed;
void create_instance();
public:
npgsql(const char* lib_path);
npgsql();
explicit npgsql(const char* lib_path);
explicit npgsql();
npgsql(const npgsql&) = delete;
npgsql& operator=(const npgsql&) = delete;
~npgsql();
void quote_literal(std::string&str) {
str = "'" + str + "'";
return;
};
virtual const char * get_last_error();
virtual int connect(const char* conn);
virtual int execute_scalar(const char *query, char *result);
virtual int execute_scalar(const char *sp, std::list<npgsql_params*>&sql_param, std::map<std::string, char*>& result);
virtual int execute_io(const char *sp, const char *login_id, const char *form_data, std::map<std::string, char*>& result);
}
const char * get_last_error();
int connect(const char* conn);
int connect();
int execute_scalar(const char *query, char *result);
int execute_scalar(const char *sp, std::list<npgsql_params*>&sql_param, std::map<std::string, char*>& result);
int execute_io(const char *sp, const char *login_id, const char *form_data, std::map<std::string, char*>& result);
// Execute the statement
virtual int execute_non_query(const char *query);
virtual const char* execute_query(const char * query, int&rec);
int execute_non_query(const char *query);
const char* execute_query(const char * query, int&rec);
template<class _func>
int execute_scalar(const char *query, _func func);
template<class _func>
int execute_scalar(const char *query, std::list<npgsql_params*>&sql_param, _func func);
template<class _func>
int execute_scalar_l(const char *query, std::list<npgsql_param_type*>&sql_param, _func func);
virtual int close();
int close();
void release();
};
#pragma warning (default : 4231)
template<class _func>
inline int npgsql::execute_scalar(const char * query, _func func) {
return _pgsql->execute_scalar(query, func);
};
}

template<class _func>
inline int npgsql::execute_scalar( const char* query, std::list<npgsql_params*>& sql_param, _func func ) {
Expand All @@ -85,7 +85,7 @@ inline int npgsql::execute_scalar( const char* query, std::list<npgsql_params*>&
param_stmt->append( param->parameter_name );
param_stmt->append( "=" );
param_stmt->append( val->c_str() );
free( val );
_free_obj( val );
param_stmt->append( "::" );
param_stmt->append( get_db_type( param->db_type ) );
continue;
Expand All @@ -95,19 +95,19 @@ inline int npgsql::execute_scalar( const char* query, std::list<npgsql_params*>&
param_stmt->append( param->parameter_name );
param_stmt->append( "=" );
param_stmt->append( val->c_str() );
free( val );
_free_obj( val );
param_stmt->append( "::" );
param_stmt->append( get_db_type( param->db_type ) );
}
int ret = 0;
if ( param_count <= 0 ) {
free( param_stmt );
_free_obj(param_stmt);
ret = _pgsql->execute_scalar( query, func );
} else {
std::string* stmt = new std::string( query );
stmt->append( param_stmt->c_str() ); free( param_stmt );
stmt->append( param_stmt->c_str() );
ret = _pgsql->execute_scalar( stmt->c_str(), func );
free( stmt );
_free_obj(stmt); _free_obj(param_stmt);
}
return ret;
}
Expand Down Expand Up @@ -136,15 +136,11 @@ inline int npgsql::execute_scalar_l( const char* query, std::list<npgsql_param_t
}
std::string& copy = *_query;
copy = std::regex_replace( copy, *re, val->c_str() );
//std::cout << val->c_str() << "<br/>";
//std::cout << copy << "<br/>";
free( str ); free( re ); free( val );
_free_obj(str); delete re; _free_obj(val);
}
}
//std::cout << _query->c_str() << "<br/>";
int ret = _pgsql->execute_scalar( _query->c_str(), func );
//free(_query);
delete _query;
_free_obj(_query);
return ret;
}
#endif // !npgsql_h
Binary file modified src/npgsql.rc
Binary file not shown.
25 changes: 25 additions & 0 deletions src/npgsql_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2018, SOW (https://www.safeonline.world). (https://github.com/RKTUXYN) All rights reserved.
* @author {SOW}
* Copyrights licensed under the New BSD License.
* See the accompanying LICENSE file for terms.
*/
//11:42 AM 2/19/2020
#if defined(_MSC_VER)
#pragma once
#endif//!_MSC_VER
#if !defined(_npgsql_config_h)
# define _npgsql_config_h
#if defined(NPGSQL_EXPORTS)
# define NPGSQL_API __declspec(dllexport)
#else
# define NPGSQL_API __declspec(dllimport)
#endif//!NPGSQL_EXPORTS
#if !defined(_free_obj)
# define _free_obj(obj)\
while(obj){\
obj->clear();delete obj;obj = NULL;\
}
#endif//!_free_obj
# define SUCCESS 1
#endif//!_npgsql_config_h
Loading