Author Topic: Querying map tables with python.  (Read 2600 times)

0 Members and 1 Guest are viewing this topic.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Querying map tables with python.
« on: June 02, 2015, 02:35:27 PM »
Quick example demonstrating how to get a python script to query map tables.

First of all you need to download the library from here. Then copy ONLY the DLL file (only the dll file) to the folder below and ignore any instructions from the developer.
<your VC folder>\dlls

Here is the command:
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.4.2-->
<commandGroup open="True" name="map query test" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="633" name="Run the querymaps.py at startup" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\querymaps.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
    <event>VC.Rebuild</event>
  </command>
  <command id="549" name="Query maps.db3" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="Quick example on how to query a table Sensors_Presentation listing all the lines from the table where the fromkey field is equal to the ones in the Sensors_Control_Type table and the tovalue field is equal to 'BOOLEAN' on the Sensors_Control_Type table. Purely a relational database example.">
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>executesquery("select * from Sensors_Presentation where fromkey in (select fromkey from Sensors_Control_Type where tovalue='BOOLEAN')")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
  </command>
</commandGroup>


Here is the python script. Save it inside your VC installation folder, inside the PY folder and name it querymaps.py:
Code: [Select]
import sqlite3

#Executes queries to VC's map tables
def executesquery(sql):
    print "Going to execute the query:"
    print str(sql)
    con=sqlite3.connect("data\\maps.db3")
    c=con.cursor()
    c.execute(sql)
    print c.fetchall()

« Last Edit: June 02, 2015, 02:43:50 PM by marcusvdt »