webmcp
view framework/env/trace/sql.lua @ 375:fb98b17056e5
Proper support for mutable data types (JSON objects/arrays) in table columns
| author | jbe | 
|---|---|
| date | Sat Nov 14 15:44:53 2015 +0100 (2015-11-14) | 
| parents | e3e2a03f75b2 | 
| children | 
 line source
     1 --[[--
     2 trace.sql{
     3   command        = command,         -- executed SQL command as string
     4   execution_time = execution_time,  -- execution time of the statement in seconds
     5   error_position = error_position   -- optional position in bytes where an error occurred
     6 }
     8 This command is used to log SQL command execution. It does not need to be invoked manually.
    10 --]]--
    12 function trace.sql(args)
    13   if not trace._disabled then
    14     local command = args.command
    15     local execution_time = args.execution_time
    16     local error_position = args.error_position
    17     if type(command) ~= "string" then
    18       error("No command string passed to trace.sql{...}.")
    19     end
    20     if type(execution_time) ~= "number" then
    21       error("No execution time number passed to trace.sql{...}.")
    22     end
    23     if error_position and type(error_position) ~= "number" then
    24       error("error_position must be a number.")
    25     end
    26     trace._new_entry{
    27       type           = "sql",
    28       command        = command,
    29       execution_time = execution_time,
    30       error_position = error_position
    31     }
    32     for i, entry in ipairs(trace._stack) do
    33       entry.db_time = entry.db_time + execution_time
    34     end
    35   end
    36 end
