pySQLPlus - simple lib for querying to AspenTech Infoplus.21 database. The native SQLPLUS protocol is used to connect to the database. This does not require REST, SOAP, ODBC or other technologies
import sqlplus
s = sqlplus.SQLplus('INFO',10014)
query = "SELECT TS_START, AVG FROM aggregates WHERE name='00AAA01CT001:av' AND
ts between '01-FEB-13 00:00' AND '28-FEB-13 00:00'AND period = 864000;"
code, length, res = s.query(query.encode())
if (code!=sqlplus.SQLPLUS_SUCCESS):
raise Exception("Query error {}: {}".format(code,res))
print(res.decode())
The sqlplus server is installed in the INFO server. By default, it listens on TCP port 10014.
- Connect to the sqlplus server tcp port
- Send bytes
\x4a\x00\x00\x02\x00
; - Server returns name, version, sequence number and string (token)
- Connect done!
- Increase seq.number by one (4)
- Append token bytes (36)
- Append bytes
\x00\x64\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb4
(47) - Append length of the query string (4)
- Append query string bytes
- Append packet length to the beginning
- Encrypt the resulting packet by the RC4 algorithm with 8 bytes. For more see advapi32.py.
- Send to the server
- Accept in a buffer of size 4004;
- Decrypt the first 4 bytes. This is the packet length;
- Accept packets until the number of received bytes is less than the packet length. For each recv, decrease the buffer size by the number of received bytes;
- Decrypt the received packet;
- The 0th byte contains the return code. 0x53 is normal. Bytes 1-4 contain the message length;
- Then the result of the request in text form;
- If the packet length is less than the message length, continue steps 1-7, excluding step 5
This program is free for both personal and commercial use and is licensed under the MIT License. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.