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
94f18a08
Commit
94f18a08
authored
Nov 16, 2015
by
Hugo Beauzée-Luyssen
Browse files
sqlite: Merge insert & executeInsert
parent
58862629
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/Album.cpp
View file @
94f18a08
...
...
@@ -227,7 +227,7 @@ bool Album::addArtist( std::shared_ptr<Artist> artist )
LOG_ERROR
(
"Both artist & album need to be inserted in database before being linked together"
);
return
false
;
}
return
sqlite
::
Tools
::
executeI
nsert
(
m_dbConnection
,
req
,
m_id
,
artist
->
id
()
);
return
sqlite
::
Tools
::
i
nsert
(
m_dbConnection
,
req
,
m_id
,
artist
->
id
()
)
!=
0
;
}
bool
Album
::
removeArtist
(
Artist
*
artist
)
...
...
src/Artist.cpp
View file @
94f18a08
...
...
@@ -108,7 +108,7 @@ bool Artist::addMedia(Media* media)
static
const
std
::
string
req
=
"INSERT INTO MediaArtistRelation VALUES(?, ?)"
;
// If track's ID is 0, the request will fail due to table constraints
sqlite
::
ForeignKey
artistForeignKey
(
m_id
);
return
sqlite
::
Tools
::
executeI
nsert
(
m_dbConnection
,
req
,
media
->
id
(),
artistForeignKey
);
return
sqlite
::
Tools
::
i
nsert
(
m_dbConnection
,
req
,
media
->
id
(),
artistForeignKey
)
!=
0
;
}
const
std
::
string
&
Artist
::
artworkUrl
()
const
...
...
@@ -190,7 +190,7 @@ bool Artist::createDefaultArtists( DBConnection dbConnection )
// This will skip the cache for those new entities, but they will be inserted soon enough anyway.
static
const
std
::
string
req
=
"INSERT OR IGNORE INTO "
+
policy
::
ArtistTable
::
Name
+
"(id_artist) VALUES(?),(?)"
;
sqlite
::
Tools
::
executeI
nsert
(
dbConnection
,
req
,
medialibrary
::
UnknownArtistID
,
sqlite
::
Tools
::
i
nsert
(
dbConnection
,
req
,
medialibrary
::
UnknownArtistID
,
medialibrary
::
VariousArtistID
);
// Always return true. The insertion might succeed, but we consider it a failure when 0 row
// gets inserted, while we are explicitely specifying "OR IGNORE" here.
...
...
src/Media.cpp
View file @
94f18a08
...
...
@@ -334,7 +334,7 @@ bool Media::addLabel( LabelPtr label )
return
false
;
}
const
char
*
req
=
"INSERT INTO LabelFileRelation VALUES(?, ?)"
;
return
sqlite
::
Tools
::
executeI
nsert
(
m_dbConnection
,
req
,
label
->
id
(),
m_id
);
return
sqlite
::
Tools
::
i
nsert
(
m_dbConnection
,
req
,
label
->
id
(),
m_id
)
!=
0
;
}
bool
Media
::
removeLabel
(
LabelPtr
label
)
...
...
src/database/SqliteTools.h
View file @
94f18a08
...
...
@@ -240,13 +240,6 @@ class Tools
return
executeDelete
(
dbConnectionWeak
,
req
,
std
::
forward
<
Args
>
(
args
)...
);
}
template
<
typename
...
Args
>
static
bool
executeInsert
(
DBConnection
dbConnectionWeak
,
const
std
::
string
&
req
,
Args
&&
...
args
)
{
// The code would be exactly the same, do not freak out because it calls executeDelete :)
return
executeDelete
(
dbConnectionWeak
,
req
,
std
::
forward
<
Args
>
(
args
)...
);
}
/**
* Inserts a record to the DB and return the newly created primary key.
* Returns 0 (which is an invalid sqlite primary key) when insertion fails.
...
...
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