storing binary data in a "memory" database
Bob Sneidar
bobsneidar at iotecdigital.com
Fri Jun 3 18:55:09 EDT 2022
Hi Doc thanks for the response. I am using aes256 encryption so an ascii hash is not viable. If this were a file based sqLite database I could perhaps change the encoding. Maybe I can with a :memory: database too! Here's my code. I have posted this before, it's an incredibly useful handler. If you provide pDBID it will ADD or REPLACE a table in that :memory: database. If you do NOT it will create a NEW :memory: database and return the database ID. The parameter pDBName is misnamed it should probably be pTableName. I'll fix that later.
I suppose what I need is a statement to change the encoding of the database before I create it.
put arrayToSQLite(tPasswordsDataA, ":memory:", "passwords", lMemoryDB) into lMemoryDB
FUNCTION arrayToSQLite pArrayDataA, pDBFile, pDBName, pDBID
put the keys of pArrayDataA into tArrayKeys
sort tArrayKeys numeric ascending
IF pDBFile is empty THEN put ":memory:" into pDBFile
IF pDBName is empty THEN put "arraydata" into pDBName
TRY
if pDBID is empty then \
put revOpenDatabase("sqlite", pDBFile) into pDBID
IF "Error" is in pDBID THEN
return empty
END IF
put "drop table " & pDBName into tDropSQL
revExecuteSQL pDBID, tDropSQL
put the result into tResult
CATCH tError
answer tError
IF the environment is "development" THEN exit to top ELSE quit
END TRY
-- create the table
put "create table" && quote & pDBName & quote \
& cr into tCreateCommand
put "(" & quote & "recordid" & quote && "NUMERIC PRIMARY KEY UNIQUE, " \
& cr AFTER tCreateCommand
put the keys of pArrayDataA [1] into tRecordKeyList
REPEAT for each line tRecordKey in tRecordKeyList
if pArrayDataA [1] [tRecordKey] is an array or \
pArrayDataA [1] [tRecordKey] begins with "Salted__" then
put "BLOB" into tColumnType
else
put VARCHAR into tColumnType
end if
put quote & tRecordKey & quote && tColumnType & "," && cr AFTER tCreateCommand
END REPEAT
delete char -3 to -1 of tCreateCommand
put ")" AFTER tCreateCommand
TRY
revExecuteSQL pDBID, tCreateCommand
put the result into tResult
IF tResult is not 0 THEN breakpoint
CATCH tError
breakpoint
END TRY
put 1 into tRecordCounter
put "recordid" & cr & tRecordKeyList into tColumns
repeat with i = 1 to the number of lines of tColumns
put ":" & i into item i of tColumnList
end repeat
put "(" & tColumnList & ")" into tColumnList
-- insert data
REPEAT for each line tKey in tArrayKeys
put 1 into tColumnCounter
put pArrayDataA [tKey] into tRecordDataA
put tRecordCounter into tQueryDataA [1]
REPEAT for each line tRecordKey in tRecordKeyList
add 1 to tColumnCounter
if tRecordDataA [tRecordKey] is an array then
put arrayEncode(tRecordDataA [tRecordKey]) into tValue
else
put tRecordDataA [tRecordKey] into tValue
end if
put tValue into tQueryDataA [tColumnCounter]
END REPEAT
put "insert into" && pDBName && "VALUES" && tColumnList into tInsertSQL
TRY
revExecuteSQL pDBID, tInsertSQL, "tQueryDataA"
put the result into tResult
if the result is not a number then breakpoint
CATCH tError
breakpoint
END TRY
add 1 to tRecordCounter
END REPEAT
return pDBID
END arrayToSQLite
> On Jun 3, 2022, at 15:04 , doc hawk via use-livecode <use-livecode at lists.runrev.com> wrote:
>
> A couple of lines of code with declarations, storing, and retrieving would probably help.
>
>
> There also might be a UTF issue (which would be beyond me)—a hash should be in good old 6.5 bit ASCII, not something newfangled with eight or more bits.
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list