Fred J. Stephens wrote: > Thanks John & Dennis; > Looks like I am getting ahead of myself here. I'm just doing a simple > PIM app as a BASH script that uses SQLite to store data. Probably I > can't do this in a script as you could in C. > > I find the formating of the text from a file is not saved if I read it > and insert it into a table, so I was hoping there was a way to save the > binary file and thus preserve all the formatting. Also it would let me > save images etc. in the database. > > When I get back to learning Python, maybe one of the SQLite wrappers > will help me do this more easily. My present program is really just a > way to get started until I move to Python. Also, it is good practice in > BASH scripting, SQL and basic usage of SQLite. >
Fred, If you are using the command line sqlite3 program rather than the library, then all your input must be text that can appear on the command line or be redirected from stdin. Handling binary data this way will be difficult. They only idea I have is to use another command to encode the binary file as pure text, say by converting each byte into a two character hex encoding of that byte, and then using .import to load the encoded text file into a table. From there other SQL commands can move the data to other tables etc. To recover the file your bash scripts would have to export the encoded file using .output and a select statement, then run another command to decode the file back to its binary representation. The encode/decode programs would be quite easy to write in C or Python, or they may already exist. One disadvantage of this scheme is that the encoded file will be twice the size of the original. This could be mitigated for text files by compressing them before encoding, and decompressing them after decoding, since text files typically compress very well. This wouldn't work (i.e. won't stop the file doubling) for files that hold compressed data such as jpeg image data. Any of the command line file compressors, like gzip and bzip, should work fine. Note the encoding scheme must not split a file into multiple lines (i.e the encoded format can't have any embedded linefeeds), since the .import command would split the file into multiple records. HTH Dennis Cote _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users