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
00911199
Commit
00911199
authored
Dec 19, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make style, new release
parent
04cf4bc4
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
36 deletions
+51
-36
MySQLInterface.cc
extensions/DBServer-MySQL/MySQLInterface.cc
+1
-0
MySQLInterface.h
extensions/DBServer-MySQL/MySQLInterface.h
+12
-11
PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
+11
-10
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+3
-0
SQLiteInterface.h
extensions/DBServer-SQLite/SQLiteInterface.h
+11
-10
DBInterface.h
include/DBInterface.h
+5
-5
DBInterface.cc
src/Services/DBInterface.cc
+8
-0
No files found.
extensions/DBServer-MySQL/MySQLInterface.cc
View file @
00911199
...
@@ -92,6 +92,7 @@ DBResult MySQLInterface::query( const std::string& q )
...
@@ -92,6 +92,7 @@ DBResult MySQLInterface::query( const std::string& q )
if
(
!
res
||
mysql_num_rows
(
res
)
==
0
)
if
(
!
res
||
mysql_num_rows
(
res
)
==
0
)
return
DBResult
();
return
DBResult
();
DBResult
dbres
;
DBResult
dbres
;
makeResult
(
dbres
,
res
,
true
);
makeResult
(
dbres
,
res
,
true
);
return
dbres
;
return
dbres
;
...
...
extensions/DBServer-MySQL/MySQLInterface.h
View file @
00911199
...
@@ -33,7 +33,8 @@
...
@@ -33,7 +33,8 @@
#include <mysql/mysql.h>
#include <mysql/mysql.h>
#include <DBInterface.h>
#include <DBInterface.h>
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class
MySQLInterface
:
public
DBNetInterface
class
MySQLInterface
:
public
DBNetInterface
{
{
public
:
public
:
...
@@ -42,17 +43,17 @@ class MySQLInterface : public DBNetInterface
...
@@ -42,17 +43,17 @@ class MySQLInterface : public DBNetInterface
// DBResult listFields( const std::string& table, const std::string& wild );
// DBResult listFields( const std::string& table, const std::string& wild );
bool
nconnect
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
pswd
,
virtual
bool
nconnect
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
pswd
,
const
std
::
string
&
dbname
)
override
;
const
std
::
string
&
dbname
)
override
;
bool
close
()
override
;
virtual
bool
close
()
override
;
bool
query_ok
(
const
std
::
string
&
q
);
bool
query_ok
(
const
std
::
string
&
q
);
// \param finalize - освободить буфер после запроса
// \param finalize - освободить буфер после запроса
DBResult
query
(
const
std
::
string
&
q
)
override
;
virtual
DBResult
query
(
const
std
::
string
&
q
)
override
;
const
std
::
string
lastQuery
()
override
;
virtual
const
std
::
string
lastQuery
()
override
;
bool
insert
(
const
std
::
string
&
q
)
override
;
virtual
bool
insert
(
const
std
::
string
&
q
)
override
;
std
::
string
addslashes
(
const
std
::
string
&
str
);
std
::
string
addslashes
(
const
std
::
string
&
str
);
...
@@ -60,14 +61,14 @@ class MySQLInterface : public DBNetInterface
...
@@ -60,14 +61,14 @@ class MySQLInterface : public DBNetInterface
проверка связи с БД.
проверка связи с БД.
в случае отсутсвия попытка восстановить...
в случае отсутсвия попытка восстановить...
*/
*/
bool
ping
()
override
;
virtual
bool
ping
()
override
;
/*! связь с БД установлена (была) */
/*! связь с БД установлена (была) */
bool
isConnection
()
override
;
virtual
bool
isConnection
()
override
;
double
insert_id
()
override
;
virtual
double
insert_id
()
override
;
const
std
::
string
error
()
override
;
virtual
const
std
::
string
error
()
override
;
// *******************
// *******************
const
char
*
gethostinfo
();
const
char
*
gethostinfo
();
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
View file @
00911199
...
@@ -10,27 +10,28 @@
...
@@ -10,27 +10,28 @@
#include <PassiveTimer.h>
#include <PassiveTimer.h>
#include <DBInterface.h>
#include <DBInterface.h>
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class
PostgreSQLInterface
:
public
DBNetInterface
class
PostgreSQLInterface
:
public
DBNetInterface
{
{
public
:
public
:
PostgreSQLInterface
();
PostgreSQLInterface
();
~
PostgreSQLInterface
();
~
PostgreSQLInterface
();
bool
nconnect
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
pswd
,
const
std
::
string
&
dbname
)
override
;
virtual
bool
nconnect
(
const
std
::
string
&
host
,
const
std
::
string
&
user
,
const
std
::
string
&
pswd
,
const
std
::
string
&
dbname
)
override
;
bool
close
()
override
;
virtual
bool
close
()
override
;
bool
isConnection
()
override
;
virtual
bool
isConnection
()
override
;
bool
ping
()
override
;
// проверка доступности БД
virtual
bool
ping
()
override
;
// проверка доступности БД
DBResult
query
(
const
std
::
string
&
q
)
override
;
virtual
DBResult
query
(
const
std
::
string
&
q
)
override
;
const
std
::
string
lastQuery
()
override
;
virtual
const
std
::
string
lastQuery
()
override
;
bool
insert
(
const
std
::
string
&
q
)
override
;
virtual
bool
insert
(
const
std
::
string
&
q
)
override
;
bool
insertAndSaveRowid
(
const
std
::
string
&
q
);
bool
insertAndSaveRowid
(
const
std
::
string
&
q
);
double
insert_id
()
override
;
virtual
double
insert_id
()
override
;
void
save_inserted_id
(
const
pqxx
::
result
&
res
);
void
save_inserted_id
(
const
pqxx
::
result
&
res
);
const
std
::
string
error
()
override
;
virtual
const
std
::
string
error
()
override
;
protected
:
protected
:
...
...
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
00911199
...
@@ -56,13 +56,16 @@ bool SQLiteInterface::connect( const std::string& param )
...
@@ -56,13 +56,16 @@ bool SQLiteInterface::connect( const std::string& param )
{
{
std
::
string
dbfile
;
std
::
string
dbfile
;
std
::
string
::
size_type
pos
=
param
.
find_first_of
(
":"
);
std
::
string
::
size_type
pos
=
param
.
find_first_of
(
":"
);
if
(
pos
!=
std
::
string
::
npos
)
if
(
pos
!=
std
::
string
::
npos
)
{
{
dbfile
=
param
.
substr
(
0
,
pos
);
dbfile
=
param
.
substr
(
0
,
pos
);
std
::
string
create_str
=
param
.
substr
(
pos
+
1
,
std
::
string
::
npos
);
std
::
string
create_str
=
param
.
substr
(
pos
+
1
,
std
::
string
::
npos
);
if
(
create_str
==
"true"
)
if
(
create_str
==
"true"
)
return
connect
(
dbfile
,
true
);
return
connect
(
dbfile
,
true
);
}
}
return
connect
(
dbfile
,
false
);
return
connect
(
dbfile
,
false
);
}
}
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
...
...
extensions/DBServer-SQLite/SQLiteInterface.h
View file @
00911199
...
@@ -82,18 +82,19 @@
...
@@ -82,18 +82,19 @@
// PRAGMA journal_mode = MEMORY
// PRAGMA journal_mode = MEMORY
// При этом конечно есть риск потерять данные при выключении..
// При этом конечно есть риск потерять данные при выключении..
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
class
SQLiteInterface
:
public
DBInterface
class
SQLiteInterface
:
public
DBInterface
{
{
public
:
public
:
SQLiteInterface
();
SQLiteInterface
();
~
SQLiteInterface
();
~
SQLiteInterface
();
bool
connect
(
const
std
::
string
&
param
)
override
;
virtual
bool
connect
(
const
std
::
string
&
param
)
override
;
bool
connect
(
const
std
::
string
&
dbfile
,
bool
create
);
bool
connect
(
const
std
::
string
&
dbfile
,
bool
create
);
bool
close
()
override
;
virtual
bool
close
()
override
;
bool
isConnection
()
override
;
virtual
bool
isConnection
()
override
;
bool
ping
()
override
;
// проверка доступности БД
virtual
bool
ping
()
override
;
// проверка доступности БД
void
setOperationTimeout
(
timeout_t
msec
);
void
setOperationTimeout
(
timeout_t
msec
);
inline
timeout_t
getOperationTimeout
()
inline
timeout_t
getOperationTimeout
()
...
@@ -110,13 +111,13 @@ class SQLiteInterface : public DBInterface
...
@@ -110,13 +111,13 @@ class SQLiteInterface : public DBInterface
return
opCheckPause
;
return
opCheckPause
;
}
}
DBResult
query
(
const
std
::
string
&
q
)
override
;
virtual
DBResult
query
(
const
std
::
string
&
q
)
override
;
const
std
::
string
lastQuery
()
override
;
virtual
const
std
::
string
lastQuery
()
override
;
bool
insert
(
const
std
::
string
&
q
)
override
;
virtual
bool
insert
(
const
std
::
string
&
q
)
override
;
double
insert_id
()
override
;
virtual
double
insert_id
()
override
;
const
std
::
string
error
()
override
;
virtual
const
std
::
string
error
()
override
;
protected
:
protected
:
...
...
include/DBInterface.h
View file @
00911199
...
@@ -14,8 +14,8 @@ class DBInterface
...
@@ -14,8 +14,8 @@ class DBInterface
{
{
public
:
public
:
DBInterface
(){};
DBInterface
()
{};
virtual
~
DBInterface
(){};
virtual
~
DBInterface
()
{};
// Функция подключения к БД, параметры подключения зависят от типа БД
// Функция подключения к БД, параметры подключения зависят от типа БД
virtual
bool
connect
(
const
std
::
string
&
param
)
=
0
;
virtual
bool
connect
(
const
std
::
string
&
param
)
=
0
;
...
@@ -34,8 +34,8 @@ class DBNetInterface : public DBInterface
...
@@ -34,8 +34,8 @@ class DBNetInterface : public DBInterface
{
{
public
:
public
:
DBNetInterface
(){};
DBNetInterface
()
{};
virtual
~
DBNetInterface
(){};
virtual
~
DBNetInterface
()
{};
// Для сетевых БД параметры должны быть в формате user@host:pswd:dbname
// Для сетевых БД параметры должны быть в формате user@host:pswd:dbname
virtual
bool
connect
(
const
std
::
string
&
param
);
virtual
bool
connect
(
const
std
::
string
&
param
);
...
@@ -47,7 +47,7 @@ class DBResult
...
@@ -47,7 +47,7 @@ class DBResult
public
:
public
:
DBResult
()
{}
DBResult
()
{}
virtual
~
DBResult
(){};
virtual
~
DBResult
()
{};
typedef
std
::
vector
<
std
::
string
>
COL
;
typedef
std
::
vector
<
std
::
string
>
COL
;
typedef
std
::
deque
<
COL
>
ROW
;
typedef
std
::
deque
<
COL
>
ROW
;
...
...
src/Services/DBInterface.cc
View file @
00911199
...
@@ -8,20 +8,28 @@ bool DBNetInterface::connect( const std::string& param )
...
@@ -8,20 +8,28 @@ bool DBNetInterface::connect( const std::string& param )
std
::
string
dbname
;
std
::
string
dbname
;
std
::
string
::
size_type
pos
=
param
.
find_first_of
(
"@"
);
std
::
string
::
size_type
pos
=
param
.
find_first_of
(
"@"
);
std
::
string
::
size_type
prev
=
0
;
std
::
string
::
size_type
prev
=
0
;
if
(
pos
!=
std
::
string
::
npos
)
if
(
pos
!=
std
::
string
::
npos
)
user
=
param
.
substr
(
prev
,
pos
);
user
=
param
.
substr
(
prev
,
pos
);
prev
=
pos
+
1
;
prev
=
pos
+
1
;
pos
=
param
.
find_first_of
(
":"
,
prev
);
pos
=
param
.
find_first_of
(
":"
,
prev
);
if
(
pos
!=
std
::
string
::
npos
)
if
(
pos
!=
std
::
string
::
npos
)
host
=
param
.
substr
(
prev
,
pos
);
host
=
param
.
substr
(
prev
,
pos
);
prev
=
pos
+
1
;
prev
=
pos
+
1
;
pos
=
param
.
find_first_of
(
":"
,
prev
);
pos
=
param
.
find_first_of
(
":"
,
prev
);
if
(
pos
!=
std
::
string
::
npos
)
if
(
pos
!=
std
::
string
::
npos
)
pswd
=
param
.
substr
(
prev
,
pos
);
pswd
=
param
.
substr
(
prev
,
pos
);
prev
=
pos
+
1
;
prev
=
pos
+
1
;
pos
=
param
.
find_first_of
(
":"
,
prev
);
pos
=
param
.
find_first_of
(
":"
,
prev
);
if
(
pos
!=
std
::
string
::
npos
)
if
(
pos
!=
std
::
string
::
npos
)
dbname
=
param
.
substr
(
prev
,
pos
);
dbname
=
param
.
substr
(
prev
,
pos
);
return
nconnect
(
host
,
user
,
pswd
,
dbname
);
return
nconnect
(
host
,
user
,
pswd
,
dbname
);
}
}
//--------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
...
...
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