"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "sql.c" between
minidlna-1.1.5.tar.gz and minidlna-1.2.0.tar.gz

About: ReadyMedia (formerly known as MiniDLNA) is a simple media server software, with the aim of being fully compliant with DLNA/UPnP-AV clients.

sql.c  (minidlna-1.1.5):sql.c  (minidlna-1.2.0)
/* MiniDLNA media server /* MiniDLNA media server
* Copyright (C) 2008-2009 Justin Maggard * Copyright (C) 2008-2017 Justin Maggard
* *
* This file is part of MiniDLNA. * This file is part of MiniDLNA.
* *
* MiniDLNA is free software; you can redistribute it and/or modify * MiniDLNA is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* MiniDLNA is distributed in the hope that it will be useful, * MiniDLNA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
skipping to change at line 96 skipping to change at line 96
break; break;
default: default:
DPRINTF(E_ERROR, L_DB_SQL, "prepare failed: %s\n%s\n", sq lite3_errmsg(db), sql); DPRINTF(E_ERROR, L_DB_SQL, "prepare failed: %s\n%s\n", sq lite3_errmsg(db), sql);
sqlite3_free(sql); sqlite3_free(sql);
return -1; return -1;
} }
for (counter = 0; for (counter = 0;
((result = sqlite3_step(stmt)) == SQLITE_BUSY || result == SQLITE_LO CKED) && counter < 2; ((result = sqlite3_step(stmt)) == SQLITE_BUSY || result == SQLITE_LO CKED) && counter < 2;
counter++) { counter++) {
/* While SQLITE_BUSY has a built in timeout, /* While SQLITE_BUSY has a built in timeout,
SQLITE_LOCKED does not, so sleep */ * SQLITE_LOCKED does not, so sleep */
if (result == SQLITE_LOCKED) if (result == SQLITE_LOCKED)
sleep(1); sleep(1);
} }
switch (result) switch (result)
{ {
case SQLITE_DONE: case SQLITE_DONE:
/* no rows returned */ /* no rows returned */
ret = 0; ret = 0;
break; break;
case SQLITE_ROW: case SQLITE_ROW:
if (sqlite3_column_type(stmt, 0) == SQLITE_NULL) if (sqlite3_column_type(stmt, 0) == SQLITE_NULL)
{ {
ret = 0; ret = 0;
break; break;
} }
ret = sqlite3_column_int(stmt, 0); ret = sqlite3_column_int(stmt, 0);
break; break;
default: default:
DPRINTF(E_WARN, L_DB_SQL, "%s: step failed: %s\n%s\n", __ func__, sqlite3_errmsg(db), sql); DPRINTF(E_WARN, L_DB_SQL, "%s: step failed: %s\n%s\n", __ func__, sqlite3_errmsg(db), sql);
ret = -1; ret = -1;
break; break;
} }
sqlite3_free(sql); sqlite3_free(sql);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return ret; return ret;
} }
int64_t int64_t
sql_get_int64_field(sqlite3 *db, const char *fmt, ...) sql_get_int64_field(sqlite3 *db, const char *fmt, ...)
{ {
va_list ap; va_list ap;
skipping to change at line 155 skipping to change at line 155
break; break;
default: default:
DPRINTF(E_ERROR, L_DB_SQL, "prepare failed: %s\n%s\n", sq lite3_errmsg(db), sql); DPRINTF(E_ERROR, L_DB_SQL, "prepare failed: %s\n%s\n", sq lite3_errmsg(db), sql);
sqlite3_free(sql); sqlite3_free(sql);
return -1; return -1;
} }
for (counter = 0; for (counter = 0;
((result = sqlite3_step(stmt)) == SQLITE_BUSY || result == SQLITE_LO CKED) && counter < 2; ((result = sqlite3_step(stmt)) == SQLITE_BUSY || result == SQLITE_LO CKED) && counter < 2;
counter++) { counter++) {
/* While SQLITE_BUSY has a built in timeout, /* While SQLITE_BUSY has a built in timeout,
SQLITE_LOCKED does not, so sleep */ * SQLITE_LOCKED does not, so sleep */
if (result == SQLITE_LOCKED) if (result == SQLITE_LOCKED)
sleep(1); sleep(1);
} }
switch (result) switch (result)
{ {
case SQLITE_DONE: case SQLITE_DONE:
/* no rows returned */ /* no rows returned */
ret = 0; ret = 0;
break; break;
case SQLITE_ROW: case SQLITE_ROW:
if (sqlite3_column_type(stmt, 0) == SQLITE_NULL) if (sqlite3_column_type(stmt, 0) == SQLITE_NULL)
{ {
ret = 0; ret = 0;
break; break;
} }
ret = sqlite3_column_int64(stmt, 0); ret = sqlite3_column_int64(stmt, 0);
break; break;
default: default:
DPRINTF(E_WARN, L_DB_SQL, "%s: step failed: %s\n%s\n", __ func__, sqlite3_errmsg(db), sql); DPRINTF(E_WARN, L_DB_SQL, "%s: step failed: %s\n%s\n", __ func__, sqlite3_errmsg(db), sql);
ret = -1; ret = -1;
break; break;
} }
sqlite3_free(sql); sqlite3_free(sql);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return ret; return ret;
} }
char * char *
sql_get_text_field(sqlite3 *db, const char *fmt, ...) sql_get_text_field(sqlite3 *db, const char *fmt, ...)
{ {
va_list ap; va_list ap;
skipping to change at line 266 skipping to change at line 266
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return str; return str;
} }
int int
db_upgrade(sqlite3 *db) db_upgrade(sqlite3 *db)
{ {
int db_vers; int db_vers;
int ret;
db_vers = sql_get_int_field(db, "PRAGMA user_version"); db_vers = sql_get_int_field(db, "PRAGMA user_version");
if (db_vers == DB_VERSION) if (db_vers == DB_VERSION)
return 0; return 0;
if (db_vers > DB_VERSION) if (db_vers > DB_VERSION)
return -2; return -2;
if (db_vers < 1) if (db_vers < 1)
return -1; return -1;
if (db_vers < 9) if (db_vers < 9)
return db_vers; return db_vers;
if (db_vers < 10)
{
DPRINTF(E_WARN, L_DB_SQL, "Updating DB version to v%d\n", 10);
ret = sql_exec(db, "ALTER TABLE BOOKMARKS ADD WATCH_COUNT INTEGER
");
if (ret != SQLITE_OK)
return 9;
}
sql_exec(db, "PRAGMA user_version = %d", DB_VERSION); sql_exec(db, "PRAGMA user_version = %d", DB_VERSION);
return 0; return 0;
} }
 End of changes. 7 change blocks. 
11 lines changed or deleted 20 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS