Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
medialibrary
Commits
6a448852
Commit
6a448852
authored
May 10, 2014
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Link files & labels
parent
d5d2d7a5
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
118 additions
and
6 deletions
+118
-6
CMakeLists.txt
CMakeLists.txt
+1
-0
src/Album.h
src/Album.h
+1
-1
src/File.cpp
src/File.cpp
+25
-2
src/Label.cpp
src/Label.cpp
+59
-0
src/Label.h
src/Label.h
+27
-0
src/MediaLibrary.cpp
src/MediaLibrary.cpp
+2
-0
src/SqliteTools.cpp
src/SqliteTools.cpp
+2
-2
src/SqliteTools.h
src/SqliteTools.h
+1
-1
No files found.
CMakeLists.txt
View file @
6a448852
...
...
@@ -22,6 +22,7 @@ list(APPEND SRC_LIST ${HEADERS_LIST}
src/File.cpp
src/Album.cpp
src/Show.cpp
src/Label.cpp
)
find_package
(
Sqlite3 REQUIRED
)
...
...
src/Album.h
View file @
6a448852
...
...
@@ -18,7 +18,7 @@ class Album : public IAlbum
virtual
time_t
lastSyncDate
();
static
bool
CreateTable
(
sqlite3
*
dbConnection
);
static
Album
*
Fetch
(
sqlite3
*
dbConnection
,
unsigned
int
albumTrackId
)
static
Album
*
Fetch
(
sqlite3
*
dbConnection
,
unsigned
int
albumTrackId
);
protected:
sqlite3
*
m_dbConnection
;
...
...
src/File.cpp
View file @
6a448852
#include <cassert>
#include "File.h"
#include "Label.h"
#include "SqliteTools.h"
#include "Album.h"
File
::
File
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
)
:
m_dbConnection
(
dbConnection
)
...
...
@@ -38,7 +40,7 @@ bool File::insert( sqlite3* dbConnection )
return
true
;
}
IAlbumTrack
*
File
::
albumTrack
()
IAlbumTrack
*
File
::
albumTrack
()
{
if
(
m_albumTrack
==
NULL
&&
m_albumTrackId
!=
0
)
{
...
...
@@ -62,11 +64,32 @@ IShowEpisode*File::showEpisode()
std
::
vector
<
ILabel
*>
File
::
labels
()
{
if
(
m_labels
==
NULL
)
{
m_labels
=
new
std
::
vector
<
ILabel
*>
;
const
char
*
req
=
"SELECT * FROM Labels l"
"LEFT JOIN LabelFileRelation lfr ON lfr.id_label = f.id_label "
"WHERE lfr.id_file = ?"
;
sqlite3_stmt
*
stmt
;
int
res
=
sqlite3_prepare_v2
(
m_dbConnection
,
req
,
-
1
,
&
stmt
,
NULL
);
if
(
res
!=
SQLITE_OK
)
return
*
m_labels
;
sqlite3_bind_int
(
stmt
,
1
,
m_id
);
res
=
sqlite3_step
(
stmt
);
while
(
res
==
SQLITE_ROW
)
{
ILabel
*
l
=
new
Label
(
m_dbConnection
,
stmt
);
m_labels
->
push_back
(
l
);
res
=
sqlite3_step
(
stmt
);
}
sqlite3_finalize
(
stmt
);
}
return
*
m_labels
;
}
bool
File
::
CreateTable
(
sqlite3
*
connection
)
{
std
::
string
req
=
"CREATE TABLE IF NOT EXISTS File("
const
char
*
req
=
"CREATE TABLE IF NOT EXISTS File("
"id_media INTEGER PRIMARY KEY AUTOINCREMENT,"
"type INTEGER, duration UNSIGNED INTEGER,"
"album_track_id UNSIGNED INTEGER)"
;
...
...
src/Label.cpp
0 → 100644
View file @
6a448852
#include "Label.h"
#include "SqliteTools.h"
Label
::
Label
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
)
:
m_dbConnection
(
dbConnection
)
,
m_files
(
NULL
)
{
m_id
=
sqlite3_column_int
(
stmt
,
1
);
m_name
=
(
const
char
*
)
sqlite3_column_text
(
stmt
,
2
);
}
const
std
::
string
&
Label
::
name
()
{
return
m_name
;
}
std
::
vector
<
IFile
*>
Label
::
files
()
{
if
(
m_files
==
NULL
)
{
m_files
=
new
std
::
vector
<
IFile
*>
;
const
char
*
req
=
"SELECT * FROM Files f"
"LEFT JOIN LabelFileRelation lfr ON lfr.id_file = f.id_file "
"WHERE lfr.id_label = ?"
;
sqlite3_stmt
*
stmt
;
int
res
=
sqlite3_prepare_v2
(
m_dbConnection
,
req
,
-
1
,
&
stmt
,
NULL
);
if
(
res
!=
SQLITE_OK
)
return
;
sqlite3_bind_int
(
stmt
,
1
,
m_id
);
res
=
sqlite3_step
(
stmt
);
while
(
res
==
SQLITE_ROW
)
{
IFile
*
f
=
new
File
(
m_dbConnection
,
stmt
);
m_files
->
push_back
(
f
);
res
=
sqlite3_step
(
stmt
);
}
sqlite3_finalize
(
stmt
);
}
return
*
m_files
;
}
bool
Label
::
createTable
(
sqlite3
*
dbConnection
)
{
const
char
*
req
=
"CREATE TABLE IF NOT EXISTS Label("
"id_label INTEGER PRIMARY KEY AUTO INCREMENT, "
"name TEXT"
")"
;
if
(
SqliteTools
::
CreateTable
(
dbConnection
,
req
)
)
return
false
;
req
=
"CREATE TABLE IF NOT EXISTS LabelFileRelation("
"id_label INTEGER,"
"id_file INTEGER,"
"PRIMARY KEY (id_label, id_file)"
"FOREIGN KEY(id_label) REFERENCES Label(id_label) ON DELETE CASCADE,"
"FOREIGN KEY(id_file) REFERENCES File(id_file) ON DELETE CASCADE);"
;
return
SqliteTools
::
CreateTable
(
dbConnection
,
req
);
}
src/Label.h
0 → 100644
View file @
6a448852
#ifndef LABEL_H
#define LABEL_H
#include <sqlite3.h>
#include <string>
#include "ILabel.h"
class
Label
:
public
ILabel
{
public:
Label
(
sqlite3
*
dbConnection
,
sqlite3_stmt
*
stmt
);
public:
virtual
const
std
::
string
&
name
();
virtual
std
::
vector
<
IFile
*>
files
();
static
bool
createTable
(
sqlite3
*
dbConnection
);
private:
sqlite3
*
m_dbConnection
;
unsigned
int
m_id
;
std
::
string
m_name
;
std
::
vector
<
IFile
*>*
m_files
;
};
#endif // LABEL_H
src/MediaLibrary.cpp
View file @
6a448852
...
...
@@ -7,6 +7,8 @@ MediaLibrary::MediaLibrary()
bool
MediaLibrary
::
initialize
(
const
std
::
string
&
dbPath
)
{
int
res
=
sqlite3_open
(
dbPath
.
c_str
(),
&
m_dbConnection
);
//FIXME:
// PRAGMA foreign_keys = ON;
return
res
==
SQLITE_OK
;
}
...
...
src/SqliteTools.cpp
View file @
6a448852
...
...
@@ -2,10 +2,10 @@
#include "SqliteTools.h"
bool
SqliteTools
::
CreateTable
(
sqlite3
*
db
,
const
std
::
string
&
request
)
bool
SqliteTools
::
CreateTable
(
sqlite3
*
db
,
const
char
*
request
)
{
sqlite3_stmt
*
stmt
;
int
res
=
sqlite3_prepare_v2
(
db
,
request
.
c_str
()
,
-
1
,
&
stmt
,
NULL
);
int
res
=
sqlite3_prepare_v2
(
db
,
request
,
-
1
,
&
stmt
,
NULL
);
if
(
res
!=
SQLITE_OK
)
{
std
::
cerr
<<
"Failed to execute request: "
<<
request
<<
std
::
endl
;
...
...
src/SqliteTools.h
View file @
6a448852
...
...
@@ -7,7 +7,7 @@
class
SqliteTools
{
public:
static
bool
CreateTable
(
sqlite3
*
db
,
const
std
::
string
&
request
);
static
bool
CreateTable
(
sqlite3
*
db
,
const
char
*
request
);
};
#endif // SQLITETOOLS_H
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