Inserting Data
Use the esp_sqlInsert
function to insert records into the database.
local resp = esp_sqlInsert(options)
In the function,
options is a Lua table that contains the following
fields:
connis the name of the SQL connection to use.tableis the database table in which to insert data.datacontains one or more Lua objects that contain the records to insert.contextis an optional value that specifies the Lua context in which the connection exists.
If you are processing stock trades, then you could use a Lua subscriber connector on the Source window to grab incoming trades and write them to a database:
<window-source name="trades" insert-only="true">
<schema>
<fields>
<field key="true" name="id" type="int64"/>
<field name="symbol" type="string"/>
<field name="currency" type="int32"/>
<field name="time" type="int64"/>
<field name="msecs" type="int32"/>
<field name="price" type="double"/>
<field name="quant" type="int32"/>
<field name="venue" type="int32"/>
<field name="broker" type="int32"/>
<field name="buyer" type="int32"/>
<field name="seller" type="int32"/>
<field name="buysellflg" type="int32"/>
</fields>
</schema>
<connectors>
<connector class="lua" name="sub">
<properties>
<property name="type">sub</property>
<property name="code"><![CDATA[
function subscribe(data)
local response = esp_sqlInsert({conn="db",table="trades",data=data})
if (response.code == false)
then
print(esp_toString(response))
end
end
]]></property>
</properties>
</connector>
</connectors>
</window-source>
The return value from
esp_sqlInsert is a Lua object that contains the following
fields:
codeis the status of the insert:truefor success andfalsefor failure.messagecontains information that is related to the failure when one occurs.objectis the data for the failed record when a failure occurs.
Last updated: August 18, 2026