Author Topic: MySQL database for video clip info  (Read 1009 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
MySQL database for video clip info
« on: June 22, 2020, 10:52:02 pm »
A post by @lawsonm1 earlier was talking about how he wanted to be able to store info about video clips in a file or something to be read back later so he can open them in VLC. This is just a test to show that it would work but here is my contribution using MySQL. I'm not posting the whole code here because I would need to use Source Merger and there would be a lot of cutting. I'll just post the main module that does the work :)
Code: QB64: [Select]
  1. '$INCLUDE:'MYSQL.BI'
  2. TYPE Video
  3.     vid_id AS LONG
  4.     video_name AS STRING
  5.     coloration AS STRING
  6.     clip_length AS STRING
  7.     clip_type AS STRING
  8.  
  9. mydb = DB_Open("Spriggsy", "videouser", "pass@word", "")
  10.  
  11. DIM Video AS Video
  12. Video.video_name = "Superman Returns"
  13. Video.coloration = "color"
  14. Video.clip_length = "2h49m"
  15. Video.clip_type = "movie"
  16.  
  17. Video.vid_id = AddVideo(Video)
  18. IF Video.vid_id <> 0 THEN
  19.     PRINT "Successfully added "; Video.video_name; " to database"
  20. PRINT Video.vid_id
  21.  
  22. FUNCTION AddVideo (Video AS Video)
  23.     DIM ReturnVideo AS Video
  24.     Video.vid_id = 0
  25.     DB_QUERY "INSERT INTO `videos`.`video` (video_name, coloration, clip_length, clip_type) VALUES ('" + Video.video_name + "','" + Video.coloration + "','" + Video.clip_length + "','" + Video.clip_type + "');"
  26.     DB_QUERY "SELECT vid_id FROM `videos`.`video` WHERE video_name = '" + Video.video_name + "' AND coloration = '" + Video.coloration + "' AND clip_length = '" + Video.clip_length + "' AND clip_type = '" + Video.clip_type + "';"
  27.     FOR y = 1 TO UBOUND(db_result, 2)
  28.         ReturnVideo.vid_id = VAL(DB_RESULT(1, y))
  29.     NEXT
  30.     IF ReturnVideo.vid_id <> 0 THEN
  31.         AddVideo = ReturnVideo.vid_id
  32.     ELSE
  33.         AddVideo = 0
  34.     END IF
  35.  
  36. '$INCLUDE:'MYSQL.BM'
Here are screenshots showing the program working:
 
add video to database.png

 
proof of add to database.png

I think it would be a great idea to use MySQL as it doesn't require any kind of parsing of a file or knowing any kind of insane sorting algorithms. I'll end up showing more for this later on when I finally do a post all about how to use MySQL effectively in QB64. This is just a simple usage. I figured using a user defined type would be best so you can keep it straight in your mind the column names and the variables that they pair with.
« Last Edit: June 22, 2020, 10:54:00 pm by SpriggsySpriggs »
Shuwatch!