Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
0c2ab17e
Commit
0c2ab17e
authored
Jul 05, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sticker: use GError for error handling
parent
12e82b9e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
17 deletions
+45
-17
main.c
src/main.c
+6
-1
sticker.c
src/sticker.c
+33
-14
sticker.h
src/sticker.h
+6
-2
No files found.
src/main.c
View file @
0c2ab17e
...
...
@@ -231,6 +231,8 @@ int main(int argc, char *argv[])
Options
options
;
clock_t
start
;
bool
create_db
;
bool
success
;
GError
*
error
=
NULL
;
daemonize_close_stdin
();
...
...
@@ -288,7 +290,10 @@ int main(int argc, char *argv[])
create_db
=
!
openDB
(
&
options
);
#ifdef ENABLE_SQLITE
sticker_global_init
(
config_get_path
(
CONF_STICKER_FILE
));
success
=
sticker_global_init
(
config_get_path
(
CONF_STICKER_FILE
),
&
error
);
if
(
!
success
)
g_error
(
"%s"
,
error
->
message
);
#endif
command_init
();
...
...
src/sticker.c
View file @
0c2ab17e
...
...
@@ -72,50 +72,69 @@ static const char sticker_sql_create[] =
static
sqlite3
*
sticker_db
;
static
sqlite3_stmt
*
sticker_stmt
[
G_N_ELEMENTS
(
sticker_sql
)];
static
GQuark
sticker_quark
(
void
)
{
return
g_quark_from_static_string
(
"sticker"
);
}
static
sqlite3_stmt
*
sticker_prepare
(
const
char
*
sql
)
sticker_prepare
(
const
char
*
sql
,
GError
**
error_r
)
{
int
ret
;
sqlite3_stmt
*
stmt
;
ret
=
sqlite3_prepare_v2
(
sticker_db
,
sql
,
-
1
,
&
stmt
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
g_error
(
"sqlite3_prepare_v2() failed: %s"
,
sqlite3_errmsg
(
sticker_db
));
if
(
ret
!=
SQLITE_OK
)
{
g_set_error
(
error_r
,
sticker_quark
(),
ret
,
"sqlite3_prepare_v2() failed: %s"
,
sqlite3_errmsg
(
sticker_db
));
return
NULL
;
}
return
stmt
;
}
void
sticker_global_init
(
const
char
*
path
)
bool
sticker_global_init
(
const
char
*
path
,
GError
**
error_r
)
{
int
ret
;
if
(
path
==
NULL
)
/* not configured */
return
;
return
true
;
/* open/create the sqlite database */
ret
=
sqlite3_open
(
path
,
&
sticker_db
);
if
(
ret
!=
SQLITE_OK
)
g_error
(
"Failed to open sqlite database '%s': %s"
,
path
,
sqlite3_errmsg
(
sticker_db
));
if
(
ret
!=
SQLITE_OK
)
{
g_set_error
(
error_r
,
sticker_quark
(),
ret
,
"Failed to open sqlite database '%s': %s"
,
path
,
sqlite3_errmsg
(
sticker_db
));
return
false
;
}
/* create the table and index */
ret
=
sqlite3_exec
(
sticker_db
,
sticker_sql_create
,
NULL
,
NULL
,
NULL
);
if
(
ret
!=
SQLITE_OK
)
g_error
(
"Failed to create sticker table: %s"
,
sqlite3_errmsg
(
sticker_db
));
if
(
ret
!=
SQLITE_OK
)
{
g_set_error
(
error_r
,
sticker_quark
(),
ret
,
"Failed to create sticker table: %s"
,
sqlite3_errmsg
(
sticker_db
));
return
false
;
}
/* prepare the statements we're going to use */
for
(
unsigned
i
=
0
;
i
<
G_N_ELEMENTS
(
sticker_sql
);
++
i
)
{
assert
(
sticker_sql
[
i
]
!=
NULL
);
sticker_stmt
[
i
]
=
sticker_prepare
(
sticker_sql
[
i
]);
sticker_stmt
[
i
]
=
sticker_prepare
(
sticker_sql
[
i
],
error_r
);
if
(
sticker_stmt
[
i
]
==
NULL
)
return
false
;
}
return
true
;
}
void
...
...
src/sticker.h
View file @
0c2ab17e
...
...
@@ -50,9 +50,13 @@ struct sticker;
/**
* Opens the sticker database (if path is not NULL).
*
* @param error_r location to store the error occuring, or NULL to
* ignore errors
* @return true on success, false on error
*/
void
sticker_global_init
(
const
char
*
path
);
bool
sticker_global_init
(
const
char
*
path
,
GError
**
error_r
);
/**
* Close the sticker database.
...
...
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