soton_corenlppy.SqlHandler module

SQL database io handler abstract class | note: Applications should instantiate thier choice of either MysqlHandler or PostgresqlHandler classes but use the SqlHandler interface. This avoids having to install both database backend libraries when only one is needed.

class soton_corenlppy.SqlHandler.SqlHandler(user, passw, hostname, port, database, timeout_statement=60)[source]

Bases: object

Abstract SQL handler class to allow clients to execute robust, retry on failure type SQL statements.

close()[source]

close an open connection

execute_sql_query(query, timeout_statement=60, timeout_overall=180)[source]

execute a single SQL query and return the result (if any) | note: use variables for all data that has escape characters, non-ascii encoding or is simply large as opposed to niavely serializing the data into an SQL query string

Parameters
  • query (tuple) – SQL query tuple to execute to get config JSON object. e.g. ( “SELECT var FROM mytable WHERE var = %s”, (‘match_value’,) ). if there is no data part to the query None can be provided e.g. ( “SELECT * FROM mytable”, None )

  • timeout_statement (int) – number of seconds to allow each SQL statement

  • timeout_overall (int) – number of seconds total to allow each SQL statement (including retries)

Returns

Python list with result row data OR empty list (no data)

Return type

list

execute_sql_statement(statement_list, timeout_statement=60, timeout_overall=180)[source]

execute a set of SQL statements (insert, create etc) with no result expected | note: use variables for all data that has escape characters, non-ascii encoding or is simply large as opposed to niavely serializing the data into an SQL query string

Parameters
  • statement_list (list) – list of SQL statements in tuple form to execute in a single commit e.g. [ ( “INSERT INTO mytable VALUES(%s,%s)”, (‘value1’,’value2’) ), … ]. if there is no data part to the query None can be provided e.g. ( “INSERT INTO mytable VALUES(1)”, None )

  • timeout_statement (int) – number of seconds to allow each SQL statement

  • timeout_overall (int) – number of seconds total to allow each SQL statement (including retries)