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
892cd666
Commit
892cd666
authored
May 08, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(DBInterface): небольшой рефакторинг функций makeResult()
parent
bb2f6345
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
24 deletions
+29
-24
MySQLInterface.cc
extensions/DBServer-MySQL/MySQLInterface.cc
+9
-7
MySQLInterface.h
extensions/DBServer-MySQL/MySQLInterface.h
+1
-1
PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
+8
-6
PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
+1
-1
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+9
-8
SQLiteInterface.h
extensions/DBServer-SQLite/SQLiteInterface.h
+1
-1
No files found.
extensions/DBServer-MySQL/MySQLInterface.cc
View file @
892cd666
...
...
@@ -98,9 +98,7 @@ DBResult MySQLInterface::query( const std::string& q )
if
(
!
res
||
mysql_num_rows
(
res
)
==
0
)
return
DBResult
();
DBResult
dbres
;
makeResult
(
dbres
,
res
,
true
);
return
dbres
;
return
makeResult
(
res
,
true
);
}
// -----------------------------------------------------------------------------------------
bool
MySQLInterface
::
query_ok
(
const
string
&
q
)
...
...
@@ -180,14 +178,16 @@ string MySQLInterface::addslashes( const string& str )
return
tmp
.
str
();
}
// -----------------------------------------------------------------------------------------
void
MySQLInterface
::
makeResult
(
DBResult
&
dbres
,
MYSQL_RES
*
myres
,
bool
finalize
)
DBResult
MySQLInterface
::
makeResult
(
MYSQL_RES
*
myres
,
bool
finalize
)
{
DBResult
result
;
if
(
!
myres
)
{
if
(
finalize
)
mysql_free_result
(
myres
);
return
;
return
result
;
}
MYSQL_ROW
mysql_row
;
...
...
@@ -200,16 +200,18 @@ void MySQLInterface::makeResult( DBResult& dbres, MYSQL_RES* myres, bool finaliz
for
(
unsigned
int
i
=
0
;
i
<
nfields
;
i
++
)
{
MYSQL_FIELD
*
field_info
=
mysql_fetch_field_direct
(
myres
,
i
);
dbres
.
setColName
(
i
,
std
::
string
(
field_info
->
name
)
);
result
.
setColName
(
i
,
std
::
string
(
field_info
->
name
)
);
c
.
emplace_back
(
(
mysql_row
[
i
]
!=
0
?
string
(
mysql_row
[
i
])
:
""
)
);
}
dbres
.
row
().
emplace_back
(
c
);
result
.
row
().
emplace_back
(
c
);
}
if
(
finalize
)
mysql_free_result
(
myres
);
return
result
;
}
// -----------------------------------------------------------------------------------------
extern
"C"
std
::
shared_ptr
<
DBInterface
>
create_mysqlinterface
()
...
...
extensions/DBServer-MySQL/MySQLInterface.h
View file @
892cd666
...
...
@@ -76,7 +76,7 @@ namespace uniset
private
:
void
makeResult
(
DBResult
&
dbres
,
MYSQL_RES
*
r
,
bool
finalize
=
true
);
DBResult
makeResult
(
MYSQL_RES
*
r
,
bool
finalize
=
true
);
MYSQL
*
mysql
;
std
::
string
lastQ
;
bool
connected
;
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
View file @
892cd666
...
...
@@ -180,9 +180,7 @@ DBResult PostgreSQLInterface::query( const string& q )
/* Execute SQL query */
result
res
(
n
.
exec
(
q
)
);
DBResult
dbres
;
makeResult
(
dbres
,
res
);
return
dbres
;
return
makeResult
(
res
);
}
catch
(
const
std
::
exception
&
e
)
{
...
...
@@ -218,8 +216,10 @@ bool PostgreSQLInterface::isConnection() const
return
(
db
&&
db
->
is_open
());
}
// -----------------------------------------------------------------------------------------
void
PostgreSQLInterface
::
makeResult
(
DBResult
&
dbres
,
const
pqxx
::
result
&
res
)
DBResult
PostgreSQLInterface
::
makeResult
(
const
pqxx
::
result
&
res
)
{
DBResult
result
;
for
(
result
::
const_iterator
c
=
res
.
begin
();
c
!=
res
.
end
();
++
c
)
{
DBResult
::
COL
col
;
...
...
@@ -230,13 +230,15 @@ void PostgreSQLInterface::makeResult( DBResult& dbres, const pqxx::result& res )
col
.
push_back
(
""
);
else
{
dbres
.
setColName
(
i
.
num
(),
i
.
name
());
result
.
setColName
(
i
.
num
(),
i
.
name
());
col
.
push_back
(
i
.
as
<
string
>
()
);
}
}
dbres
.
row
().
push_back
(
std
::
move
(
col
)
);
result
.
row
().
push_back
(
std
::
move
(
col
)
);
}
return
result
;
}
// -----------------------------------------------------------------------------------------
extern
"C"
std
::
shared_ptr
<
DBInterface
>
create_postgresqlinterface
()
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
View file @
892cd666
...
...
@@ -64,7 +64,7 @@ namespace uniset
private
:
void
makeResult
(
DBResult
&
dbres
,
const
pqxx
::
result
&
res
);
DBResult
makeResult
(
const
pqxx
::
result
&
res
);
std
::
shared_ptr
<
pqxx
::
connection
>
db
;
std
::
string
lastQ
;
std
::
string
lastE
;
...
...
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
892cd666
...
...
@@ -175,9 +175,7 @@ DBResult SQLiteInterface::query( const string& q )
lastQ
=
q
;
queryok
=
true
;
DBResult
dbres
;
makeResult
(
dbres
,
pStmt
,
true
);
return
dbres
;
return
makeResult
(
pStmt
,
true
);
}
// -----------------------------------------------------------------------------------------
bool
SQLiteInterface
::
wait
(
sqlite3_stmt
*
stmt
,
int
result
)
...
...
@@ -224,14 +222,15 @@ bool SQLiteInterface::isConnection() const
return
connected
;
}
// -----------------------------------------------------------------------------------------
void
SQLiteInterface
::
makeResult
(
DBResult
&
dbres
,
sqlite3_stmt
*
s
,
bool
finalize
)
DBResult
SQLiteInterface
::
makeResult
(
sqlite3_stmt
*
s
,
bool
finalize
)
{
DBResult
result
;
if
(
!
s
)
{
if
(
finalize
)
sqlite3_finalize
(
s
);
return
;
return
result
;
}
do
...
...
@@ -243,7 +242,7 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize
if
(
finalize
)
sqlite3_finalize
(
s
);
return
;
return
result
;
}
DBResult
::
COL
c
;
...
...
@@ -256,7 +255,7 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize
{
const
char
*
cname
=
(
const
char
*
)
sqlite3_column_name
(
s
,
i
);
if
(
cname
)
dbres
.
setColName
(
i
,
cname
);
result
.
setColName
(
i
,
cname
);
c
.
emplace_back
(
p
);
}
...
...
@@ -264,12 +263,14 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize
c
.
emplace_back
(
""
);
}
dbres
.
row
().
emplace_back
(
c
);
result
.
row
().
emplace_back
(
c
);
}
while
(
sqlite3_step
(
s
)
==
SQLITE_ROW
);
if
(
finalize
)
sqlite3_finalize
(
s
);
return
result
;
}
// -----------------------------------------------------------------------------------------
extern
"C"
std
::
shared_ptr
<
DBInterface
>
create_sqliteinterface
()
...
...
extensions/DBServer-SQLite/SQLiteInterface.h
View file @
892cd666
...
...
@@ -126,7 +126,7 @@ namespace uniset
private
:
void
makeResult
(
DBResult
&
dbres
,
sqlite3_stmt
*
s
,
bool
finalize
=
true
);
DBResult
makeResult
(
sqlite3_stmt
*
s
,
bool
finalize
=
true
);
sqlite3
*
db
;
// sqlite3_stmt* curStmt;
...
...
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