private static void WriteLFold(SQLiteConnection conn, LogicalFolder lfold, int parent = 0) { using (var cmd = conn.CreateCommand()) { /* * [ID] INTEGER NOT NULL PRIMARY KEY, * [Owner] INTEGER NOT NULL, * [Name] TEXT, * [Desc] TEXT, * [Type] INTEGER */ cmd.CommandText = "INSERT INTO [LFold] (Owner, Name, Desc, Type) VALUES ("; cmd.CommandText += "'" + parent + "',"; cmd.CommandText += "'" + lfold.Name.Replace("'", "''") + "',"; cmd.CommandText += "'" + lfold.Description.Replace("'", "''") + "',"; cmd.CommandText += "'" + (int)lfold.FolderType + "')"; cmd.ExecuteNonQuery(); // pass disc id for folders cmd.CommandText = "select last_insert_rowid()"; Int64 lastRowId64 = (Int64)cmd.ExecuteScalar(); int lastRowId = (int)lastRowId64; lfold.DbId = lastRowId; // Will need this for logical folder map foreach (var subFold in lfold.GetSubFolders()) { WriteLFold(conn, subFold, lastRowId); } } }
private static void WriteLFoldMap(SQLiteConnection conn, LogicalFolder lfold) { // Write the mapping between logical folders and items in them. // This code depends on each object's DbId having been updated // earlier in the write process. //[ID] INTEGER NOT NULL PRIMARY KEY, //[LFold] INTEGER NOT NULL, //[ItemId] INTEGER NOT NULL, //[ItemType] INTEGER NOT NULL if (_writeLFoldMapCmd == null) { _writeLFoldMapCmd = new SQLiteCommand(conn); const string sql = "insert into [LFoldMap] (LFold,ItemId,ItemType) VALUES (@lfold,@item,@type)"; _writeLFoldMapCmd.CommandText = sql; } foreach (var iid in lfold.Items) { _writeFileCmd.Parameters.Clear(); _writeLFoldMapCmd.Parameters.Add("@lfold", DbType.Int32).Value = lfold.DbId; _writeLFoldMapCmd.Parameters.Add("@item", DbType.Int32).Value = iid.DbId; int itemType = 1; // assume folder (regular) if (iid is CompressedFile) { itemType = 1; } else if (iid is FileInDatabase) { itemType = 2; } else if (iid is DiscInDatabase) { itemType = 3; } _writeLFoldMapCmd.Parameters.Add("@type", DbType.Int16).Value = itemType; _writeLFoldMapCmd.ExecuteNonQuery(); } foreach (var subf in lfold.GetSubFolders()) { WriteLFoldMap(conn, subf); } }