Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkgin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,6 @@ CREATE INDEX [idx_local_pkg_comment] ON [LOCAL_PKG] (
CREATE INDEX [idx_local_pkg_name] ON [LOCAL_PKG] (
[PKGNAME] ASC
);

PRAGMA application_id = 1886087022;
PRAGMA user_version = 1;
34 changes: 33 additions & 1 deletion pkgindb.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,31 @@ pkgindb_savepoint_release(uint64_t savepoint)
}
}

/*
* Check the application_id and user_version parameters.
*/
static int
check_appid(void *param, int argc, char **argv, char **colname)
{

if (argc != 1 || argv == NULL)
return PDB_ERR;
if (strcmp(argv[0], "1886087022") != 0)
return PDB_ERR;
return PDB_OK;
}

static int
check_version(void *param, int argc, char **argv, char **colname)
{

if (argc != 1 || argv == NULL)
return PDB_ERR;
if (strcmp(argv[0], "1") != 0)
return PDB_ERR;
return PDB_OK;
}

/*
* Configure the pkgin database. Returns 0 if opening an existing compatible
* database, or 1 if the database needs to be created or recreated (in the case
Expand Down Expand Up @@ -277,7 +302,14 @@ pkgindb_open(void)
errx(EXIT_FAILURE, "cannot create database: %s",
sqlite3_errmsg(pdb));
} else {
if (pkgindb_doquery(CHECK_DB_LATEST, NULL, NULL) != PDB_OK) {
if (pkgindb_doquery("PRAGMA application_id", check_appid, NULL)
!= PDB_OK) {
if (unlink(pkgin_sqldb) < 0)
err(EXIT_FAILURE, "cannot recreate database");
goto recreate;
}
if (pkgindb_doquery("PRAGMA user_version", check_version, NULL)
!= PDB_OK) {
if (unlink(pkgin_sqldb) < 0)
err(EXIT_FAILURE, "cannot recreate database");
goto recreate;
Expand Down
11 changes: 0 additions & 11 deletions pkgindb_queries.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@
* SUCH DAMAGE.
*/

/*
* This query checks the compatibility of the current database, and should be
* one that either completes or fails due to an SQL error based on the most
* recent schema change. Returned rows are ignored, so choose a query that
* runs quickly.
*/
const char CHECK_DB_LATEST[] =
"SELECT pkgbase "
" FROM local_conflicts "
" LIMIT 1;";

const char DELETE_LOCAL[] =
"DELETE FROM LOCAL_PKG;"
"DELETE FROM LOCAL_CONFLICTS;"
Expand Down