1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: libdb.c,v 1.3 2004/05/02 20:12:11 nedko Exp $
7 * Unified access to database.
10 * Nedko Arnaudov <nedko@users.sourceforge.net>
13 * GNU GENERAL PUBLIC LICENSE version 2
15 *****************************************************************************/
35 pImpl
= malloc(sizeof(mediadb_impl
));
42 pImpl
->nDBType
= nDBType
;
44 if (nDBType
== MEDIADB_DBTYPE_MYSQL
)
46 r
= mediadb_mysql_open(
52 if (MEDIADB_IS_ERROR(r
))
57 else if (nDBType
== MEDIADB_DBTYPE_SQLITE
)
59 r
= mediadb_sqlite_open(
65 if (MEDIADB_IS_ERROR(r
))
76 *phDB
= (mediadb
)pImpl
;
86 #define pDB ((mediadb_impl *)hDB)
89 mediadb_media_add_new(
92 const char *pszComment
,
93 mediadb_mediatype nType
,
94 mediadb_uint
*pnNewMediaID
)
98 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
100 r
= mediadb_mysql_media_add_new(
107 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
109 r
= mediadb_sqlite_media_add_new(
118 r
= MEDIADB_INVAL_ARG
;
126 mediadb_media_update_properties(
128 mediadb_uint nMediaID
,
129 mediadb_uint nTimeAdded
,
130 mediadb_uint nTotalFiles
,
131 mediadb_uint nTotalSize
)
135 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
137 r
= mediadb_mysql_media_update_properties(
144 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
146 r
= mediadb_sqlite_media_update_properties(
155 r
= MEDIADB_INVAL_ARG
;
163 mediadb_file_add_new(
165 mediadb_uint nMediaID
,
166 mediadb_filetype Filetype
,
169 mediadb_uint nFileSize
,
170 mediadb_uint nFileTime
)
174 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
176 r
= mediadb_mysql_file_add_new(
185 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
187 r
= mediadb_sqlite_file_add_new(
198 r
= MEDIADB_INVAL_ARG
;
211 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
213 r
= mediadb_mysql_close(
216 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
218 r
= mediadb_sqlite_close(
223 r
= MEDIADB_INVAL_ARG
;
227 if (MEDIADB_IS_ERROR(r
))
238 mediadb_get_error_message(
241 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
243 return mediadb_mysql_get_error_message(&pDB
->data
.mysql
);
246 if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
248 return mediadb_sqlite_get_error_message(&pDB
->data
.sqlite
);
252 return "enexpected behaviour";
255 /*****************************************************************************
259 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
262 * Revision 1.3 2004/05/02 20:12:11 nedko
263 * Improve error dumps.
265 * Revision 1.2 2004/05/02 13:16:58 nedko
266 * Supply filetype when adding new file
268 * Revision 1.1 2004/04/27 09:12:28 nedko
271 *****************************************************************************/