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
e825963b
Commit
e825963b
authored
May 07, 2017
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(DBInterace): первая версия реализации получения значений по имени столбца,
а не по индексу setbug #12672
parent
fba36c3e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
78 additions
and
5 deletions
+78
-5
MySQLInterface.cc
extensions/DBServer-MySQL/MySQLInterface.cc
+6
-1
test.cc
extensions/DBServer-MySQL/test.cc
+2
-1
PostgreSQLInterface.cc
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
+6
-1
PostgreSQLInterface.h
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
+1
-1
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+5
-0
SQLiteInterface.h
extensions/DBServer-SQLite/SQLiteInterface.h
+1
-1
test.cc
extensions/DBServer-SQLite/test.cc
+2
-0
DBInterface.h
include/DBInterface.h
+12
-0
DBInterface.cc
src/Services/DBInterface.cc
+43
-0
No files found.
extensions/DBServer-MySQL/MySQLInterface.cc
View file @
e825963b
...
...
@@ -180,7 +180,7 @@ string MySQLInterface::addslashes( const string& str )
return
tmp
.
str
();
}
// -----------------------------------------------------------------------------------------
void
MySQLInterface
::
makeResult
(
DBResult
&
dbres
,
MYSQL_RES
*
myres
,
bool
finalize
)
void
MySQLInterface
::
makeResult
(
DBResult
&
dbres
,
MYSQL_RES
*
myres
,
bool
finalize
)
{
if
(
!
myres
)
{
...
...
@@ -198,7 +198,12 @@ void MySQLInterface::makeResult(DBResult& dbres, MYSQL_RES* myres, bool finalize
DBResult
::
COL
c
;
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
)
);
c
.
emplace_back
(
(
mysql_row
[
i
]
!=
0
?
string
(
mysql_row
[
i
])
:
""
)
);
}
dbres
.
row
().
emplace_back
(
c
);
}
...
...
extensions/DBServer-MySQL/test.cc
View file @
e825963b
...
...
@@ -42,8 +42,9 @@ int main(int argc, char** argv)
for
(
DBResult
::
COL
::
iterator
cit
=
it
->
begin
();
cit
!=
it
->
end
();
cit
++
)
cout
<<
DBResult
::
as_string
(
cit
)
<<
"("
<<
DBResult
::
as_double
(
cit
)
<<
") | "
;
cout
<<
endl
;
cout
<<
"ID: "
<<
r
.
as_string
(
it
,
"id"
)
<<
endl
;
}
db
.
close
();
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.cc
View file @
e825963b
...
...
@@ -218,14 +218,19 @@ bool PostgreSQLInterface::isConnection() const
return
(
db
&&
db
->
is_open
());
}
// -----------------------------------------------------------------------------------------
void
PostgreSQLInterface
::
makeResult
(
DBResult
&
dbres
,
const
pqxx
::
result
&
res
)
void
PostgreSQLInterface
::
makeResult
(
DBResult
&
dbres
,
const
pqxx
::
result
&
res
)
{
for
(
result
::
const_iterator
c
=
res
.
begin
();
c
!=
res
.
end
();
++
c
)
{
DBResult
::
COL
col
;
for
(
pqxx
::
result
::
tuple
::
const_iterator
i
=
c
.
begin
();
i
!=
c
.
end
();
i
++
)
{
if
(
!
i
.
is_null
()
)
dbres
.
setColName
(
i
.
num
(),
i
.
name
());
col
.
push_back
(
(
i
.
is_null
()
?
""
:
i
.
as
<
string
>
())
);
}
dbres
.
row
().
push_back
(
std
::
move
(
col
)
);
}
...
...
extensions/DBServer-PostgreSQL/PostgreSQLInterface.h
View file @
e825963b
...
...
@@ -64,7 +64,7 @@ namespace uniset
private
:
void
makeResult
(
DBResult
&
dbres
,
const
pqxx
::
result
&
res
);
void
makeResult
(
DBResult
&
dbres
,
const
pqxx
::
result
&
res
);
std
::
shared_ptr
<
pqxx
::
connection
>
db
;
std
::
string
lastQ
;
std
::
string
lastE
;
...
...
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
e825963b
...
...
@@ -253,7 +253,12 @@ void SQLiteInterface::makeResult(DBResult& dbres, sqlite3_stmt* s, bool finalize
char
*
p
=
(
char
*
)
sqlite3_column_text
(
s
,
i
);
if
(
p
)
{
const
char
*
cname
=
(
const
char
*
)
sqlite3_column_name
(
s
,
i
);
if
(
cname
)
dbres
.
setColName
(
i
,
cname
);
c
.
emplace_back
(
p
);
}
else
c
.
emplace_back
(
""
);
}
...
...
extensions/DBServer-SQLite/SQLiteInterface.h
View file @
e825963b
...
...
@@ -126,7 +126,7 @@ namespace uniset
private
:
void
makeResult
(
DBResult
&
dbres
,
sqlite3_stmt
*
s
,
bool
finalize
=
true
);
void
makeResult
(
DBResult
&
dbres
,
sqlite3_stmt
*
s
,
bool
finalize
=
true
);
sqlite3
*
db
;
// sqlite3_stmt* curStmt;
...
...
extensions/DBServer-SQLite/test.cc
View file @
e825963b
...
...
@@ -38,6 +38,8 @@ int main(int argc, char** argv)
cout
<<
DBResult
::
as_string
(
cit
)
<<
"("
<<
DBResult
::
as_double
(
cit
)
<<
") | "
;
cout
<<
endl
;
cout
<<
"ID: "
<<
r
.
as_string
(
it
,
"id"
)
<<
endl
;
}
db
.
close
();
...
...
include/DBInterface.h
View file @
e825963b
...
...
@@ -4,6 +4,7 @@
#include <string>
#include <deque>
#include <vector>
#include <unordered_map>
#include "UniSetTypes.h"
// --------------------------------------------------------------------------
namespace
uniset
...
...
@@ -67,6 +68,10 @@ namespace uniset
static
int
as_int
(
const
DBResult
::
iterator
&
it
,
int
col
);
static
double
as_double
(
const
DBResult
::
iterator
&
it
,
int
col
);
static
std
::
string
as_string
(
const
DBResult
::
iterator
&
it
,
int
col
);
int
as_int
(
const
DBResult
::
iterator
&
it
,
const
std
::
string
&
colname
);
double
as_double
(
const
DBResult
::
iterator
&
it
,
const
std
::
string
&
colname
);
std
::
string
as_string
(
const
DBResult
::
iterator
&
it
,
const
std
::
string
&
colname
);
// ----------------------------------------------------------------------------
// COL
static
int
as_int
(
const
DBResult
::
COL
::
iterator
&
it
);
...
...
@@ -75,9 +80,16 @@ namespace uniset
static
size_t
num_cols
(
const
DBResult
::
iterator
&
it
);
// ----------------------------------------------------------------------------
// установить соответсвие индекса и имени поля
void
setColName
(
int
index
,
const
std
::
string
&
name
);
std
::
string
getColName
(
int
index
);
// slow function
protected
:
ROW
row_
;
std
::
unordered_map
<
std
::
string
,
int
>
colname
;
};
// ----------------------------------------------------------------------------------
struct
DBInterfaceDeleter
...
...
src/Services/DBInterface.cc
View file @
e825963b
...
...
@@ -93,12 +93,55 @@ namespace uniset
{
return
((
*
it
)[
col
]);
}
int
DBResult
::
as_int
(
const
DBResult
::
iterator
&
it
,
const
std
::
string
&
cname
)
{
auto
i
=
colname
.
find
(
cname
);
if
(
i
==
colname
.
end
()
)
throw
std
::
runtime_error
(
"(DBInterface): Unknown field ='"
+
cname
+
"'"
);
return
as_int
(
it
,
i
->
second
);
}
double
DBResult
::
as_double
(
const
DBResult
::
iterator
&
it
,
const
std
::
string
&
cname
)
{
auto
i
=
colname
.
find
(
cname
);
if
(
i
==
colname
.
end
()
)
throw
std
::
runtime_error
(
"(DBInterface): Unknown field ='"
+
cname
+
"'"
);
return
as_double
(
it
,
i
->
second
);
}
std
::
string
DBResult
::
as_string
(
const
DBResult
::
iterator
&
it
,
const
std
::
string
&
cname
)
{
auto
i
=
colname
.
find
(
cname
);
if
(
i
==
colname
.
end
()
)
throw
std
::
runtime_error
(
"(DBInterface): Unknown field ='"
+
cname
+
"'"
);
return
as_string
(
it
,
i
->
second
);
}
// ----------------------------------------------------------------------------
size_t
DBResult
::
num_cols
(
const
DBResult
::
iterator
&
it
)
{
return
it
->
size
();
}
// ----------------------------------------------------------------------------
void
DBResult
::
setColName
(
int
index
,
const
std
::
string
&
name
)
{
colname
[
name
]
=
index
;
}
// ----------------------------------------------------------------------------
std
::
string
DBResult
::
getColName
(
int
index
)
{
for
(
auto
&&
c
:
colname
)
{
if
(
c
.
second
==
index
)
return
c
.
first
;
}
return
""
;
}
// ----------------------------------------------------------------------------
int
DBResult
::
as_int
(
const
DBResult
::
COL
::
iterator
&
it
)
{
return
uniset
::
uni_atoi
(
(
*
it
)
);
...
...
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