[RombaSharp] More code for update

This commit is contained in:
Matt Nadareski
2016-09-02 12:51:08 -07:00
parent 03be4c956f
commit 2328e71017
2 changed files with 94 additions and 43 deletions

View File

@@ -322,6 +322,9 @@ namespace SabreTools
{ {
using (SqliteDataReader sldr = slc.ExecuteReader()) using (SqliteDataReader sldr = slc.ExecuteReader())
{ {
if (sldr.HasRows)
{
sldr.Read();
string hash = sldr.GetString(0); string hash = sldr.GetString(0);
if (!databaseDats.Contains(hash)) if (!databaseDats.Contains(hash))
{ {
@@ -365,12 +368,59 @@ namespace SabreTools
// Loop through the parsed entries // Loop through the parsed entries
foreach (string romkey in tempdat.Files.Keys) foreach (string romkey in tempdat.Files.Keys)
{ {
// So, we have an issue. Finding each of the particular crc/md5/sha1 combinations foreach (Rom rom in tempdat.Files[romkey])
// that need to be added compared to what's already in the database is likely to {
// be difficult with the current keyvault structure. Can we move to a non-kv since query = "SELECT id FROM data WHERE key=\"size\" AND value=\"" + rom.HashData.Size + "\" AND ("
// we're using a database that we are fully aware of anyway? Then we can definitely + "(key=\"crc\" AND (value=\"" + rom.HashData.CRC + "\" OR value=\"null\"))"
// have a hash table and a dat table and a mapping between the two. Slower, but works + "AND (key=\"md5\" AND value=\"" + rom.HashData.MD5 + "\" OR value=\"null\"))"
// more efficiently for my format. Get input? + "AND (key=\"sha1\" AND value=\"" + rom.HashData.SHA1 + "\" OR value=\"null\")))";
using (SqliteCommand slc = new SqliteCommand(query, dbc))
{
using (SqliteDataReader sldr = slc.ExecuteReader())
{
// If the hash exists in the database, add the dat hash for that id
if (sldr.HasRows)
{
sldr.Read();
string id = sldr.GetString(0);
string squery = "INSERT INTO data (id, key, value) VALUES (\"" + id + "\", \"dat\", \"" + key + "\")";
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
sslc.ExecuteNonQuery();
}
}
// If it doesn't exist, add the hash and the dat hash for a new id
else
{
string squery = "INSERT INTO data (key, value) VALUES (\"size\", \"" + rom.HashData.Size + "\")";
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
sslc.ExecuteNonQuery();
}
long id = -1;
squery = "SELECT last_insertConstants.Rowid()";
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
id = (long)sslc.ExecuteScalar();
}
squery = "INSERT INTO data (id, key, value) VALUES (\"" + id + "\", \"crc\", \"" + rom.HashData.CRC + "\"),"
+ " (\"" + id + "\", \"md5\", \"" + rom.HashData.MD5 + "\"),"
+ " (\"" + id + "\", \"sha1\", \"" + rom.HashData.SHA1 + "\"),"
+ " (\"" + id + "\", \"dat\", \"" + key + "\")";
using (SqliteCommand sslc = new SqliteCommand(squery, dbc))
{
sslc.ExecuteNonQuery();
}
}
}
}
}
}
} }
} }
} }

View File

@@ -40,6 +40,7 @@ CREATE TABLE IF NOT EXISTS data (
'id' INTEGER NOT NULL 'id' INTEGER NOT NULL
'key' TEXT NOT NULL 'key' TEXT NOT NULL
'value' TEXT NOT NULL 'value' TEXT NOT NULL
PRIMARY KEY (id, key, value)
)"; )";
SqliteCommand slc = new SqliteCommand(query, dbc); SqliteCommand slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery(); slc.ExecuteNonQuery();