cmd.CommandText=string.Format(@"CREATE TEMPORARY TABLE ""{0}"" (""ID"" INTEGER PRIMARY KEY, ""Path"" TEXT NOT NULL, ""BlocksetID"" INTEGER NOT NULL, ""MetadataID"" INTEGER NOT NULL, ""Targetpath"" TEXT NULL ) ",m_tempfiletable);
cmd.ExecuteNonQuery();
cmd.CommandText=string.Format(@"CREATE TEMPORARY TABLE ""{0}"" (""FileID"" INTEGER NOT NULL, ""Index"" INTEGER NOT NULL, ""Hash"" TEXT NOT NULL, ""Size"" INTEGER NOT NULL, ""Restored"" BOOLEAN NOT NULL)",m_tempblocktable);
cmd.ExecuteNonQuery();
if(filenameFilter==null&&(p==null||p.Length==0))
{
// Simple case, restore everything
cmd.CommandText=string.Format(@"INSERT INTO ""{0}"" (""Path"", ""BlocksetID"", ""MetadataID"") SELECT ""Fileset"".""Path"", ""Fileset"".""BlocksetID"", ""Fileset"".""MetadataID"" FROM ""Fileset"", ""OperationFileset"" WHERE ""Fileset"".""ID"" = ""OperationFileset"".""FilesetID"" AND ""OperationFileset"".""OperationID"" = ? ",m_tempfiletable);
cmd.AddParameter(operationID);
cmd.ExecuteNonQuery();
}
elseif(p!=null&&p.Length>0)
{
// Restore files in list
cmd.CommandText=string.Format(@"INSERT INTO ""{0}"" (""Path"", ""BlocksetID"", ""MetadataID"") SELECT ""Fileset"".""Path"", ""Fileset"".""BlocksetID"", ""Fileset"".""MetadataID"" FROM ""Fileset"", ""OperationFileset"" WHERE ""Fileset"".""ID"" = ""OperationFileset"".""FilesetID"" AND ""OperationID"" = ? AND ""Path"" = ? ",m_tempfiletable);
cmd.AddParameter(operationID);
cmd.AddParameter();
//TODO: Actually faster to just create a temp table with files,
// and then using a select to create the temporary table
// but there should be some way to report if filenames
// are not found
foreach(varsinp)
{
cmd.SetParameterValue(1,s);
varc=cmd.ExecuteNonQuery();
if(c!=1)
thrownewException("Failed to insert file into temp table");
}
}
else
{
// Restore but filter elements based on regexp
cmd.CommandText=string.Format(@"SELECT ""Fileset"".""Path"", ""Fileset"".""BlocksetID"", ""Fileset"".""MetadataID"" FROM ""Fileset"", ""OperationFileset"" WHERE ""Fileset"".""ID"" = ""OperationFileset"".""FilesetID"" AND ""OperationID"" = ?");
cmd.AddParameter(operationID);
object[]values=newobject[3];
using(varcmd2=m_connection.CreateCommand())
{
cmd2.CommandText=string.Format(@"INSERT INTO ""{0}"" (""Path"", ""BlocksetID"", ""MetadataID"") VALUES (?,?,?)",m_tempfiletable);
cmd.CommandText=string.Format(@"SELECT DISTINCT ""RemoteVolume"".""Name"", ""RemoteVolume"".""Hash"", ""RemoteVolume"".""Size"" FROM ""RemoteVolume"" WHERE ""Name"" IN (SELECT DISTINCT ""Block"".""File"" FROM ""Block"" WHERE ""Block"".""Hash"" IN (SELECT DISTINCT ""{0}"".""Hash"" FROM ""{0}"" WHERE ""{0}"".""Restored"" = 0))",m_tempblocktable);
m_command.CommandText=string.Format(@"UPDATE ""{0}"" SET ""Restored"" = 1 WHERE ""FileID"" = (SELECT ""ID"" FROM ""{1}"" WHERE ""TargetPath"" = ?) AND ""Index"" = ? AND ""Hash"" = ? AND ""Size"" = ? ",blocktablename,filetablename);