| |||||||||||
how to load text file into largetext field? Posted by that_guy (that_guy), 5 August 2003 Hello- yet another question data logging question: I'm working on a program that lets users launch programs and settings on a variety of pcs, switches, etc. I'm logging output from all the processes using trace variable expect_out(buffer). Each process is currently logged to a file named after the host on which the process is being run. I'd like to store the logged output of these console programs (iperf,tcpdump,etc) into mysql in the table belowmysql> describe experiment_results; +------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+-------+ | exp_name | varchar(80) | YES | | NULL | | | seq_number | mediumint(9) | YES | | NULL | | | output | longtext | YES | | NULL | | +------------+--------------+------+-----+---------+-------+ 3 rows in set (0.01 sec) I've tried reading in the files by the technique below,but as you can see, the result is just NULL. I read the docs on using LOAD_FILE and it says that the function will return NULL if the file is (1) not located on the server, (2) bigger than max_packet_size or (3) not listed via an absolute path. As far as I know I've satisfied all the requirements for this to work. I'm not sure about the max_packet_size issue, but a show variables does not reveal a max_packet_size variable at all. Alternatively, I wouldn't mind writing program output directly to the database, but I'm not sure what sort of buffering I'd have to setup to do that, other than perhaps within Expect/tcl have an array indexed by spawn_id and have the trace lappend output as it comes in to the appropriate cell in the array. mysql> update experiment_results set output=LOAD_FILE("/home/thatguy/refactor/test_monitor/n0a0.log"); Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from experiment_results; +----------+------------+--------+ | exp_name | seq_number | output | +----------+------------+--------+ | exp1 | NULL | NULL | +----------+------------+--------+ 1 row in set (0.00 sec) Long story short, does anyone know of a good way to log large text data into a single field in a mysql table, by any means? Posted by admin (Graham Ellis), 7 August 2003 Hmm. I would wonder about loading from file ...Question noted; I'm in an internet cafe at the moment; question is a good one; I'll have a play about and post an answer next time I'm around Posted by that_guy (that_guy), 7 August 2003 the approach I took so far was to do the file reading in tcl- read the contents of the file into a variable and then use mysqltcl to insert the contents of that variable into a field, thus obviating the need for mysql's nonstandard load_file. This seems to work fine, but I'm wondering whether it really makes sense to write out the files at all if the final destination is a database. I think using only variables for the temporary storage would be complicated- not sure how the buffering would work.Posted by admin (Graham Ellis), 7 August 2003 I've tried out a 250k shell session, and saved it into a database with no problem; I used PHP, and the "trick" is to use a normal insert command, but add extra \ characters to protect things like " which would normally be the terminating string. In PHP the function I used is "quotemeta"; "addslashes" might do it as well. I don't have Tcl to hand this week, alas This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |