Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
VideoLAN
medialibrary
Commits
32d07824
Commit
32d07824
authored
Feb 23, 2018
by
Hugo Beauzée-Luyssen
Browse files
History: Split trigger creation in a separate method
parent
30dc1916
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/History.cpp
View file @
32d07824
...
...
@@ -58,6 +58,12 @@ void History::createTable( sqlite::Connection* dbConnection )
"FOREIGN KEY (id_media) REFERENCES "
+
policy
::
MediaTable
::
Name
+
"(id_media) ON DELETE CASCADE"
")"
;
// Don't index the id_media field, we don't want to select history records using the media_id
sqlite
::
Tools
::
executeRequest
(
dbConnection
,
req
);
}
void
History
::
createTriggers
(
sqlite
::
Connection
*
dbConnection
)
{
const
std
::
string
triggerReq
=
"CREATE TRIGGER IF NOT EXISTS limit_nb_records AFTER INSERT ON "
+
policy
::
HistoryTable
::
Name
+
" BEGIN "
...
...
@@ -65,8 +71,6 @@ void History::createTable( sqlite::Connection* dbConnection )
"(SELECT id_media FROM "
+
policy
::
HistoryTable
::
Name
+
" ORDER BY insertion_date DESC LIMIT -1 OFFSET "
+
std
::
to_string
(
MaxEntries
)
+
");"
" END"
;
// Don't index the id_media field, we don't want to select history records using the media_id
sqlite
::
Tools
::
executeRequest
(
dbConnection
,
req
);
sqlite
::
Tools
::
executeRequest
(
dbConnection
,
triggerReq
);
}
...
...
src/History.h
View file @
32d07824
...
...
@@ -50,6 +50,7 @@ class History : public IHistoryEntry, public DatabaseHelpers<History, policy::Hi
public:
History
(
MediaLibraryPtr
ml
,
sqlite
::
Row
&
row
);
static
void
createTable
(
sqlite
::
Connection
*
dbConnection
);
static
void
createTriggers
(
sqlite
::
Connection
*
dbConnection
);
static
bool
insert
(
sqlite
::
Connection
*
dbConn
,
int64_t
mediaId
);
static
std
::
vector
<
HistoryPtr
>
fetch
(
MediaLibraryPtr
ml
);
static
void
clearStreams
(
MediaLibraryPtr
ml
);
...
...
src/MediaLibrary.cpp
View file @
32d07824
...
...
@@ -170,6 +170,7 @@ void MediaLibrary::createAllTriggers()
File
::
createTriggers
(
m_dbConnection
.
get
()
);
Genre
::
createTriggers
(
m_dbConnection
.
get
()
);
Playlist
::
createTriggers
(
m_dbConnection
.
get
()
);
History
::
createTriggers
(
m_dbConnection
.
get
()
);
}
template
<
typename
T
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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