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

proc 2Hex { input } { binary encode hex [encoding convertto utf-8 "$input"] }
proc 2Base { input } { encoding convertfrom utf-8 [binary decode hex "$input"] }
####
set blog_dir ./blogServ/data" ;#todo replace hardcoded path
set blog_file "dox.blog"

proc sqlite_create {} {
;# procedure to create sqlite db
variable blog_dir
variable blog_file 
sqlite3 journal "$blog_dir/$blog_file"

journal eval { CREATE TABLE "entries" (
	"journal_entry_idx"	INTEGER,
	"journal_entry_menu_tag"	TEXT,
	"journal_entry_title"		TEXT,
	"journal_entry_image"		TEXT,
	"journal_entry_content"		TEXT,
	"journal_entry_datetime"	TEXT,
	PRIMARY KEY("journal_entry_idx" AUTOINCREMENT)
); }
} ;#end proc

## Procedure to add new data to DB from Recieved data
proc sqlite_new_entry {packet} {
# procedure to update db with new file
;# sqlite_new_entry "New Title" "No-Image" "Some New Content" "21st Feburary 2022"
variable blog_dir
variable blog_file 

##Check data to see if we received it all
puts "?>>>>>>>>>SQL>>>>>>>>>"
puts "Packet Received:\n$packet"
puts "Packet Data"
puts "0: journal_entry_menu_tag | [dict get [2Base $packet] journal_entry_menu_tag]"
puts "1: journal_entry_title    | [dict get [2Base $packet] journal_entry_title]"
puts "2: journal_entry_image 	| [dict get [2Base $packet] journal_entry_image]"
puts "3: journal_entry_content  | [dict get [2Base $packet] journal_entry_content]"
puts "4: journal_entry_content  | [dict get [2Base $packet] journal_entry_datetime]"
puts "5: not-used"
puts "6: not-used"
puts "7: not-used"
puts ">>>>>>>>>>>>>>>>>>>>>?"

;#Todo: Neaten data entries to variables
set journal_entry_menu_tag 	 "[2Hex [dict get [2Base $packet] journal_entry_menu_tag]]"
set journal_entry_title 	        "[2Hex [dict get [2Base $packet] journal_entry_title]]"
set journal_entry_image 	 "[2Hex [dict get [2Base $packet] journal_entry_image]]"
set journal_entry_content  	 "[2Hex [dict get [2Base $packet] journal_entry_content]]"
set journal_entry_datetime 	 "[2Hex [dict get [2Base $packet] journal_entry_datetime]]"

sqlite3 db "$blog_dir/$blog_file"
db eval { INSERT INTO entries (journal_entry_menu_tag, journal_entry_title, journal_entry_image, 
							   journal_entry_content,  journal_entry_datetime   ) 
					   VALUES( :journal_entry_menu_tag, :journal_entry_title, :journal_entry_image, 
							   :journal_entry_content,  :journal_entry_datetime ) }
db close } ;#end proc

# procedure to view post when "blog_button" is clicked
# This should pull the single row based on the "MenuTag" (the identifier of the button pressed in HTML FORM"

proc sqlite_view {journal_entry_menu_tag} {
variable blog_dir
variable blog_file 
;#procedure to read sqlite to dictonary
set journal_entry_menu_tag "f09f9299" ;#hard coded for testing
sqlite3 db "$blog_dir/$blog_file" ; # Open up an existing database or create a new empty one.
    set value [db eval {SELECT * FROM entries WHERE journal_entry_menu_tag = :journal_entry_menu_tag} ]
db close 
puts $value ;#Returns no result all data is populated
return $value
} ;#end proc

## Communications
NaviServer 
Data to send: 737769746368207669657720757365725f66696c6520646f7820706f73745f74797065206a6f75726e616c20636f6e66696720
7b646973706c61795f6d61785f656e7472795f6d656e7520357d206a6f75726e616c5f7573657220646f78206a6f75726e616c5f656e7472795f6964782031206a6f75726e616c5f656e7472795f6d656e755f746167206630396639323939206a6f75726e616c5f656e7472795f7469746c65207b7d206a6f75726e616c5f656e7472795f696d616765207b7d206a6f75726e616c5f656e7472795f636f6e74656e74207b7d206a6f75726e616c5f656e7472795f6461746574696d65207b323032322f30332f30382031333a31377d203120746f706261725f757365725f6d656e752032206a6f75726e616c5f656e74726965735f6d656e752033206a6f75726e616c5f656e7472795f7469746c652034206a6f75726e616c5f656e7472795f696d6167652035206a6f75726e616c5f656e7472795f6d656e755f7461672036206a6f75726e616c5f656e7472795f636f6e74656e7420372075695f61646d696e5f616374696f6e5f627574746f6e73

Socket Server
Packet Received:
737769746368206e657720757365725f66696c6520646f7820706f73745f74797065206a6f75726e616c20636f6e666967207b646973706c61795f6d61785f656e7472795f6d656e7520357d206a6f75726e616c5f7573657220646f78206a6f75726e616c5f656e7472795f6964782031206a6f75726e616c5f656e7472795f6d656e755f74616720f09f9299206a6f75726e616c5f656e7472795f7469746c65207bf09f9aa720496e2070726f67726573737d206a6f75726e616c5f656e7472795f696d616765207b7d206a6f75726e616c5f656e7472795f636f6e74656e74207be29aa0efb88f20496620796f75722072656164696e6720746869732c20203c6272202f3e2050726f677265737320697320756e64657277617920696e206372656174696e672061206e657720706c6174666f726d2e0a3c6272202f3e203c6272202f3e200a416e64206e6f7720616c6c2066756e6374696f6e7320776f726b20616761696e2e203c62723e0a0a0a436f6d706c657465643a203c6272202f3e200ae29c94efb88f20437265617465204461746162617365203c6272202f3e200ae29c94efb88f205570646174696e67204461746162617365203c6272202f3e200ae29c94efb88f204e657720456e74727920746f204461746162617365203c6272202f3e200a3c6272202f3e200a496e2050726f67726573733a203c6272202f3e200a0a3c6272202f3e0a4e6f7420537461727465643a203c6272202f3e0ae29d8c202044656c6574696f6e2066726f6d204461746162617365203c6272202f3e207d206a6f75726e616c5f656e7472795f6461746574696d65207b323032322f30332f30382031333a31377d203120746f706261725f757365725f6d656e752032206a6f75726e616c5f656e74726965735f6d656e752033206a6f75726e616c5f656e7472795f7469746c652034206a6f75726e616c5f656e7472795f696d6167652035206a6f75726e616c5f656e7472795f6d656e755f7461672036206a6f75726e616c5f656e7472795f636f6e74656e7420372075695f61646d696e5f616374696f6e5f627574746f6e73

Dictonary converted back to BASE32 data

switch get 
user_file dox 
post_type journal 
config {display_max_entry_menu 5} 
journal_user dox 
journal_entry_idx 1 
journal_entry_menu_tag %F0%9F%92%99 
journal_entry_title {%F0%9F%9A%A7 In progress} 
journal_entry_image {} 
journal_entry_content {  If your reading this,  <br /> Progress is underway in creating a new platform.
<br /> <br />
And now all functions work again. <br>

Completed: <br />
 Create Database <br />
 Updating Database <br />
 New Entry to Database <br />
<br />
In Progress: <br />

<br />
Not Started: <br />
L  Deletion from Database <br /> }
 journal_entry_datetime {2022/03/08 13:17} 
1 topbar_user_menu 
2 journal_entries_menu 
3 journal_entry_title 
4 journal_entry_image 
5 journal_entry_menu_tag 
6 journal_entry_content 
7 ui_admin_action_buttons
connection error status: 0

###

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