alert.field.alert = ALERT
alert.field.alert_index = ALERT_INDEX
alert.field.alertid = ALERTID
alert.field.alertref = ALERTREF
alert.field.attack = ATTACK
alert.field.cweid = CWEID
alert.field.description = DESCRIPTION
alert.field.evidence = EVIDENCE
alert.field.historyid = HISTORYID
alert.field.inputvector = INPUT_VECTOR
alert.field.otherinfo = OTHERINFO
alert.field.param = PARAM
alert.field.pluginid = PLUGINID
alert.field.reference = REFERENCE
alert.field.reliability = RELIABILITY
alert.field.risk = RISK
alert.field.scanid = SCANID
alert.field.solution = SOLUTION
alert.field.sourcehistoryid = SOURCEHISTORYID
alert.field.sourceid = SOURCEID
alert.field.uri = URI
alert.field.wascid = WASCID
alert.ps.addalertindex = CREATE INDEX ALERT_INDEX ON ALERT (SOURCEHISTORYID)
alert.ps.addalertref = ALTER TABLE ALERT ADD COLUMN ALERTREF VARCHAR(256) DEFAULT ''
alert.ps.addattack = ALTER TABLE ALERT ADD COLUMN ATTACK VARCHAR(32768) DEFAULT ''
alert.ps.addcweid = ALTER TABLE ALERT ADD COLUMN CWEID INT DEFAULT -1
alert.ps.addevidence = ALTER TABLE ALERT ADD COLUMN EVIDENCE VARCHAR(16777216) DEFAULT ''
alert.ps.addinputvector = ALTER TABLE ALERT ADD COLUMN INPUT_VECTOR VARCHAR(256) DEFAULT ''
alert.ps.addnodename = ALTER TABLE ALERT ADD COLUMN NODENAME VARCHAR(1048576) DEFAULT NULL
alert.ps.addsourcehistoryid = ALTER TABLE ALERT ADD COLUMN SOURCEHISTORYID INT DEFAULT 0
alert.ps.addsourceid = ALTER TABLE ALERT ADD COLUMN SOURCEID INT DEFAULT 0
alert.ps.addsourceidindex = CREATE INDEX INDEX_ALERT_SOURCEID ON ALERT (SOURCEID)
alert.ps.addwascid = ALTER TABLE ALERT ADD COLUMN WASCID INT DEFAULT -1
alert.ps.delete = DELETE FROM ALERT WHERE ALERTID = ?
alert.ps.deleteall = DELETE FROM ALERT
alert.ps.getalertsforhistoryid = SELECT * FROM ALERT WHERE SOURCEHISTORYID = ?
alert.ps.getalertsforsession = SELECT ALERTID FROM ALERT INNER JOIN SCAN ON ALERT.SCANID = SCAN.SCANID WHERE SESSIONID = ?
alert.ps.getallalertids = SELECT ALERTID FROM ALERT
alert.ps.insert = INSERT INTO ALERT (SCANID, PLUGINID, ALERT, RISK, RELIABILITY, DESCRIPTION, URI, PARAM, ATTACK, OTHERINFO, SOLUTION, REFERENCE, EVIDENCE, CWEID, WASCID, HISTORYID, SOURCEHISTORYID, SOURCEID, ALERTREF, INPUT_VECTOR, NODENAME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
alert.ps.lastinsert = SELECT LAST_INSERT_ID()
alert.ps.read = SELECT * FROM ALERT WHERE ALERTID = ? LIMIT 1
alert.ps.update = UPDATE ALERT SET ALERT = ?, RISK = ?, RELIABILITY = ?, DESCRIPTION = ?, URI = ?, PARAM = ?, ATTACK = ?,OTHERINFO = ?, SOLUTION = ?, REFERENCE = ?, EVIDENCE = ?, CWEID = ?, WASCID = ?, SOURCEHISTORYID = ?, INPUT_VECTOR = ?, NODENAME = ? WHERE  ALERTID = ?
alert.ps.updatehistoryid = UPDATE ALERT SET HISTORYID = ?, SOURCEHISTORYID = ? WHERE ALERTID = ?
alert.table_name = ALERT

context.field.contextid = CONTEXTID
context.field.data = DATA
context.field.dataid = DATAID
context.field.type = TYPE
context.ps.alldata = SELECT * FROM CONTEXT_DATA
context.ps.alldataforcontext = SELECT * FROM CONTEXT_DATA WHERE  CONTEXTID = ?
context.ps.alldataforcontexttype = SELECT * FROM CONTEXT_DATA WHERE  CONTEXTID = ? AND  TYPE = ?
context.ps.createtable = CREATE CACHED TABLE CONTEXT_DATA (DATAID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), CONTEXTID INT NOT NULL, TYPE INT NOT NULL, DATA VARCHAR(8192) DEFAULT '')
context.ps.delete = DELETE FROM CONTEXT_DATA WHERE  CONTEXTID = ? AND  TYPE = ? AND DATA = ?
context.ps.deletealldataforcontext = DELETE FROM CONTEXT_DATA WHERE  CONTEXTID = ?
context.ps.deletealldataforcontexttype = DELETE FROM CONTEXT_DATA WHERE  CONTEXTID = ? AND  TYPE = ?
context.ps.insert = INSERT INTO CONTEXT_DATA (CONTEXTID, TYPE, DATA) VALUES (?, ?, ?)
context.ps.lastinsert = SELECT LAST_INSERT_ID()
context.ps.read = SELECT * FROM CONTEXT_DATA WHERE DATAID = ?
context.table_name = CONTEXT_DATA

history.field.historyid = HISTORYID
history.field.histtype = HISTTYPE
history.field.method = METHOD
history.field.note = NOTE
history.field.reqbody = REQBODY
history.field.reqheader = REQHEADER
history.field.resbody = RESBODY
history.field.resheader = RESHEADER
history.field.responsefromtargethost = RESPONSEFROMTARGETHOST
history.field.sessionid = SESSIONID
history.field.statuscode = STATUSCODE
history.field.tag = TAG
history.field.timeelapsedmillis = TIMEELAPSEDMILLIS
history.field.timesentmillis = TIMESENTMILLIS
history.field.uri = URI
history.ps.addnote = ALTER TABLE HISTORY ADD COLUMN NOTE VARCHAR(1048576) DEFAULT ''
history.ps.addrespfromtarget = ALTER TABLE HISTORY ADD COLUMN RESPONSEFROMTARGETHOST BOOLEAN DEFAULT FALSE
history.ps.addtag = ALTER TABLE HISTORY ADD COLUMN TAG VARCHAR(32768) DEFAULT ''
# TODO default 16777216 too big? But might not need? Maybe will :/
history.ps.changereqsize = ALTER TABLE TABLE_NAME ALTER COLUMN REQBODY VARBINARY(?)
history.ps.changerespsize = ALTER TABLE TABLE_NAME ALTER COLUMN RESBODY VARBINARY(?)
history.ps.containsuri = SELECT HISTORYID FROM HISTORY WHERE URI = ? AND  METHOD = ? AND REQBODY = ? AND SESSIONID = ? AND HISTTYPE = ? LIMIT 1
history.ps.delete = DELETE FROM HISTORY WHERE HISTORYID = ?
history.ps.deletesession = DELETE FROM HISTORY WHERE SESSIONID = ?
history.ps.deletetemp = DELETE FROM HISTORY WHERE HISTTYPE = ?
history.ps.deletetype = DELETE FROM HISTORY WHERE SESSIONID = ? AND HISTTYPE = ?
history.ps.gethistoryids = SELECT HISTORYID FROM HISTORY WHERE SESSIONID = ? ORDER BY HISTORYID
history.ps.gethistoryidsinctypes = SELECT HISTORYID FROM HISTORY WHERE SESSIONID = ? AND HISTTYPE IN ({0}) ORDER BY HISTORYID
history.ps.gethistoryidsnottypes = SELECT HISTORYID FROM HISTORY WHERE SESSIONID = ? AND HISTTYPE NOT IN ({0}) ORDER BY HISTORYID
history.ps.insertnost = INSERT INTO HISTORY (SESSIONID, HISTTYPE, TIMESENTMILLIS, TIMEELAPSEDMILLIS, METHOD, URI, REQHEADER,REQBODY, RESHEADER, RESBODY, TAG, NOTE, RESPONSEFROMTARGETHOST) VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ? , ?, ?, ?)
history.ps.insertstd = INSERT INTO HISTORY (SESSIONID, HISTTYPE, TIMESENTMILLIS, TIMEELAPSEDMILLIS, METHOD, URI, REQHEADER,REQBODY, RESHEADER, RESBODY, TAG, STATUSCODE, NOTE, RESPONSEFROMTARGETHOST) VALUES (?, ? ,?, ?, ?, ?, ?, ? ,? , ?, ?, ?, ?, ?)
# problem here, or just not picking up right props?
history.ps.lastindex = SELECT HISTORYID FROM HISTORY ORDER BY HISTORYID DESC LIMIT 1
history.ps.lastinsert = SELECT LAST_INSERT_ID()
history.ps.read = SELECT * FROM HISTORY WHERE HISTORYID = ? LIMIT 1 
history.ps.setnote = UPDATE HISTORY SET NOTE = ? WHERE HISTORYID = ?
history.ps.setrespfromtarget = UPDATE TABLE_NAME SET RESPONSEFROMTARGETHOST = TRUE
history.table_name = HISTORY

param.field.flags = FLAGS
param.field.name = NAME
param.field.paramid = PARAMID
param.field.site = SITE
param.field.type = TYPE
param.field.used = USED
param.field.vals = VALS
param.ps.addtable = CREATE TABLE PARAM (PARAMID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), SITE VARCHAR(32768) NOT NULL, TYPE VARCHAR(32768) NOT NULL, NAME VARCHAR(32768) NOT NULL, USED INT NOT NULL, FLAGS VARCHAR(32768) NOT NULL, VALS VARCHAR(8388608) NOT NULL)
param.ps.getall = SELECT * FROM PARAM
param.ps.insert = INSERT INTO PARAM (SITE, TYPE, NAME, USED, FLAGS, VALS) VALUES (?, ?, ?, ?, ?, ?)
param.ps.lastinsert = SELECT LAST_INSERT_ID()
param.ps.read = SELECT * FROM PARAM WHERE  PARAMID = ?
param.ps.update = UPDATE PARAM SET USED = ?, FLAGS = ?, VALS = ? WHERE PARAMID = ?
param.table_name = PARAM

scan.field.scanid = SCANID
scan.field.scanname = SCANNAME
scan.field.scantime = SCANTIME
scan.field.sessionid = SESSIONID
scan.ps.getlatestscan = SELECT * FROM SCAN WHERE SCANID = (SELECT MAX(B.SCANID) FROM SCAN AS B)
scan.ps.insert = INSERT INTO SCAN (SESSIONID, SCANNAME) VALUES (?, ?)
scan.ps.lastinsert = SELECT LAST_INSERT_ID()
scan.ps.read = SELECT * FROM SCAN WHERE SCANID = ?
scan.table_name = SCAN

session.field.lastaccess = LASTACCESS
session.field.sessionid = SESSIONID
session.field.sessionname = SESSIONNAME
session.ps.insert = INSERT INTO SESSION (SESSIONID, SESSIONNAME, LASTACCESS) VALUES (?, ?, NOW())
session.ps.list = SELECT * FROM SESSION
session.ps.update = UPDATE SESSION SET SESSIONNAME = ?, LASTACCESS = NOW() WHERE SESSIONID = ?

sessionurl.field.type = TYPE
sessionurl.field.url = URL
sessionurl.field.urlid = URLID
# TODO fix
sessionurl.ps.createtable = CREATE TABLE SESSION_URL (URLID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), TYPE INT NOT NULL, URL VARCHAR(8192) DEFAULT '')
sessionurl.ps.deleteurls = DELETE FROM SESSION_URL WHERE TYPE = ? AND URL = ?
sessionurl.ps.deleteurlsfortype = DELETE FROM SESSION_URL WHERE TYPE = ?
sessionurl.ps.geturlsfortype = SELECT * FROM SESSION_URL WHERE TYPE = ?
sessionurl.ps.insert = INSERT INTO SESSION_URL (TYPE, URL) VALUES (?, ?)
sessionurl.ps.lastinsert = SELECT LAST_INSERT_ID()
sessionurl.ps.read = SELECT * FROM SESSION_URL WHERE URLID = ?
sessionurl.table_name = SESSION_URL

structure.ps.createtable = CREATE TABLE STRUCTURE (STRUCTUREID BIGINT(20) NOT NULL AUTO_INCREMENT, SESSIONID BIGINT(20) NOT NULL, PARENTID BIGINT(20) NOT NULL, HISTORYID INT(11) DEFAULT NULL, NAME TEXT NOT NULL, NAMEHASH BIGINT(20) NOT NULL, URL TEXT NOT NULL, METHOD VARCHAR(10) NOT NULL, PRIMARY KEY (STRUCTUREID))
structure.ps.find = SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND NAMEHASH = ? AND METHOD = ?
structure.ps.getchildcount = SELECT COUNT(*) FROM STRUCTURE WHERE SESSIONID = ? AND PARENTID = ?
structure.ps.getchildren = SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND PARENTID = ?
structure.ps.insert = INSERT INTO STRUCTURE (SESSIONID, PARENTID, HISTORYID, NAME, NAMEHASH, URL, METHOD) VALUES (?, ?, ?, ?, ?, ?, ?)
structure.ps.lastinsert = SELECT LAST_INSERT_ID()
structure.ps.read = SELECT * FROM STRUCTURE WHERE SESSIONID = ? AND STRUCTUREID = ?\t\t\t\t

table.ps.lastinsert = SELECT LAST_INSERT_ID()

tag.field.historyid = HISTORYID
tag.field.tag = TAG
tag.field.tagid = TAGID
tag.ps.createtable = CREATE TABLE TAG (TAGID BIGINT GENERATED BY DEFAULT AS IDENTITY (START WITH 1), HISTORYID BIGINT NOT NULL, TAG VARCHAR(1024) DEFAULT '')
tag.ps.delete = DELETE FROM TAG WHERE HISTORYID = ? AND TAG = ?
tag.ps.deletetagsforhid = DELETE FROM TAG WHERE HISTORYID = ?
tag.ps.getalltags = SELECT DISTINCT TAG FROM TAG ORDER BY TAG
tag.ps.gettagsforhid = SELECT * FROM TAG WHERE HISTORYID = ?
tag.ps.insert = INSERT INTO TAG (HISTORYID, TAG) VALUES (?, ?)
tag.ps.lastinsert = SELECT LAST_INSERT_ID()
tag.ps.read = SELECT * FROM TAG WHERE TAGID = ?
tag.table_name = TAG
