Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
VideoLAN
medialibrary
Commits
486900fd
Commit
486900fd
authored
Apr 23, 2018
by
Hugo Beauzée-Luyssen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sqlite: Add support for pagination
parent
e9e5d6b8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
Makefile.am
Makefile.am
+1
-0
src/database/SqliteQuery.h
src/database/SqliteQuery.h
+104
-0
No files found.
Makefile.am
View file @
486900fd
...
...
@@ -124,6 +124,7 @@ noinst_HEADERS = \
src/database/DatabaseHelpers.h
\
src/database/SqliteConnection.h
\
src/database/SqliteErrors.h
\
src/database/SqliteQuery.h
\
src/database/SqliteTools.h
\
src/database/SqliteTraits.h
\
src/database/SqliteTransaction.h
\
...
...
src/database/SqliteQuery.h
0 → 100644
View file @
486900fd
/*****************************************************************************
* Media Library
*****************************************************************************
* Copyright (C) 2015 Hugo Beauzée-Luyssen, Videolabs
*
* Authors: Hugo Beauzée-Luyssen<hugo@beauzee.fr>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#pragma once
#include "medialibrary/IQuery.h"
#include "SqliteConnection.h"
#include "SqliteTools.h"
#include <vector>
#include <functional>
#include <string>
namespace
medialibrary
{
template
<
typename
Impl
,
typename
Intf
,
typename
...
RequestParams
>
class
SqliteQuery
:
public
IQuery
<
Intf
>
{
public:
using
Result
=
typename
IQuery
<
Intf
>::
Result
;
template
<
typename
...
Params
>
SqliteQuery
(
MediaLibraryPtr
ml
,
std
::
string
field
,
std
::
string
base
,
Params
&&
...
params
)
:
m_ml
(
ml
)
,
m_field
(
field
)
,
m_base
(
base
)
,
m_params
(
std
::
forward
<
Params
>
(
params
)...
)
,
m_count
(
0
)
,
m_hasCount
(
false
)
{
}
virtual
size_t
count
()
override
{
if
(
m_hasCount
==
true
)
return
m_count
;
std
::
string
req
=
"SELECT COUNT() "
+
m_base
;
auto
dbConn
=
m_ml
->
getConn
();
auto
ctx
=
dbConn
->
acquireReadContext
();
sqlite
::
Statement
stmt
(
dbConn
->
handle
(),
req
);
stmt
.
execute
(
m_params
);
auto
row
=
stmt
.
row
();
row
>>
m_count
;
assert
(
stmt
.
row
()
==
nullptr
);
m_hasCount
=
true
;
return
m_count
;
}
virtual
Result
items
(
uint32_t
nbItems
,
uint32_t
offset
)
override
{
const
std
::
string
req
=
"SELECT "
+
m_field
+
" "
+
m_base
+
" LIMIT ? OFFSET ?"
;
return
Impl
::
template
fetchAll
<
Intf
>(
m_ml
,
req
,
m_params
,
nbItems
,
offset
);
}
virtual
Result
all
()
override
{
const
std
::
string
req
=
"SELECT "
+
m_field
+
" "
+
m_base
;
return
Impl
::
template
fetchAll
<
Intf
>(
m_ml
,
req
,
m_params
);
}
private:
MediaLibraryPtr
m_ml
;
std
::
string
m_field
;
std
::
string
m_base
;
std
::
tuple
<
typename
std
::
decay
<
RequestParams
>::
type
...
>
m_params
;
size_t
m_count
;
bool
m_hasCount
;
};
template
<
typename
Impl
,
typename
Intf
=
Impl
,
typename
...
Args
>
Query
<
Intf
>
make_query
(
MediaLibraryPtr
ml
,
std
::
string
field
,
std
::
string
base
,
Args
&&
...
args
)
{
return
std
::
unique_ptr
<
IQuery
<
Intf
>>
(
new
SqliteQuery
<
Impl
,
Intf
,
Args
...
>
(
ml
,
std
::
move
(
field
),
std
::
move
(
base
),
std
::
forward
<
Args
>
(
args
)...
)
);
}
}
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