Inserting Data
Use the esp.sqlInsert
function to insert records into the database.
resp = esp.sqlInsert(options)
In the function,
options include 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 Python objects that contain the records to insert.contextis an optional value that specifies the Python context in which the connection exists.
If you are processing stock trades, then you could use a Python 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="python" name="sub">
<properties>
<property name="type">sub</property>
<property name="code"><![CDATA[
def subscribe(data):
response = esp.sqlInsert(conn="db",table="trades",data=data)
if (response.code == False):
print(str(response))
]]></property>
</properties>
</connector>
</connectors>
</window-source>
The return value from
esp.sqlInsert is a Python 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