-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove added media #16
Comments
Hi, sorry for the delay, it should be possible. When I have some spare time I'll work on it |
Brilliant!! I will wait anxiously |
Hello friend, I took the audacity to start this function, I already have progress, tomorrow I finish. |
Hello, how did it go with this? Have you been able to get media removed? |
Hi, when you said
I thought you would make a pull request, then I forgot about it 😅 |
Hello friend, I lost our conversation, today I remembered this request and I wanted to come take a look and I see that you answered me. I think the following code could help with that module: Imports System.IO
Imports System.Data.SQLite
Module DeleteMedia
Sub DeleteImg(doc As Document, mediaId As Integer)
Dim dbPath As String = doc.pub.path & "\" & doc.pub.name & ".db"
If Not File.Exists(dbPath) Then Return
Using SQLCon As New SQLiteConnection(String.Format("Data Source = {0}", dbPath))
Dim deleteMultimediaQuery As String = "DELETE FROM Multimedia WHERE MultimediaId = @MediaId"
Dim deleteDocumentMultimediaQuery As String = "DELETE FROM DocumentMultimedia WHERE DocumentId = @DocumentId AND MultimediaId = @MediaId"
SQLCon.Open()
Dim deleteMultimediaCMD As New SQLiteCommand(deleteMultimediaQuery, SQLCon)
deleteMultimediaCMD.Parameters.AddWithValue("@MediaId", mediaId)
deleteMultimediaCMD.ExecuteNonQuery()
Dim deleteDocumentMultimediaCMD As New SQLiteCommand(deleteDocumentMultimediaQuery, SQLCon)
deleteDocumentMultimediaCMD.Parameters.AddWithValue("@DocumentId", CStr(doc.documentId))
deleteDocumentMultimediaCMD.Parameters.AddWithValue("@MediaId", mediaId)
deleteDocumentMultimediaCMD.ExecuteNonQuery()
SQLCon.Close()
End Using
End Sub
Sub DeleteVideo(doc As Document, mediaId As Integer)
Dim dbPath As String = doc.pub.path & "\" & doc.pub.name & ".db"
If Not File.Exists(dbPath) Then Return
Using SQLCon As New SQLiteConnection(String.Format("Data Source = {0}", dbPath))
Dim deleteMultimediaQuery As String = "DELETE FROM Multimedia WHERE MultimediaId = @MediaId"
Dim deleteDocumentMultimediaQuery As String = "DELETE FROM DocumentMultimedia WHERE DocumentId = @DocumentId AND MultimediaId = @MediaId"
SQLCon.Open()
Dim deleteMultimediaCMD As New SQLiteCommand(deleteMultimediaQuery, SQLCon)
deleteMultimediaCMD.Parameters.AddWithValue("@MediaId", mediaId)
deleteMultimediaCMD.ExecuteNonQuery()
Dim deleteDocumentMultimediaCMD As New SQLiteCommand(deleteDocumentMultimediaQuery, SQLCon)
deleteDocumentMultimediaCMD.Parameters.AddWithValue("@DocumentId", CStr(doc.documentId))
deleteDocumentMultimediaCMD.Parameters.AddWithValue("@MediaId", mediaId)
deleteDocumentMultimediaCMD.ExecuteNonQuery()
SQLCon.Close()
End Using
End Sub
End Module The general structure is similar to the add media sub-procedures, but instead of inserting, here we are executing queries to delete records related to media and documents in the database. |
And this should work to get the media data from the database and another function called Imports System.Data.SQLite
Module ShowMultimedia
Sub Main()
Dim dbPath As String = "ruta/a/tu/base/de/datos.db" ' Cambia esto a la ruta de tu base de datos SQLite
Dim multimediaList As List(Of Multimedia) = GetMultimediaFromDatabase(dbPath)
For Each media As Multimedia In multimediaList
Console.WriteLine($"Media ID: {media.MultimediaId}")
Console.WriteLine($"Data Type: {media.DataType}")
Console.WriteLine($"Major Type: {media.MajorType}")
Console.WriteLine($"Minor Type: {media.MinorType}")
Console.WriteLine($"MIME Type: {media.MimeType}")
Console.WriteLine($"Caption: {media.Caption}")
Console.WriteLine($"File Path: {media.FilePath}")
Console.WriteLine($"Category Type: {media.CategoryType}")
Console.WriteLine()
Next
End Sub
Function GetMultimediaFromDatabase(dbPath As String) As List(Of Multimedia)
Dim multimediaList As New List(Of Multimedia)
If Not System.IO.File.Exists(dbPath) Then
Return multimediaList
End If
Using sqlCon As New SQLiteConnection(String.Format("Data Source = {0}", dbPath))
Dim query As String = "SELECT MultimediaId, DataType, MajorType, MinorType, MimeType, Caption, FilePath, CategoryType FROM multimedia"
sqlCon.Open()
Using command = sqlCon.CreateCommand()
command.CommandText = query
Using reader = command.ExecuteReader()
While reader.Read()
Dim media As New Multimedia()
media.MultimediaId = reader.GetInt32(0)
media.DataType = reader.GetInt32(1)
media.MajorType = reader.GetInt32(2)
media.MinorType = reader.GetInt32(3)
media.MimeType = reader.GetString(4)
media.Caption = reader.GetString(5)
media.FilePath = reader.GetString(6)
media.CategoryType = reader.GetInt32(7)
multimediaList.Add(media)
End While
End Using
End Using
sqlCon.Close()
End Using
Return multimediaList
End Function
End Module
Class Multimedia
Public MultimediaId As Integer
Public DataType As Integer
Public MajorType As Integer
Public MinorType As Integer
Public MimeType As String
Public Caption As String
Public FilePath As String
Public CategoryType As Integer
End Class |
If you get it done and functional, I'd like to clone your project in Go, so it's available on Windows, macOS, and Linux. I'm sure many users will appreciate it. The Playlist functions may not work as many would expect. |
Hello friend, is it possible to add the function to delete the added multimedia, for example, now it is possible to add an image or a video, but is it possible to only delete an image or a video without having to restore the entire publication?
The text was updated successfully, but these errors were encountered: