Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
e84ed083
Commit
e84ed083
authored
Jan 15, 2016
by
Vinogradov Aleksei
Committed by
Pavel Vainerman
Feb 19, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Сделал создание DBInterface через std::shared_ptr
parent
dac5c703
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
23 deletions
+37
-23
MySQLInterface.cc
extensions/DBServer-MySQL/MySQLInterface.cc
+9
-7
PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
+9
-7
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+9
-7
DBInterface.h
include/DBInterface.h
+10
-2
No files found.
extensions/DBServer-MySQL/MySQLInterface.cc
View file @
e84ed083
...
...
@@ -40,7 +40,14 @@ MySQLInterface::MySQLInterface():
MySQLInterface
::~
MySQLInterface
()
{
try
{
close
();
}
catch
(
...
)
// пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора
{
cerr
<<
"MySQLInterface::~MySQLInterface(): an error occured while closing connection!"
<<
endl
;
}
delete
mysql
;
}
...
...
@@ -201,13 +208,8 @@ void MySQLInterface::makeResult(DBResult& dbres, MYSQL_RES* myres, bool finalize
mysql_free_result
(
myres
);
}
// -----------------------------------------------------------------------------------------
extern
"C"
DBInterface
*
create_mysqlinterface
()
{
return
new
MySQLInterface
();
}
// -----------------------------------------------------------------------------------------
extern
"C"
void
destroy_mysqlinterface
(
DBInterface
*
p
)
extern
"C"
std
::
shared_ptr
<
DBInterface
>
create_mysqlinterface
()
{
delete
p
;
return
std
::
shared_ptr
<
DBInterface
>
(
new
MySQLInterface
(),
DBInterfaceDeleter
())
;
}
// -----------------------------------------------------------------------------------------
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
View file @
e84ed083
...
...
@@ -19,7 +19,14 @@ PostgreSQLInterface::PostgreSQLInterface():
PostgreSQLInterface
::~
PostgreSQLInterface
()
{
try
{
close
();
}
catch
(
...
)
// пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора
{
cerr
<<
"MySQLInterface::~MySQLInterface(): an error occured while closing connection!"
<<
endl
;
}
}
// -----------------------------------------------------------------------------------------
...
...
@@ -167,13 +174,8 @@ void PostgreSQLInterface::makeResult(DBResult& dbres, const pqxx::result& res )
}
}
// -----------------------------------------------------------------------------------------
extern
"C"
DBInterface
*
create_postgresqlinterface
()
{
return
new
PostgreSQLInterface
();
}
// -----------------------------------------------------------------------------------------
extern
"C"
void
destroy_postgresqlinterface
(
DBInterface
*
p
)
extern
"C"
std
::
shared_ptr
<
DBInterface
>
create_postgresqlinterface
()
{
delete
p
;
return
std
::
shared_ptr
<
DBInterface
>
(
new
PostgreSQLInterface
(),
DBInterfaceDeleter
())
;
}
// -----------------------------------------------------------------------------------------
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
e84ed083
...
...
@@ -43,7 +43,14 @@ SQLiteInterface::SQLiteInterface():
SQLiteInterface
::~
SQLiteInterface
()
{
try
{
close
();
}
catch
(
...
)
// пропускаем все необработанные исключения, если требуется обработать нужно вызывать close() до деструктора
{
cerr
<<
"MySQLInterface::~MySQLInterface(): an error occured while closing connection!"
<<
endl
;
}
}
// -----------------------------------------------------------------------------------------
...
...
@@ -261,13 +268,8 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize
sqlite3_finalize
(
s
);
}
// -----------------------------------------------------------------------------------------
extern
"C"
DBInterface
*
create_sqliteinterface
()
{
return
new
SQLiteInterface
();
}
// -----------------------------------------------------------------------------------------
extern
"C"
void
destroy_sqliteinterface
(
DBInterface
*
p
)
extern
"C"
std
::
shared_ptr
<
DBInterface
>
create_sqliteinterface
()
{
delete
p
;
return
std
::
shared_ptr
<
DBInterface
>
(
new
SQLiteInterface
(),
DBInterfaceDeleter
())
;
}
// -----------------------------------------------------------------------------------------
include/DBInterface.h
View file @
e84ed083
...
...
@@ -77,9 +77,17 @@ class DBResult
ROW
row_
;
};
// ----------------------------------------------------------------------------------
struct
DBInterfaceDeleter
{
void
operator
()(
DBInterface
*
p
)
const
{
try
{
delete
p
;
}
catch
(...)
{}
}
};
// ----------------------------------------------------------------------------------
// the types of the class factories
typedef
DBInterface
*
create_dbinterface_t
();
typedef
void
destroy_dbinterface_t
(
DBInterface
*
);
typedef
std
::
shared_ptr
<
DBInterface
>
create_dbinterface_t
();
// --------------------------------------------------------------------------
#endif // DBInterface_H_
// --------------------------------------------------------------------------
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment