Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
biboumi
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
88
Issues
88
List
Boards
Labels
Service Desk
Milestones
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
louiz’
biboumi
Commits
3cd64902
Commit
3cd64902
authored
Jan 14, 2018
by
louiz’
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove all the ugly database debug
parent
b4b9828d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
5 additions
and
41 deletions
+5
-41
src/database/insert_query.hpp
src/database/insert_query.hpp
+1
-4
src/database/postgresql_engine.cpp
src/database/postgresql_engine.cpp
+0
-3
src/database/postgresql_statement.hpp
src/database/postgresql_statement.hpp
+2
-11
src/database/query.cpp
src/database/query.cpp
+0
-3
src/database/select_query.hpp
src/database/select_query.hpp
+0
-1
src/database/sqlite3_engine.cpp
src/database/sqlite3_engine.cpp
+0
-5
src/database/sqlite3_statement.hpp
src/database/sqlite3_statement.hpp
+0
-1
src/database/table.hpp
src/database/table.hpp
+2
-13
No files found.
src/database/insert_query.hpp
View file @
3cd64902
...
...
@@ -16,10 +16,7 @@ update_autoincrement_id(std::tuple<T...>& columns, Statement& statement)
{
using
ColumnType
=
typename
std
::
decay
<
decltype
(
std
::
get
<
N
>
(
columns
))
>::
type
;
if
(
std
::
is_same
<
ColumnType
,
Id
>::
value
)
{
log_debug
(
"EXTRACTING LAST ID"
);
auto
&&
column
=
std
::
get
<
Id
>
(
columns
);
}
auto
&&
column
=
std
::
get
<
Id
>
(
columns
);
update_autoincrement_id
<
N
+
1
>
(
columns
,
statement
);
}
...
...
src/database/postgresql_engine.cpp
View file @
3cd64902
...
...
@@ -20,7 +20,6 @@ PostgresqlEngine::~PostgresqlEngine()
std
::
unique_ptr
<
DatabaseEngine
>
PostgresqlEngine
::
open
(
const
std
::
string
&
conninfo
)
{
log_debug
(
"trying to open: "
,
conninfo
);
PGconn
*
con
=
PQconnectdb
(
conninfo
.
data
());
if
(
!
con
)
...
...
@@ -47,13 +46,11 @@ std::set<std::string> PostgresqlEngine::get_all_columns_from_table(const std::st
while
(
statement
->
step
()
==
StepResult
::
Row
)
columns
.
insert
(
statement
->
get_column_text
(
0
));
log_debug
(
"found "
,
columns
.
size
(),
" columns."
);
return
columns
;
}
std
::
tuple
<
bool
,
std
::
string
>
PostgresqlEngine
::
raw_exec
(
const
std
::
string
&
query
)
{
log_debug
(
"raw_exec:"
,
query
);
PGresult
*
res
=
PQexec
(
this
->
conn
,
query
.
data
());
auto
sg
=
utils
::
make_scope_guard
([
res
](){
PQclear
(
res
);
...
...
src/database/postgresql_statement.hpp
View file @
3cd64902
...
...
@@ -96,12 +96,7 @@ private:
params
.
reserve
(
this
->
params
.
size
());
for
(
const
auto
&
param
:
this
->
params
)
{
log_debug
(
"param:"
,
param
);
params
.
push_back
(
param
.
data
());
}
log_debug
(
"body: "
,
body
);
params
.
push_back
(
param
.
data
());
const
int
param_size
=
static_cast
<
int
>
(
this
->
params
.
size
());
this
->
result
=
PQexecParams
(
this
->
conn
,
this
->
body
.
data
(),
param_size
,
...
...
@@ -111,11 +106,7 @@ private:
nullptr
,
0
);
const
auto
status
=
PQresultStatus
(
this
->
result
);
if
(
status
==
PGRES_TUPLES_OK
)
{
log_debug
(
"PGRES_TUPLES_OK"
);
}
else
if
(
status
!=
PGRES_COMMAND_OK
)
if
(
status
!=
PGRES_TUPLES_OK
&&
status
!=
PGRES_COMMAND_OK
)
{
log_error
(
"Failed to execute command: "
,
PQresultErrorMessage
(
this
->
result
));
return
false
;
...
...
src/database/query.cpp
View file @
3cd64902
...
...
@@ -3,19 +3,16 @@
void
actual_bind
(
Statement
&
statement
,
const
std
::
string
&
value
,
int
index
)
{
log_debug
(
"binding string:"
,
value
,
" to col "
,
index
);
statement
.
bind_text
(
index
,
value
);
}
void
actual_bind
(
Statement
&
statement
,
const
std
::
size_t
value
,
int
index
)
{
log_debug
(
"binding size_t:"
,
value
);
statement
.
bind_int64
(
index
,
value
);
}
void
actual_bind
(
Statement
&
statement
,
const
OptionalBool
&
value
,
int
index
)
{
log_debug
(
"binding optional_t:"
,
value
.
to_string
());
if
(
!
value
.
is_set
)
statement
.
bind_int64
(
index
,
0
);
else
if
(
value
.
value
)
...
...
src/database/select_query.hpp
View file @
3cd64902
...
...
@@ -115,7 +115,6 @@ struct SelectQuery: public Query
while
(
statement
->
step
()
==
StepResult
::
Row
)
{
log_debug
(
"one result."
);
Row
<
T
...
>
row
(
this
->
table_name
);
extract_row_values
(
row
,
*
statement
);
rows
.
push_back
(
row
);
...
...
src/database/sqlite3_engine.cpp
View file @
3cd64902
...
...
@@ -39,9 +39,6 @@ std::set<std::string> Sqlite3Engine::get_all_columns_from_table(const std::strin
sqlite3_free
(
errmsg
);
}
log_debug
(
"List of columns in table "
,
table_name
,
":"
);
for
(
const
auto
&
c
:
result
)
log_debug
(
c
);
return
result
;
}
...
...
@@ -74,7 +71,6 @@ std::tuple<bool, std::string> Sqlite3Engine::raw_exec(const std::string& query)
std
::
unique_ptr
<
Statement
>
Sqlite3Engine
::
prepare
(
const
std
::
string
&
query
)
{
sqlite3_stmt
*
stmt
;
log_debug
(
"SQLITE3: "
,
query
);
auto
res
=
sqlite3_prepare
(
db
,
query
.
data
(),
static_cast
<
int
>
(
query
.
size
())
+
1
,
&
stmt
,
nullptr
);
if
(
res
!=
SQLITE_OK
)
...
...
@@ -88,7 +84,6 @@ std::unique_ptr<Statement> Sqlite3Engine::prepare(const std::string& query)
void
Sqlite3Engine
::
extract_last_insert_rowid
(
Statement
&
)
{
this
->
last_inserted_rowid
=
sqlite3_last_insert_rowid
(
this
->
db
);
log_debug
(
"extracted inserted ID: "
,
this
->
last_inserted_rowid
);
}
std
::
string
Sqlite3Engine
::
id_column_type
()
...
...
src/database/sqlite3_statement.hpp
View file @
3cd64902
...
...
@@ -19,7 +19,6 @@ class Sqlite3Statement: public Statement
StepResult
step
()
override
final
{
auto
res
=
sqlite3_step
(
this
->
get
());
log_debug
(
"step: "
,
res
);
if
(
res
==
SQLITE_ROW
)
return
StepResult
::
Row
;
else
if
(
res
==
SQLITE_DONE
)
...
...
src/database/table.hpp
View file @
3cd64902
...
...
@@ -65,11 +65,10 @@ class Table
{
std
::
string
query
{
"CREATE TABLE IF NOT EXISTS "
};
query
+=
this
->
name
;
query
+=
" (
\n
"
;
query
+=
" ("
;
this
->
add_column_create
(
db
,
query
);
query
+=
")"
;
log_debug
(
"create:"
,
query
);
auto
result
=
db
.
raw_exec
(
query
);
if
(
std
::
get
<
0
>
(
result
)
==
false
)
log_error
(
"Error executing query: "
,
std
::
get
<
1
>
(
result
));
...
...
@@ -112,21 +111,11 @@ class Table
add_column_create
(
DatabaseEngine
&
db
,
std
::
string
&
str
)
{
using
ColumnType
=
typename
std
::
remove_reference
<
decltype
(
std
::
get
<
N
>
(
std
::
declval
<
ColumnTypes
>
()))
>::
type
;
// using RealType = typename ColumnType::real_type;
str
+=
ColumnType
::
name
;
str
+=
" "
;
// if (std::is_same<ColumnType, Id>::value)
// {
// str += "INTEGER PRIMARY KEY AUTOINCREMENT";
// }
// else
// {
str
+=
ToSQLType
<
ColumnType
>
(
db
);
// append_option<ColumnType>(str);
// }
str
+=
ToSQLType
<
ColumnType
>
(
db
);
if
(
N
!=
sizeof
...(
T
)
-
1
)
str
+=
","
;
str
+=
"
\n
"
;
add_column_create
<
N
+
1
>
(
db
,
str
);
}
...
...
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