Posted to tcl by mookie at Tue Mar 08 13:31:41 GMT 2022view raw

  1. proc 2Hex { input } { binary encode hex [encoding convertto utf-8 "$input"] }
  2. proc 2Base { input } { encoding convertfrom utf-8 [binary decode hex "$input"] }
  3. ####
  4. set blog_dir ./blogServ/data" ;#todo replace hardcoded path
  5. set blog_file "dox.blog"
  6.  
  7. proc sqlite_create {} {
  8. ;# procedure to create sqlite db
  9. variable blog_dir
  10. variable blog_file
  11. sqlite3 journal "$blog_dir/$blog_file"
  12.  
  13. journal eval { CREATE TABLE "entries" (
  14. "journal_entry_idx" INTEGER,
  15. "journal_entry_menu_tag" TEXT,
  16. "journal_entry_title" TEXT,
  17. "journal_entry_image" TEXT,
  18. "journal_entry_content" TEXT,
  19. "journal_entry_datetime" TEXT,
  20. PRIMARY KEY("journal_entry_idx" AUTOINCREMENT)
  21. ); }
  22. } ;#end proc
  23.  
  24. ## Procedure to add new data to DB from Recieved data
  25. proc sqlite_new_entry {packet} {
  26. # procedure to update db with new file
  27. ;# sqlite_new_entry "New Title" "No-Image" "Some New Content" "21st Feburary 2022"
  28. variable blog_dir
  29. variable blog_file
  30.  
  31. ##Check data to see if we received it all
  32. puts "?>>>>>>>>>SQL>>>>>>>>>"
  33. puts "Packet Received:\n$packet"
  34. puts "Packet Data"
  35. puts "0: journal_entry_menu_tag | [dict get [2Base $packet] journal_entry_menu_tag]"
  36. puts "1: journal_entry_title | [dict get [2Base $packet] journal_entry_title]"
  37. puts "2: journal_entry_image | [dict get [2Base $packet] journal_entry_image]"
  38. puts "3: journal_entry_content | [dict get [2Base $packet] journal_entry_content]"
  39. puts "4: journal_entry_content | [dict get [2Base $packet] journal_entry_datetime]"
  40. puts "5: not-used"
  41. puts "6: not-used"
  42. puts "7: not-used"
  43. puts ">>>>>>>>>>>>>>>>>>>>>?"
  44.  
  45. ;#Todo: Neaten data entries to variables
  46. set journal_entry_menu_tag "[2Hex [dict get [2Base $packet] journal_entry_menu_tag]]"
  47. set journal_entry_title "[2Hex [dict get [2Base $packet] journal_entry_title]]"
  48. set journal_entry_image "[2Hex [dict get [2Base $packet] journal_entry_image]]"
  49. set journal_entry_content "[2Hex [dict get [2Base $packet] journal_entry_content]]"
  50. set journal_entry_datetime "[2Hex [dict get [2Base $packet] journal_entry_datetime]]"
  51.  
  52. sqlite3 db "$blog_dir/$blog_file"
  53. db eval { INSERT INTO entries (journal_entry_menu_tag, journal_entry_title, journal_entry_image,
  54. journal_entry_content, journal_entry_datetime )
  55. VALUES( :journal_entry_menu_tag, :journal_entry_title, :journal_entry_image,
  56. :journal_entry_content, :journal_entry_datetime ) }
  57. db close } ;#end proc
  58.  
  59. # procedure to view post when "blog_button" is clicked
  60. # This should pull the single row based on the "MenuTag" (the identifier of the button pressed in HTML FORM"
  61.  
  62. proc sqlite_view {journal_entry_menu_tag} {
  63. variable blog_dir
  64. variable blog_file
  65. ;#procedure to read sqlite to dictonary
  66. set journal_entry_menu_tag "f09f9299" ;#hard coded for testing
  67. sqlite3 db "$blog_dir/$blog_file" ; # Open up an existing database or create a new empty one.
  68. set value [db eval {SELECT * FROM entries WHERE journal_entry_menu_tag = :journal_entry_menu_tag} ]
  69. db close
  70. puts $value ;#Returns no result all data is populated
  71. return $value
  72. } ;#end proc
  73.  
  74. ## Communications
  75. NaviServer
  76. Data to send: 737769746368207669657720757365725f66696c6520646f7820706f73745f74797065206a6f75726e616c20636f6e66696720
  77. 7b646973706c61795f6d61785f656e7472795f6d656e7520357d206a6f75726e616c5f7573657220646f78206a6f75726e616c5f656e7472795f6964782031206a6f75726e616c5f656e7472795f6d656e755f746167206630396639323939206a6f75726e616c5f656e7472795f7469746c65207b7d206a6f75726e616c5f656e7472795f696d616765207b7d206a6f75726e616c5f656e7472795f636f6e74656e74207b7d206a6f75726e616c5f656e7472795f6461746574696d65207b323032322f30332f30382031333a31377d203120746f706261725f757365725f6d656e752032206a6f75726e616c5f656e74726965735f6d656e752033206a6f75726e616c5f656e7472795f7469746c652034206a6f75726e616c5f656e7472795f696d6167652035206a6f75726e616c5f656e7472795f6d656e755f7461672036206a6f75726e616c5f656e7472795f636f6e74656e7420372075695f61646d696e5f616374696f6e5f627574746f6e73
  78.  
  79. Socket Server
  80. Packet Received:
  81. 737769746368206e657720757365725f66696c6520646f7820706f73745f74797065206a6f75726e616c20636f6e666967207b646973706c61795f6d61785f656e7472795f6d656e7520357d206a6f75726e616c5f7573657220646f78206a6f75726e616c5f656e7472795f6964782031206a6f75726e616c5f656e7472795f6d656e755f74616720f09f9299206a6f75726e616c5f656e7472795f7469746c65207bf09f9aa720496e2070726f67726573737d206a6f75726e616c5f656e7472795f696d616765207b7d206a6f75726e616c5f656e7472795f636f6e74656e74207be29aa0efb88f20496620796f75722072656164696e6720746869732c20203c6272202f3e2050726f677265737320697320756e64657277617920696e206372656174696e672061206e657720706c6174666f726d2e0a3c6272202f3e203c6272202f3e200a416e64206e6f7720616c6c2066756e6374696f6e7320776f726b20616761696e2e203c62723e0a0a0a436f6d706c657465643a203c6272202f3e200ae29c94efb88f20437265617465204461746162617365203c6272202f3e200ae29c94efb88f205570646174696e67204461746162617365203c6272202f3e200ae29c94efb88f204e657720456e74727920746f204461746162617365203c6272202f3e200a3c6272202f3e200a496e2050726f67726573733a203c6272202f3e200a0a3c6272202f3e0a4e6f7420537461727465643a203c6272202f3e0ae29d8c202044656c6574696f6e2066726f6d204461746162617365203c6272202f3e207d206a6f75726e616c5f656e7472795f6461746574696d65207b323032322f30332f30382031333a31377d203120746f706261725f757365725f6d656e752032206a6f75726e616c5f656e74726965735f6d656e752033206a6f75726e616c5f656e7472795f7469746c652034206a6f75726e616c5f656e7472795f696d6167652035206a6f75726e616c5f656e7472795f6d656e755f7461672036206a6f75726e616c5f656e7472795f636f6e74656e7420372075695f61646d696e5f616374696f6e5f627574746f6e73
  82.  
  83. Dictonary converted back to BASE32 data
  84.  
  85. switch get
  86. user_file dox
  87. post_type journal
  88. config {display_max_entry_menu 5}
  89. journal_user dox
  90. journal_entry_idx 1
  91. journal_entry_menu_tag %F0%9F%92%99
  92. journal_entry_title {%F0%9F%9A%A7 In progress}
  93. journal_entry_image {}
  94. journal_entry_content {  If your reading this, <br /> Progress is underway in creating a new platform.
  95. <br /> <br />
  96. And now all functions work again. <br>
  97.  
  98. Completed: <br />
  99.  Create Database <br />
  100.  Updating Database <br />
  101.  New Entry to Database <br />
  102. <br />
  103. In Progress: <br />
  104.  
  105. <br />
  106. Not Started: <br />
  107. L Deletion from Database <br /> }
  108. journal_entry_datetime {2022/03/08 13:17}
  109. 1 topbar_user_menu
  110. 2 journal_entries_menu
  111. 3 journal_entry_title
  112. 4 journal_entry_image
  113. 5 journal_entry_menu_tag
  114. 6 journal_entry_content
  115. 7 ui_admin_action_buttons
  116. connection error status: 0
  117.  
  118. ###

Comments

Posted by sebres at Tue Mar 08 14:05:47 GMT 2022 [text] [code]

set packet {737769746368207669657720757365725f66696c6520646f7820706f73745f74797065206a6f75726e616c20636f6e66696720 7b646973706c61795f6d61785f656e7472795f6d656e7520357d206a6f75726e616c5f7573657220646f78206a6f75726e616c5f656e7472795f6964782031206a6f75726e616c5f656e7472795f6d656e755f746167206630396639323939206a6f75726e616c5f656e7472795f7469746c65207b7d206a6f75726e616c5f656e7472795f696d616765207b7d206a6f75726e616c5f656e7472795f636f6e74656e74207b7d206a6f75726e616c5f656e7472795f6461746574696d65207b323032322f30332f30382031333a31377d203120746f706261725f757365725f6d656e752032206a6f75726e616c5f656e74726965735f6d656e752033206a6f75726e616c5f656e7472795f7469746c652034206a6f75726e616c5f656e7472795f696d6167652035206a6f75726e616c5f656e7472795f6d656e755f7461672036206a6f75726e616c5f656e7472795f636f6e74656e7420372075695f61646d696e5f616374696f6e5f627574746f6e73 } puts [2Base $packet] ; # ===> ... journal_entry_menu_tag f09f9299 ... set journal_entry_menu_tag "[2Hex [dict get [2Base $packet] journal_entry_menu_tag]]"; # ===> 6630396639323939