Almacenamiento/registro de pulsaciones de teclas en una base de datos

I am developing a module which has to log and later playback all individual keystrokes in a form field. I would like to be able to store this in a database, and be able to retrieve this fast.

Typically it will be used to replay the path the user took to come to the finally submitted text.

I want to know if inserting a record for each keypress (perhaps grouping consecutive same strokes with a count for compression , albeit losing some timestamp info ?) is good,

CREATE TABLE `keystroke_log` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `keystroke` char(1) NOT NULL,
  `count` smallint(6) unsigned NOT NULL,
  `user_id` int(11) unsigned NOT NULL,
  'form_field_id' int(11) unsigned NOT NULL,
  'timestamp' timestamp NOT NULL default CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

or is it better to store all keystrokes in a single row as serialised JSON object with something like this ?

CREATE TABLE `keystroke_log` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `user_id` int(11) unsigned NOT NULL,
  `form_field_id` int(11) unsigned NOT NULL,
  `keystroke_dump` MEDIUMTEXT DEFAULT NULL,
) ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8 ENGINE=InnoDB DEFAULT CHARSET=utf8;

EDITAR: Los keystroke_dump JSON object would ideally contain timestamp and the actual UTF-8 stroke code

Is there any better way to store and retrieve this data ?

JSON in a relational DB is never a good idea, however the most common query will have to load the entire object anyway querying for full playback I am not sure if using a sql structure will result in significant performance loss?

preguntado el 28 de mayo de 14 a las 12:05

are you trying to capture my home banking password? :-) I'd go with the second option. Storing each keypress + timestamp looks a little "over" for me -

Why would you store JSON object insteaf of a simple utf8 (or whatever) encoded string ? -

The best way to store the data depends on how you plan to use it. -

@Zaffy i am not talking about storing the final string, i am talking about the keystrokes that lead to it, -

@Leo lol!.. this is to monitor students and prevent cheating in assessments :D -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.