Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
lektor
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté GitLab
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
Kubat
lektor
Validations
13e5140a
Vérifiée
Valider
13e5140a
rédigé
Il y a 5 ans
par
Kubat
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Use the id if present in the kara name: `\d+.mkv`
parent
ba7cffa5
Branches
Branches contenant la validation
Étiquettes
Étiquettes contenant la validation
1 requête de fusion
!76
Database update from FS
Modifications
1
Afficher les modifications d'espaces
En ligne
Côte à côte
Affichage de
1 fichier modifié
src/database/update.c
+26
-4
26 ajouts, 4 suppressions
src/database/update.c
avec
26 ajouts
et
4 suppressions
src/database/update.c
+
26
−
4
Voir le fichier @
13e5140a
...
@@ -21,21 +21,44 @@ database_add_kara(volatile sqlite3 *db, const char *filename)
...
@@ -21,21 +21,44 @@ database_add_kara(volatile sqlite3 *db, const char *filename)
"INSERT INTO "
"INSERT INTO "
"kara (song_name, source_name, category, song_type, language, file_path, is_new, author_name, author_year, song_number)"
"kara (song_name, source_name, category, song_type, language, file_path, is_new, author_name, author_year, song_number)"
"SELECT ?, ?, ?, ?, ?, ?, ?, ?, strftime('%s','now'), ?"
;
"SELECT ?, ?, ?, ?, ?, ?, ?, ?, strftime('%s','now'), ?"
;
static
const
char
*
SQL_STMT_WITH_ID
=
"INSERT INTO "
"kara (song_name, source_name, category, song_type, language, file_path, is_new, author_name, author_year, song_number, id)"
"SELECT ?, ?, ?, ?, ?, ?, ?, ?, strftime('%s','now'), ?, ?"
;
sqlite3_stmt
*
stmt
=
NULL
;
sqlite3_stmt
*
stmt
=
NULL
;
int
code
=
SQLITE_OK
,
status
=
false
;
long
code
=
SQLITE_OK
,
status
=
false
,
kara_id
;
struct
kara_metadata
data
;
struct
kara_metadata
data
;
time_t
the_time
=
time
(
NULL
);
time_t
the_time
=
time
(
NULL
);
struct
tm
*
the_local_time
=
localtime
(
&
the_time
);
struct
tm
*
the_local_time
=
localtime
(
&
the_time
);
char
year
[
10
];
char
year
[
10
],
path
[
PATH_MAX
],
*
saveptr
=
NULL
,
*
token
,
*
id
=
NULL
;
/* A timestamp */
code
=
safe_snprintf
(
year
,
10
,
"%d"
,
the_local_time
->
tm_year
+
1900
);
code
=
safe_snprintf
(
year
,
10
,
"%d"
,
the_local_time
->
tm_year
+
1900
);
RETURN_IF
(
code
<
0
||
code
>=
10
,
"Failed to get the year of the current date"
,
false
);
RETURN_IF
(
code
<
0
||
code
>=
10
,
"Failed to get the year of the current date"
,
false
);
/* Metadata */
if
(
kara_metadata_read
(
&
data
,
filename
)
!=
0
)
{
if
(
kara_metadata_read
(
&
data
,
filename
)
!=
0
)
{
LOG_ERROR
(
"Failed to get mdt for the kara '%s'"
,
filename
);
LOG_ERROR
(
"Failed to get mdt for the kara '%s'"
,
filename
);
return
false
;
return
false
;
}
}
/* Try to find an id in the filename, reuse of variables, it's ugly */
path
[
PATH_MAX
-
1
]
=
'\0'
;
memcpy
(
path
,
filename
,
(
strlen
(
filename
)
+
1
)
*
sizeof
(
char
));
while
(
NULL
!=
(
token
=
strtok_r
(
path
,
"/"
,
&
saveptr
)))
id
=
token
;
size_t
id_len
=
strspn
(
id
,
"0123456789"
);
id
[
id_len
]
=
'\0'
;
/* Replace the . of .mkv */
STRTOL
(
kara_id
,
id
,
token
,
id_len
);
if
(
!
id_len
&&
STR_MATCH
(
&
token
[
1
],
"mkv"
))
{
/* Use the found id, most of the time, normally */
LOG_INFO_SCT
(
"DB"
,
"Found id '%ld' in kara '%s'"
,
kara_id
,
filename
);
SQLITE_PREPARE
(
db
,
stmt
,
SQL_STMT_WITH_ID
,
error
);
SQLITE_BIND_INT
(
db
,
stmt
,
10
,
(
int
)
kara_id
,
error
);
}
else
{
/* Generate a new id */
SQLITE_PREPARE
(
db
,
stmt
,
SQL_STMT
,
error
);
SQLITE_PREPARE
(
db
,
stmt
,
SQL_STMT
,
error
);
}
if
((
sqlite3_bind_text
(
stmt
,
1
,
data
.
song_name
,
-
1
,
0
)
!=
SQLITE_OK
)
||
if
((
sqlite3_bind_text
(
stmt
,
1
,
data
.
song_name
,
-
1
,
0
)
!=
SQLITE_OK
)
||
(
sqlite3_bind_text
(
stmt
,
2
,
data
.
source_name
,
-
1
,
0
)
!=
SQLITE_OK
)
||
(
sqlite3_bind_text
(
stmt
,
2
,
data
.
source_name
,
-
1
,
0
)
!=
SQLITE_OK
)
||
...
@@ -50,7 +73,6 @@ database_add_kara(volatile sqlite3 *db, const char *filename)
...
@@ -50,7 +73,6 @@ database_add_kara(volatile sqlite3 *db, const char *filename)
LOG_ERROR_SCT
(
"DB"
,
"Failed to bind for kara %s: %s"
,
filename
,
sqlite3_errmsg
((
sqlite3
*
)
db
));
LOG_ERROR_SCT
(
"DB"
,
"Failed to bind for kara %s: %s"
,
filename
,
sqlite3_errmsg
((
sqlite3
*
)
db
));
goto
error
;
goto
error
;
}
}
SQLITE_STEP_DONE
(
db
,
stmt
,
error
);
SQLITE_STEP_DONE
(
db
,
stmt
,
error
);
status
=
true
;
status
=
true
;
error:
error:
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter