webmcp
annotate framework/env/trace/sql.lua @ 496:3b4dbabca31f
Bugfix in request.handler(...) for allowing actions to directly return content
| author | jbe | 
|---|---|
| date | Sun Jul 02 04:22:20 2017 +0200 (2017-07-02) | 
| parents | e3e2a03f75b2 | 
| children | 
| rev | line source | 
|---|---|
| jbe/bsw@0 | 1 --[[-- | 
| jbe/bsw@0 | 2 trace.sql{ | 
| jbe@295 | 3 command = command, -- executed SQL command as string | 
| jbe@295 | 4 execution_time = execution_time, -- execution time of the statement in seconds | 
| jbe@295 | 5 error_position = error_position -- optional position in bytes where an error occurred | 
| jbe/bsw@0 | 6 } | 
| jbe/bsw@0 | 7 | 
| jbe@320 | 8 This command is used to log SQL command execution. It does not need to be invoked manually. | 
| jbe/bsw@0 | 9 | 
| jbe/bsw@0 | 10 --]]-- | 
| jbe/bsw@0 | 11 | 
| jbe/bsw@0 | 12 function trace.sql(args) | 
| jbe@41 | 13 if not trace._disabled then | 
| jbe@41 | 14 local command = args.command | 
| jbe@295 | 15 local execution_time = args.execution_time | 
| jbe@41 | 16 local error_position = args.error_position | 
| jbe@41 | 17 if type(command) ~= "string" then | 
| jbe@41 | 18 error("No command string passed to trace.sql{...}.") | 
| jbe@41 | 19 end | 
| jbe@295 | 20 if type(execution_time) ~= "number" then | 
| jbe@295 | 21 error("No execution time number passed to trace.sql{...}.") | 
| jbe@295 | 22 end | 
| jbe@41 | 23 if error_position and type(error_position) ~= "number" then | 
| jbe@41 | 24 error("error_position must be a number.") | 
| jbe@41 | 25 end | 
| jbe@41 | 26 trace._new_entry{ | 
| jbe@297 | 27 type = "sql", | 
| jbe@297 | 28 command = command, | 
| jbe@297 | 29 execution_time = execution_time, | 
| jbe@41 | 30 error_position = error_position | 
| jbe@41 | 31 } | 
| jbe@302 | 32 for i, entry in ipairs(trace._stack) do | 
| jbe@302 | 33 entry.db_time = entry.db_time + execution_time | 
| jbe@302 | 34 end | 
| jbe/bsw@0 | 35 end | 
| jbe/bsw@0 | 36 end |