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
R
recommender_C-stateofart
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandre Peres Arias
recommender_C-stateofart
Commits
2dee8bae
Commit
2dee8bae
authored
Jul 13, 2016
by
Giovanne Marcelo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add log in db api
parent
630b3f7a
Pipeline
#6325
failed with stage
in 1 minute and 30 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
8 deletions
+8
-8
include/db_api.h
include/db_api.h
+1
-0
src/db_api.c
src/db_api.c
+5
-8
src/log.c
src/log.c
+2
-0
No files found.
include/db_api.h
View file @
2dee8bae
...
...
@@ -10,6 +10,7 @@
#include <string.h>
#include <jansson.h>
#include <stdlib.h>
#include "log.h"
typedef
PGresult
DBresult
;
...
...
src/db_api.c
View file @
2dee8bae
...
...
@@ -21,8 +21,7 @@ void read_conf(const char *path, char * conninfo) {
json_t
*
config
=
json_load_file
(
path
,
JSON_ENCODE_ANY
,
&
error
);
if
(
!
config
)
{
fprintf
(
stderr
,
"Error in database config file.
\n
"
);
fprintf
(
stderr
,
"%s
\n
"
,
error
.
text
);
error
(
error
.
text
);
exit
(
-
1
);
}
...
...
@@ -46,12 +45,11 @@ PGconn* db_connect() {
// Validate
if
(
!
conn
)
{
fprintf
(
stderr
,
"Error in create a connection with db.
\n
"
);
error
(
"Error in create a connection with db.
\n
"
);
exit
(
-
1
);
}
else
if
(
PQstatus
(
conn
)
==
CONNECTION_BAD
)
{
fprintf
(
stderr
,
"Conection to database failed.
\n
"
);
fprintf
(
stderr
,
"%s"
,
PQerrorMessage
(
conn
));
error
(
PQerrorMessage
(
conn
));
exit
(
-
1
);
}
return
conn
;
...
...
@@ -74,11 +72,10 @@ DBresult* db_select( char *columns, char *table, char *where) {
// Validate
if
(
!
result
){
fprintf
(
stderr
,
"Error in executing the command.
\n
"
);
error
(
"Error in executing the command.
"
);
}
else
if
(
PQresultStatus
(
result
)
==
PGRES_FATAL_ERROR
)
{
fprintf
(
stderr
,
"Error in query.
\n
"
);
fprintf
(
stderr
,
"%s
\n
"
,
PQresultErrorMessage
(
result
));
error
(
PQresultErrorMessage
(
result
));
exit
(
-
1
);
}
db_disconnect
(
conn
);
...
...
src/log.c
View file @
2dee8bae
...
...
@@ -21,6 +21,7 @@ void log_error(char* msg, int line, char *file) {
FILE
*
stream
=
open_log
();
write_date
(
stream
);
fprintf
(
stream
,
"%s:%d - [ERROR] - %s
\n
"
,
file
,
line
,
msg
);
fprintf
(
stderr
,
"[ERROR] Check log for more details.
\n
"
);
close_log
(
stream
);
}
...
...
@@ -28,6 +29,7 @@ void log_warn(char* msg, int line, char *file) {
FILE
*
stream
=
open_log
();
write_date
(
stream
);
fprintf
(
stream
,
"%s:%d - [WARN] - %s
\n
"
,
file
,
line
,
msg
);
fprintf
(
stderr
,
"[WARN] Check log for more details.
\n
"
);
close_log
(
stream
);
}
...
...
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