1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * $Id: libdb.c,v 1.10 2005/03/05 21:39:44 nedko Exp $
7 * Unified access to database.
10 * Nedko Arnaudov <nedko@users.sourceforge.net>
13 * GNU GENERAL PUBLIC LICENSE version 2
15 *****************************************************************************/
21 #include "../result.h"
25 char *pszErrorMsg
= NULL
;
39 pImpl
= malloc(sizeof(mediadb_impl
));
46 pImpl
->nDBType
= nDBType
;
48 if (nDBType
== MEDIADB_DBTYPE_MYSQL
)
50 r
= mediadb_mysql_open(
56 if (MEDIADB_IS_ERROR(r
))
58 if (pszErrorMsg
!= NULL
)
60 pszErrorMsg
= strdup(mediadb_mysql_get_error_message(&pImpl
->data
.mysql
));
64 else if (nDBType
== MEDIADB_DBTYPE_SQLITE
)
66 r
= mediadb_sqlite_open(
72 if (MEDIADB_IS_ERROR(r
))
74 if (pszErrorMsg
!= NULL
)
76 pszErrorMsg
= strdup(mediadb_sqlite_get_error_message(&pImpl
->data
.sqlite
));
86 *phDB
= (mediadb
)pImpl
;
96 #define pDB ((mediadb_impl *)hDB)
99 mediadb_media_add_new(
102 const char *pszComment
,
103 mediadb_mediatype nType
,
104 mediadb_uint
*pnNewMediaID
)
108 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
110 r
= mediadb_mysql_media_add_new(
117 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
119 r
= mediadb_sqlite_media_add_new(
128 r
= MEDIADB_INVAL_ARG
;
136 mediadb_media_update_properties(
138 mediadb_uint nMediaID
,
139 mediadb_uint nTimeAdded
,
140 mediadb_uint nTotalFiles
,
141 mediadb_uint nTotalSize
)
145 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
147 r
= mediadb_mysql_media_update_properties(
154 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
156 r
= mediadb_sqlite_media_update_properties(
165 r
= MEDIADB_INVAL_ARG
;
173 mediadb_file_add_new(
175 mediadb_uint nMediaID
,
176 mediadb_filetype Filetype
,
179 mediadb_uint nFileSize
,
180 mediadb_uint nFileTime
)
184 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
186 r
= mediadb_mysql_file_add_new(
195 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
197 r
= mediadb_sqlite_file_add_new(
208 r
= MEDIADB_INVAL_ARG
;
216 mediadb_media_get_properties(
218 mediadb_uint nMediaID
,
219 mediadb_uint
*pnTimeAdded
,
220 mediadb_mediatype
*pnType
,
221 mediadb_uint
*pnLocationID
,
226 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
228 r
= mediadb_mysql_media_get_properties(
236 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
238 r
= mediadb_sqlite_media_get_properties(
248 r
= MEDIADB_INVAL_ARG
;
256 mediadb_location_get_properties(
258 mediadb_uint nLocationID
,
259 mediadb_uint
*pnLocationTypeID
,
260 char **ppszDescription
)
264 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
266 r
= mediadb_mysql_location_get_properties(
272 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
274 r
= mediadb_sqlite_location_get_properties(
282 r
= MEDIADB_INVAL_ARG
;
290 mediadb_location_type_get_properties(
292 mediadb_uint nLocationTypeID
,
293 char **ppszDescription
)
297 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
299 r
= mediadb_mysql_location_type_get_properties(
304 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
306 r
= mediadb_sqlite_location_type_get_properties(
313 r
= MEDIADB_INVAL_ARG
;
321 mediadb_media_get_properties_data(
323 mediadb_uint nMediaID
,
324 mediadb_uint
*pnTotalFiles
,
325 mediadb_uint
*pnTotalSize
)
329 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
331 r
= mediadb_mysql_media_get_properties_data(
337 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
339 r
= mediadb_sqlite_media_get_properties_data(
347 r
= MEDIADB_INVAL_ARG
;
355 mediadb_delete_media_files(
357 mediadb_uint nMediaID
)
361 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
363 r
= mediadb_mysql_delete_media_files(
367 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
369 r
= mediadb_sqlite_delete_media_files(
375 r
= MEDIADB_INVAL_ARG
;
383 mediadb_media_update_name(
385 mediadb_uint nMediaID
,
390 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
392 r
= mediadb_mysql_media_update_name(
397 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
399 r
= mediadb_sqlite_media_update_name(
406 r
= MEDIADB_INVAL_ARG
;
419 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
421 r
= mediadb_mysql_close(
424 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
426 r
= mediadb_sqlite_close(
431 r
= MEDIADB_INVAL_ARG
;
435 if (MEDIADB_IS_ERROR(r
))
446 mediadb_get_error_message(
451 if (pszErrorMsg
== NULL
)
461 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
463 return mediadb_mysql_get_error_message(&pDB
->data
.mysql
);
466 if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
468 return mediadb_sqlite_get_error_message(&pDB
->data
.sqlite
);
472 return "enexpected behaviour";
476 mediadb_media_get_all(
478 mediadb_media_callback pCallback
,
483 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
485 r
= mediadb_mysql_media_get_all(
490 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
492 r
= mediadb_sqlite_media_get_all(
499 r
= MEDIADB_INVAL_ARG
;
509 mediadb_uint nMediaID
,
511 mediadb_files_callback pCallback
,
516 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
518 r
= mediadb_mysql_files_get(
525 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
527 r
= mediadb_sqlite_files_get(
536 r
= MEDIADB_INVAL_ARG
;
544 mediadb_get_pattern_match_methods(
546 const struct mediadb_pattern_match_method
**ppPMM
)
550 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
552 r
= mediadb_mysql_get_pattern_match_methods(
556 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
558 r
= mediadb_sqlite_get_pattern_match_methods(
564 r
= MEDIADB_INVAL_ARG
;
572 mediadb_files_search(
574 mediadb_uint nFilenamePMMID
,
575 const char *pszFilenamePattern
,
576 mediadb_uint nPathPMMID
,
577 const char *pszPathPattern
,
578 const mediadb_uint
*pnMinSize
,
579 const mediadb_uint
*pnMaxSize
,
580 mediadb_files_search_callback pCallback
,
585 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
587 r
= mediadb_mysql_files_search(
598 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
600 r
= mediadb_sqlite_files_search(
613 r
= MEDIADB_INVAL_ARG
;
621 mediadb_file_get_properties(
623 mediadb_uint nMediaID
,
626 mediadb_filetype
*pFiletype
,
627 mediadb_uint
*pnSize
,
628 mediadb_uint
*pnTime
)
632 if (pDB
->nDBType
== MEDIADB_DBTYPE_MYSQL
)
634 r
= mediadb_mysql_file_get_properties(
643 else if (pDB
->nDBType
== MEDIADB_DBTYPE_SQLITE
)
645 r
= mediadb_sqlite_file_get_properties(
656 r
= MEDIADB_INVAL_ARG
;
663 /*****************************************************************************
667 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
670 * Revision 1.10 2005/03/05 21:39:44 nedko
671 * new functionality - file_get_properties()
673 * Revision 1.9 2004/08/31 22:40:15 nedko
674 * Partitally implemented search feature.
676 * Revision 1.8 2004/08/08 00:47:42 nedko
677 * Get more info for media from database.
679 * Revision 1.7 2004/05/21 23:40:46 nedko
680 * New functionality: mediadb_files_get()
682 * Revision 1.6 2004/05/16 18:57:12 nedko
683 * media_get_all functionality implemented.
685 * Revision 1.5 2004/05/11 01:17:42 nedko
686 * Allow mediadb_get_error_message() to work after failed database open.
688 * Revision 1.4 2004/05/03 20:47:14 nedko
689 * Update mode for cui
691 * Revision 1.3 2004/05/02 20:12:11 nedko
692 * Improve error dumps.
694 * Revision 1.2 2004/05/02 13:16:58 nedko
695 * Supply filetype when adding new file
697 * Revision 1.1 2004/04/27 09:12:28 nedko
700 *****************************************************************************/